Spaces:
Sleeping
Sleeping
add vlc to play deezer music
Browse files
app.py
CHANGED
|
@@ -1,6 +1,8 @@
|
|
| 1 |
from smolagents import CodeAgent,DuckDuckGoSearchTool, HfApiModel,load_tool,tool
|
| 2 |
import datetime
|
| 3 |
import requests
|
|
|
|
|
|
|
| 4 |
import pytz
|
| 5 |
import yaml
|
| 6 |
from tools.final_answer import FinalAnswerTool
|
|
@@ -33,7 +35,46 @@ def get_current_time_in_timezone(timezone: str) -> str:
|
|
| 33 |
except Exception as e:
|
| 34 |
return f"Error fetching time for timezone '{timezone}': {str(e)}"
|
| 35 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 36 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 37 |
final_answer = FinalAnswerTool()
|
| 38 |
|
| 39 |
# If the agent does not answer, the model is overloaded, please use another model or the following Hugging Face Endpoint that also contains qwen2.5 coder:
|
|
@@ -56,7 +97,7 @@ with open("prompts.yaml", 'r') as stream:
|
|
| 56 |
|
| 57 |
agent = CodeAgent(
|
| 58 |
model=model,
|
| 59 |
-
tools=[final_answer,
|
| 60 |
max_steps=6,
|
| 61 |
verbosity_level=1,
|
| 62 |
grammar=None,
|
|
|
|
| 1 |
from smolagents import CodeAgent,DuckDuckGoSearchTool, HfApiModel,load_tool,tool
|
| 2 |
import datetime
|
| 3 |
import requests
|
| 4 |
+
import vlc
|
| 5 |
+
import time
|
| 6 |
import pytz
|
| 7 |
import yaml
|
| 8 |
from tools.final_answer import FinalAnswerTool
|
|
|
|
| 35 |
except Exception as e:
|
| 36 |
return f"Error fetching time for timezone '{timezone}': {str(e)}"
|
| 37 |
|
| 38 |
+
@tool
|
| 39 |
+
def play_preview_deezer(track: str, artist:str) -> None:
|
| 40 |
+
"""Play a preview of a track from Deezer.
|
| 41 |
+
Args:
|
| 42 |
+
track: The track to play.
|
| 43 |
+
artist: The artist of the track.
|
| 44 |
+
"""
|
| 45 |
+
# Define the API endpoint
|
| 46 |
+
url = "https://api.deezer.com/search"
|
| 47 |
+
|
| 48 |
+
# Define the query parameters
|
| 49 |
+
params = {
|
| 50 |
+
"q": f'track:"{track}" artist:"{artist}"',
|
| 51 |
+
}
|
| 52 |
+
print(params)
|
| 53 |
+
|
| 54 |
+
# Make the GET request
|
| 55 |
+
response = requests.get(url, params=params)
|
| 56 |
|
| 57 |
+
# Check if the request was successful
|
| 58 |
+
if response.status_code == 200:
|
| 59 |
+
data = response.json()
|
| 60 |
+
# Print the first track from the search results
|
| 61 |
+
if data['data']:
|
| 62 |
+
first_track = data['data'][0]
|
| 63 |
+
print(f"Title: {first_track['title']}")
|
| 64 |
+
print(f"Artist: {first_track['artist']['name']}")
|
| 65 |
+
print(f"Album: {first_track['album']['title']}")
|
| 66 |
+
print(f"link: {first_track['link']}")
|
| 67 |
+
# Play the track using VLC
|
| 68 |
+
print("Playing preview: ", first_track['preview'])
|
| 69 |
+
player = vlc.MediaPlayer(first_track['preview'])
|
| 70 |
+
player.play()
|
| 71 |
+
# wait time for vlc to load
|
| 72 |
+
time.sleep(30)
|
| 73 |
+
else:
|
| 74 |
+
print("No tracks found.")
|
| 75 |
+
else:
|
| 76 |
+
print(f"Error: {response.status_code}")
|
| 77 |
+
|
| 78 |
final_answer = FinalAnswerTool()
|
| 79 |
|
| 80 |
# If the agent does not answer, the model is overloaded, please use another model or the following Hugging Face Endpoint that also contains qwen2.5 coder:
|
|
|
|
| 97 |
|
| 98 |
agent = CodeAgent(
|
| 99 |
model=model,
|
| 100 |
+
tools=[final_answer, play_preview_deezer], ## add your tools here (don't remove final answer)
|
| 101 |
max_steps=6,
|
| 102 |
verbosity_level=1,
|
| 103 |
grammar=None,
|