saayedalam commited on
Commit
298031f
·
verified ·
1 Parent(s): 4a20cb3

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +19 -16
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
- 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 f"No album found for {artist_name}"
44
- else:
45
- return f"{artist_name} not found."
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