Spaces:
Runtime error
Runtime error
Update app.py
Browse files
app.py
CHANGED
|
@@ -10,34 +10,37 @@ from Gradio_UI import GradioUI
|
|
| 10 |
|
| 11 |
# Below is an example of a tool that does nothing. Amaze us with your creativity !
|
| 12 |
|
| 13 |
-
# Initialize the Genius API client with access token
|
| 14 |
-
genius = lyricsgenius.Genius("2kWJ8Wy72HT3T8qjkh__gGB3fAbCLtTbC68j1i9tvOM9DF9ikSr95wm-hOQLZq9_")
|
| 15 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 16 |
|
| 17 |
-
#
|
| 18 |
-
genius
|
| 19 |
-
genius.excluded_terms = ["(Remix)", "(Live)"] # Excludes unwanted terms from search results
|
| 20 |
|
| 21 |
-
|
| 22 |
-
|
| 23 |
-
|
| 24 |
-
|
| 25 |
-
|
| 26 |
-
|
| 27 |
-
|
| 28 |
-
|
|
|
|
| 29 |
|
| 30 |
try:
|
| 31 |
# Search for the song by title and artist
|
| 32 |
song = genius.search_song(song_name, artist_name)
|
| 33 |
|
| 34 |
if song:
|
| 35 |
-
|
| 36 |
-
return f"The lyrics of the {song_name} by {artist_name} is ... {song.lyrics}"
|
| 37 |
else:
|
| 38 |
return "Song not found."
|
| 39 |
except Exception as e:
|
| 40 |
-
return f"Error fetching song lyrics of
|
| 41 |
|
| 42 |
|
| 43 |
|
|
|
|
| 10 |
|
| 11 |
# Below is an example of a tool that does nothing. Amaze us with your creativity !
|
| 12 |
|
|
|
|
|
|
|
| 13 |
|
| 14 |
+
@tool
|
| 15 |
+
def get_song_lyrics(song_name: str, artist_name: str) -> str:
|
| 16 |
+
"""Fetch lyrics from Genius based on song title and artist name."""
|
| 17 |
+
genius_token = os.getenv("Genius")
|
| 18 |
+
if not genius_token:
|
| 19 |
+
return "Error: Genius API token not found."
|
| 20 |
|
| 21 |
+
# Initialize Genius API client
|
| 22 |
+
genius = lyricsgenius.Genius(genius_token)
|
|
|
|
| 23 |
|
| 24 |
+
# Add headers to avoid 403 errors
|
| 25 |
+
headers = {
|
| 26 |
+
"User-Agent": "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/58.0.3029.110 Safari/537.36"
|
| 27 |
+
}
|
| 28 |
+
genius._headers = headers # Set the headers in the API client
|
| 29 |
+
|
| 30 |
+
# Optional settings
|
| 31 |
+
genius.remove_section_headers = True # Removes [Chorus], [Verse] headers
|
| 32 |
+
genius.excluded_terms = ["(Remix)", "(Live)"]
|
| 33 |
|
| 34 |
try:
|
| 35 |
# Search for the song by title and artist
|
| 36 |
song = genius.search_song(song_name, artist_name)
|
| 37 |
|
| 38 |
if song:
|
| 39 |
+
return f"The lyrics of the song '{song_name}' by {artist_name} are ...\n{song.lyrics[:300]}..."
|
|
|
|
| 40 |
else:
|
| 41 |
return "Song not found."
|
| 42 |
except Exception as e:
|
| 43 |
+
return f"Error fetching song lyrics of '{song_name}' by {artist_name}: {str(e)}"
|
| 44 |
|
| 45 |
|
| 46 |
|