Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
|
@@ -29,7 +29,6 @@ def get_nbp_exchange_rate(currency: str) -> float:
|
|
| 29 |
else:
|
| 30 |
raise ValueError(f"Failed to fetch exchange rate for {currency}. HTTP Status: {response.status_code}")
|
| 31 |
|
| 32 |
-
|
| 33 |
@tool
|
| 34 |
def get_billboard_hot_100_last_countdown() -> list:
|
| 35 |
"""A tool that fetches the latest Billboard Hot 100 countdown with song names and artist names.
|
|
@@ -51,22 +50,28 @@ def get_billboard_hot_100_last_countdown() -> list:
|
|
| 51 |
|
| 52 |
for item in chart_items[:10]:
|
| 53 |
song_name_elem = item.select_one("h3")
|
| 54 |
-
artist_name_elem = item.
|
| 55 |
|
| 56 |
if song_name_elem and artist_name_elem:
|
| 57 |
song_name = song_name_elem.get_text(strip=True)
|
| 58 |
-
artist_name = artist_name_elem.get_text(strip=True)
|
| 59 |
|
| 60 |
-
#
|
| 61 |
-
|
| 62 |
-
|
|
|
|
|
|
|
|
|
|
| 63 |
|
| 64 |
-
|
|
|
|
| 65 |
|
| 66 |
return top_songs
|
| 67 |
else:
|
| 68 |
raise ValueError(f"Failed to fetch Billboard Hot 100. HTTP Status: {response.status_code}")
|
| 69 |
|
|
|
|
|
|
|
|
|
|
| 70 |
# Below is an example of a tool that does nothing. Amaze us with your creativity !
|
| 71 |
@tool
|
| 72 |
def my_custom_tool(arg1:str, arg2:int)-> str: #it's import to specify the return type
|
|
|
|
| 29 |
else:
|
| 30 |
raise ValueError(f"Failed to fetch exchange rate for {currency}. HTTP Status: {response.status_code}")
|
| 31 |
|
|
|
|
| 32 |
@tool
|
| 33 |
def get_billboard_hot_100_last_countdown() -> list:
|
| 34 |
"""A tool that fetches the latest Billboard Hot 100 countdown with song names and artist names.
|
|
|
|
| 50 |
|
| 51 |
for item in chart_items[:10]:
|
| 52 |
song_name_elem = item.select_one("h3")
|
| 53 |
+
artist_name_elem = item.select("span.c-label")
|
| 54 |
|
| 55 |
if song_name_elem and artist_name_elem:
|
| 56 |
song_name = song_name_elem.get_text(strip=True)
|
|
|
|
| 57 |
|
| 58 |
+
# The artist name is usually the second span.c-label element in Billboard's structure
|
| 59 |
+
artist_name = None
|
| 60 |
+
for span in artist_name_elem:
|
| 61 |
+
if not span.get_text(strip=True).isdigit(): # Avoid selecting ranking numbers
|
| 62 |
+
artist_name = span.get_text(strip=True)
|
| 63 |
+
break
|
| 64 |
|
| 65 |
+
if artist_name:
|
| 66 |
+
top_songs.append({"song": song_name, "artist": artist_name})
|
| 67 |
|
| 68 |
return top_songs
|
| 69 |
else:
|
| 70 |
raise ValueError(f"Failed to fetch Billboard Hot 100. HTTP Status: {response.status_code}")
|
| 71 |
|
| 72 |
+
|
| 73 |
+
|
| 74 |
+
|
| 75 |
# Below is an example of a tool that does nothing. Amaze us with your creativity !
|
| 76 |
@tool
|
| 77 |
def my_custom_tool(arg1:str, arg2:int)-> str: #it's import to specify the return type
|