Spaces:
Runtime error
Runtime error
Update app.py
Browse files
app.py
CHANGED
|
@@ -25,25 +25,28 @@ def get_most_recent_album_name(artist_name: str) -> str:
|
|
| 25 |
Args:
|
| 26 |
artist_name: A string representing a valid name of a song.
|
| 27 |
"""
|
| 28 |
-
|
| 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
|
| 37 |
-
|
| 38 |
-
|
|
|
|
|
|
|
| 39 |
|
| 40 |
-
|
| 41 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 42 |
else:
|
| 43 |
-
return
|
| 44 |
-
|
| 45 |
-
|
| 46 |
-
|
| 47 |
|
| 48 |
|
| 49 |
@tool
|
|
|
|
| 25 |
Args:
|
| 26 |
artist_name: A string representing a valid name of a song.
|
| 27 |
"""
|
| 28 |
+
try:
|
| 29 |
+
# Search for the artist by nameresult = sp.search(q=artist_name, type='artist', limit=1)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 30 |
|
| 31 |
+
if result['artists']['items']:
|
| 32 |
+
artist_id = result['artists']['items'][0]['id']
|
| 33 |
+
|
| 34 |
+
# Get the artist's albums (in reverse chronological order)
|
| 35 |
+
albums = sp.artist_albums(artist_id, album_type='album', limit=1, offset=0)
|
| 36 |
|
| 37 |
+
if albums['items']:
|
| 38 |
+
# Get the most recent album
|
| 39 |
+
most_recent_album = albums['items'][0]
|
| 40 |
+
|
| 41 |
+
# Return the name of the most recent album
|
| 42 |
+
return most_recent_album['name']
|
| 43 |
+
else:
|
| 44 |
+
return "No albums found for this artist."
|
| 45 |
else:
|
| 46 |
+
return "Artist not found."
|
| 47 |
+
|
| 48 |
+
except Exception as e:
|
| 49 |
+
return f"An error occurred: {str(e)}"
|
| 50 |
|
| 51 |
|
| 52 |
@tool
|