Spaces:
Runtime error
Runtime error
Update app.py
Browse files
app.py
CHANGED
|
@@ -4,19 +4,38 @@ 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 |
#Keep this format for the description / args / args description but feel free to modify the tool
|
| 14 |
-
"""A tool that
|
| 15 |
Args:
|
| 16 |
-
|
| 17 |
-
|
| 18 |
"""
|
| 19 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 20 |
|
| 21 |
@tool
|
| 22 |
def get_current_time_in_timezone(timezone: str) -> str:
|
|
@@ -55,7 +74,7 @@ with open("prompts.yaml", 'r') as stream:
|
|
| 55 |
|
| 56 |
agent = CodeAgent(
|
| 57 |
model=model,
|
| 58 |
-
tools=[final_answer], ## add your tools here (don't remove final answer)
|
| 59 |
max_steps=6,
|
| 60 |
verbosity_level=1,
|
| 61 |
grammar=None,
|
|
|
|
| 4 |
import pytz
|
| 5 |
import yaml
|
| 6 |
from tools.final_answer import FinalAnswerTool
|
| 7 |
+
import lyricsgenius
|
| 8 |
|
| 9 |
from Gradio_UI import GradioUI
|
| 10 |
|
| 11 |
# Below is an example of a tool that does nothing. Amaze us with your creativity !
|
| 12 |
@tool
|
| 13 |
+
def get_song_lyrics(song_name:str, artist_name:str)-> str: #it's import to specify the return type
|
| 14 |
#Keep this format for the description / args / args description but feel free to modify the tool
|
| 15 |
+
"""A tool that fetches lyrics from Genius based on the song title and artist name.
|
| 16 |
Args:
|
| 17 |
+
song_name: A string representing a valid name of a song.
|
| 18 |
+
artist_name: A string representing a valid name of a song.
|
| 19 |
"""
|
| 20 |
+
# Initialize the Genius API client with access token
|
| 21 |
+
genius = lyricsgenius.Genius("Genius_Lyrics")
|
| 22 |
+
|
| 23 |
+
# Setting some preferences
|
| 24 |
+
genius.remove_section_headers = True # Removes section headers like [Chorus], [Verse], etc.
|
| 25 |
+
genius.excluded_terms = ["(Remix)", "(Live)"] # Excludes unwanted terms from search results
|
| 26 |
+
|
| 27 |
+
try:
|
| 28 |
+
# Search for the song by title and artist
|
| 29 |
+
song = genius.search_song(song_name, artist_name)
|
| 30 |
+
|
| 31 |
+
if song:
|
| 32 |
+
# Return the song lyrics if found
|
| 33 |
+
return f"The lyrics of the {song_name} by {artist_name} is ... {song.lyrics}
|
| 34 |
+
else:
|
| 35 |
+
return "Song not found."
|
| 36 |
+
except Exception as e:
|
| 37 |
+
return f"Error fetching song lyrics of the {song_name} by {artist_name}: {e}"
|
| 38 |
+
|
| 39 |
|
| 40 |
@tool
|
| 41 |
def get_current_time_in_timezone(timezone: str) -> str:
|
|
|
|
| 74 |
|
| 75 |
agent = CodeAgent(
|
| 76 |
model=model,
|
| 77 |
+
tools=[final_answer, get_song_lyrics], ## add your tools here (don't remove final answer)
|
| 78 |
max_steps=6,
|
| 79 |
verbosity_level=1,
|
| 80 |
grammar=None,
|