Spaces:
Runtime error
Runtime error
Update app.py
Browse files
app.py
CHANGED
|
@@ -4,44 +4,45 @@ import requests
|
|
| 4 |
import pytz
|
| 5 |
import yaml
|
| 6 |
from tools.final_answer import FinalAnswerTool
|
| 7 |
-
import
|
| 8 |
-
import
|
| 9 |
-
|
| 10 |
from Gradio_UI import GradioUI
|
| 11 |
|
| 12 |
# Below is an example of a tool that does nothing. Amaze us with your creativity !
|
| 13 |
|
| 14 |
-
|
| 15 |
-
|
| 16 |
-
|
| 17 |
-
# Add headers to avoid 403 errors
|
| 18 |
-
headers = {
|
| 19 |
-
"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"}
|
| 20 |
-
|
| 21 |
-
genius._headers = headers # Set the headers in the API client
|
| 22 |
|
| 23 |
-
#
|
| 24 |
-
|
| 25 |
-
|
| 26 |
|
| 27 |
@tool
|
| 28 |
-
def get_song_lyrics(
|
| 29 |
-
"""A tool that fetches
|
| 30 |
Args:
|
| 31 |
-
song_name: A string representing a valid name of a song.
|
| 32 |
artist_name: A string representing a valid name of a song.
|
| 33 |
"""
|
|
|
|
| 34 |
|
| 35 |
-
|
| 36 |
-
|
| 37 |
-
|
|
|
|
|
|
|
| 38 |
|
| 39 |
-
if
|
| 40 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
| 41 |
else:
|
| 42 |
-
return "
|
| 43 |
-
|
| 44 |
-
return
|
| 45 |
|
| 46 |
|
| 47 |
|
|
|
|
| 4 |
import pytz
|
| 5 |
import yaml
|
| 6 |
from tools.final_answer import FinalAnswerTool
|
| 7 |
+
import spotipy
|
| 8 |
+
from spotipy.oauth2 import SpotifyClientCredentials
|
| 9 |
+
|
| 10 |
from Gradio_UI import GradioUI
|
| 11 |
|
| 12 |
# Below is an example of a tool that does nothing. Amaze us with your creativity !
|
| 13 |
|
| 14 |
+
# Set your Spotify API credentials
|
| 15 |
+
client_id = 'f4b7863fa1504190b0d49939fc31a05f'
|
| 16 |
+
client_secret = 'db2c21e185404604a02a5b8d683a6c03'
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 17 |
|
| 18 |
+
# Set up Spotify authentication
|
| 19 |
+
client_credentials_manager = SpotifyClientCredentials(client_id=client_id, client_secret=client_secret)
|
| 20 |
+
sp = spotipy.Spotify(client_credentials_manager=client_credentials_manager)
|
| 21 |
|
| 22 |
@tool
|
| 23 |
+
def get_song_lyrics(artist_name: str) -> str:
|
| 24 |
+
"""A tool that fetches the most recent album name of a given artist.
|
| 25 |
Args:
|
|
|
|
| 26 |
artist_name: A string representing a valid name of a song.
|
| 27 |
"""
|
| 28 |
+
result = sp.search(q=artist_name, type='artist', limit=1)
|
| 29 |
|
| 30 |
+
if result['artists']['items']:
|
| 31 |
+
artist_id = result['artists']['items'][0]['id']
|
| 32 |
+
|
| 33 |
+
# Get the artist's albums (in reverse chronological order)
|
| 34 |
+
albums = sp.artist_albums(artist_id, album_type='album', limit=1, offset=0)
|
| 35 |
|
| 36 |
+
if albums['items']:
|
| 37 |
+
# Get the most recent album
|
| 38 |
+
most_recent_album = albums['items'][0]
|
| 39 |
+
|
| 40 |
+
# Return the name of the most recent album
|
| 41 |
+
return f"The most recent album of the {artist_name} is {most_recent_album['name']}
|
| 42 |
else:
|
| 43 |
+
return "No albums found for this artist."
|
| 44 |
+
else:
|
| 45 |
+
return "Artist not found."
|
| 46 |
|
| 47 |
|
| 48 |
|