saayedalam commited on
Commit
0bd8c5c
·
verified ·
1 Parent(s): cbcdcd4

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +19 -20
app.py CHANGED
@@ -11,41 +11,40 @@ 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_most_recent_album_name(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
  try:
 
 
 
29
  # Search for the artist by name
30
  result = sp.search(q=artist_name, type='artist', limit=1)
31
-
32
  if result['artists']['items']:
33
  artist_id = result['artists']['items'][0]['id']
34
 
35
  # Get the artist's albums (in reverse chronological order)
36
- albums = sp.artist_albums(artist_id, album_type='album', limit=1, offset=0)
37
-
38
  if albums['items']:
39
  # Get the most recent album
40
- most_recent_album = albums['items'][0]
41
 
42
- # Return the name of the most recent album
43
- return f"The most recent album of {artist_name} is {most_recent_album['name']}"
44
  else:
45
- return "No albums found for this artist."
46
  else:
47
- return "Artist not found."
48
-
49
  except Exception as e:
50
  return f"An error occurred: {str(e)}"
51
 
 
11
 
12
  # Below is an example of a tool that does nothing. Amaze us with your creativity !
13
 
 
 
 
 
 
 
 
 
14
  @tool
15
+ def get_latest_album_name(artist_name: str) -> str:
16
+ """Fetches the latest album name of a given artist using the Spotify API.
17
+
18
  Args:
19
+ artist_name (str): A string representing a valid artist's name.
20
+
21
+ Returns:
22
+ str: The name of the latest album by the artist.
23
  """
24
  try:
25
+ # Set up Spotify authentication
26
+ sp = spotipy.Spotify(auth_manager=SpotifyClientCredentials(client_id="f4b7863fa1504190b0d49939fc31a05f", client_secret="db2c21e185404604a02a5b8d683a6c03"))
27
+
28
  # Search for the artist by name
29
  result = 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)
36
+
37
  if albums['items']:
38
  # Get the most recent album
39
+ latest_album = albums['items'][0]
40
 
41
+ # Return the name of the latest album
42
+ return f"The latest album of {artist_name} is {latest_album['name']}"
43
  else:
44
+ return f"No albums found for artist '{artist_name}'."
45
  else:
46
+ return f"Artist '{artist_name}' not found."
47
+
48
  except Exception as e:
49
  return f"An error occurred: {str(e)}"
50