Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
|
@@ -35,17 +35,23 @@ def get_current_time_in_timezone(timezone: str) -> str:
|
|
| 35 |
|
| 36 |
@tool
|
| 37 |
def get_random_cat_picture() -> str:
|
| 38 |
-
"""Fetches a random cat picture
|
| 39 |
|
| 40 |
Returns:
|
| 41 |
-
|
| 42 |
"""
|
| 43 |
api_url = "https://api.thecatapi.com/v1/images/search"
|
| 44 |
|
| 45 |
try:
|
| 46 |
response = requests.get(api_url)
|
| 47 |
data = response.json()
|
| 48 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 49 |
except Exception as e:
|
| 50 |
return f"Error fetching cat image: {str(e)}"
|
| 51 |
|
|
|
|
| 35 |
|
| 36 |
@tool
|
| 37 |
def get_random_cat_picture() -> str:
|
| 38 |
+
"""Fetches a random cat picture and returns it as an image.
|
| 39 |
|
| 40 |
Returns:
|
| 41 |
+
An image of a random cat.
|
| 42 |
"""
|
| 43 |
api_url = "https://api.thecatapi.com/v1/images/search"
|
| 44 |
|
| 45 |
try:
|
| 46 |
response = requests.get(api_url)
|
| 47 |
data = response.json()
|
| 48 |
+
img_url = data[0]["url"]
|
| 49 |
+
|
| 50 |
+
# Fetch the image content
|
| 51 |
+
img_response = requests.get(img_url)
|
| 52 |
+
img = Image.open(BytesIO(img_response.content))
|
| 53 |
+
|
| 54 |
+
return img # Return the image directly
|
| 55 |
except Exception as e:
|
| 56 |
return f"Error fetching cat image: {str(e)}"
|
| 57 |
|