Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
@@ -4,19 +4,57 @@ import requests
|
|
4 |
import pytz
|
5 |
import yaml
|
6 |
from tools.final_answer import FinalAnswerTool
|
|
|
|
|
|
|
7 |
|
8 |
from Gradio_UI import GradioUI
|
9 |
|
10 |
# Below is an example of a tool that does nothing. Amaze us with your creativity !
|
11 |
@tool
|
12 |
-
def
|
13 |
-
|
14 |
-
|
|
|
15 |
Args:
|
16 |
-
|
17 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
18 |
"""
|
19 |
-
|
|
|
|
|
|
|
20 |
|
21 |
@tool
|
22 |
def get_current_time_in_timezone(timezone: str) -> str:
|
@@ -51,7 +89,7 @@ with open("prompts.yaml", 'r') as stream:
|
|
51 |
|
52 |
agent = CodeAgent(
|
53 |
model=model,
|
54 |
-
tools=[final_answer], ## add your tools here (don't remove final answer)
|
55 |
max_steps=6,
|
56 |
verbosity_level=1,
|
57 |
grammar=None,
|
|
|
4 |
import pytz
|
5 |
import yaml
|
6 |
from tools.final_answer import FinalAnswerTool
|
7 |
+
from typing import Dict, Union
|
8 |
+
import urllib.parse
|
9 |
+
import json
|
10 |
|
11 |
from Gradio_UI import GradioUI
|
12 |
|
13 |
# Below is an example of a tool that does nothing. Amaze us with your creativity !
|
14 |
@tool
|
15 |
+
def get_song_lyrics(artist:str = "artist", song:str = "song") -> Dict[str, str]:
|
16 |
+
"""
|
17 |
+
Fetches the lyrics of a song from the lyrics.ovh API.
|
18 |
+
|
19 |
Args:
|
20 |
+
artist (str): The name of the artist. Defaults to "artist".
|
21 |
+
song (str): The name of the song. Defaults to "song".
|
22 |
+
|
23 |
+
Returns:
|
24 |
+
Dict[str, str]: A dictionary containing either:
|
25 |
+
- {'Error': 'No lyrics found'} if the lyrics are not available.
|
26 |
+
- {'lyrics': "<song lyrics>"} if the lyrics are successfully retrieved.
|
27 |
+
"""
|
28 |
+
|
29 |
+
if len(artist)<1:
|
30 |
+
artist = 'artist'
|
31 |
+
|
32 |
+
if len(song)<1:
|
33 |
+
song = 'song'
|
34 |
+
|
35 |
+
base_url = "https://api.lyrics.ovh/v1/"
|
36 |
+
|
37 |
+
encoded_artist = urllib.parse.quote(artist)
|
38 |
+
encoded_song = urllib.parse.quote(song)
|
39 |
+
|
40 |
+
url = f"{base_url}{encoded_artist}/{encoded_song}"
|
41 |
+
response = requests.get(url)
|
42 |
+
|
43 |
+
if json.loads(response.text).get('error','ok').lower()=='no lyrics found':
|
44 |
+
return {'Error': 'No lyrics found'}
|
45 |
+
if response.status_code == 200:
|
46 |
+
return {'lyrics': json.loads(response.text).get('lyrics')}
|
47 |
+
|
48 |
+
return {"Error": str(response.status_code)}
|
49 |
+
|
50 |
+
@tool
|
51 |
+
def get_random_fact()-> str:
|
52 |
+
"""Get useless, but true facts. Function will return random fact.
|
53 |
"""
|
54 |
+
url = "https://uselessfacts.jsph.pl/api/v2/facts/random"
|
55 |
+
headers = {"Accept": "text/plain"}
|
56 |
+
response = requests.get(url, headers=headers)
|
57 |
+
return response.text
|
58 |
|
59 |
@tool
|
60 |
def get_current_time_in_timezone(timezone: str) -> str:
|
|
|
89 |
|
90 |
agent = CodeAgent(
|
91 |
model=model,
|
92 |
+
tools=[get_song_lyrics, get_random_fact, final_answer], ## add your tools here (don't remove final answer)
|
93 |
max_steps=6,
|
94 |
verbosity_level=1,
|
95 |
grammar=None,
|