Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
|
@@ -59,8 +59,32 @@ def get_billboard_hot_100_last_countdown() -> list:
|
|
| 59 |
|
| 60 |
return top_songs
|
| 61 |
|
| 62 |
-
|
| 63 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 64 |
|
| 65 |
# Below is an example of a tool that does nothing. Amaze us with your creativity !
|
| 66 |
@tool
|
|
|
|
| 59 |
|
| 60 |
return top_songs
|
| 61 |
|
| 62 |
+
@tool
|
| 63 |
+
def get_cat_picture_with_name():
|
| 64 |
+
"""A tool that searches the internet for a picture of a cat, downloads the first result, and displays it with a randomly generated name.
|
| 65 |
+
"""
|
| 66 |
+
import requests
|
| 67 |
+
import random
|
| 68 |
+
from PIL import Image
|
| 69 |
+
from io import BytesIO
|
| 70 |
+
|
| 71 |
+
url = "https://api.thecatapi.com/v1/images/search"
|
| 72 |
+
try:
|
| 73 |
+
response = requests.get(url)
|
| 74 |
+
response.raise_for_status()
|
| 75 |
+
data = response.json()
|
| 76 |
+
if data:
|
| 77 |
+
cat_image_url = data[0]["url"]
|
| 78 |
+
cat_name = random.choice(["Whiskers", "Mittens", "Shadow", "Luna", "Simba", "Oliver", "Bella", "Charlie", "Leo", "Max"])
|
| 79 |
+
|
| 80 |
+
image_response = requests.get(cat_image_url)
|
| 81 |
+
image_response.raise_for_status()
|
| 82 |
+
img = Image.open(BytesIO(image_response.content))
|
| 83 |
+
img.show(title=f"This cat's name is {cat_name}")
|
| 84 |
+
else:
|
| 85 |
+
print("No cat image found.")
|
| 86 |
+
except requests.exceptions.RequestException as e:
|
| 87 |
+
raise ValueError(f"Error fetching cat image: {e}")
|
| 88 |
|
| 89 |
# Below is an example of a tool that does nothing. Amaze us with your creativity !
|
| 90 |
@tool
|