Spaces:
Sleeping
Sleeping
- A more safe approach
Browse files
app.py
CHANGED
|
@@ -8,26 +8,26 @@ import numpy as np
|
|
| 8 |
from Gradio_UI import GradioUI
|
| 9 |
from bs4 import BeautifulSoup
|
| 10 |
import random
|
|
|
|
|
|
|
|
|
|
|
|
|
| 11 |
# Below is an example of a tool that does nothing. Amaze us with your creativity !
|
| 12 |
@tool
|
| 13 |
-
def get_animal_image(animal_name:str)-> np.ndarray
|
| 14 |
-
|
| 15 |
-
"""A tool that gets a random animal image from the internet and returns an image as numpy array
|
| 16 |
Args:
|
| 17 |
-
animal_name:
|
| 18 |
"""
|
| 19 |
-
#
|
| 20 |
-
|
| 21 |
-
|
| 22 |
-
response = requests.get(
|
| 23 |
-
|
| 24 |
-
|
| 25 |
-
|
| 26 |
-
|
| 27 |
-
|
| 28 |
-
response = requests.get(image_url)
|
| 29 |
-
#return the image as numpy array
|
| 30 |
-
return np.array(response.content)
|
| 31 |
|
| 32 |
@tool
|
| 33 |
def get_current_time_in_timezone(timezone: str) -> str:
|
|
|
|
| 8 |
from Gradio_UI import GradioUI
|
| 9 |
from bs4 import BeautifulSoup
|
| 10 |
import random
|
| 11 |
+
from PIL import Image
|
| 12 |
+
from io import BytesIO
|
| 13 |
+
from typing import Annotated
|
| 14 |
+
|
| 15 |
# Below is an example of a tool that does nothing. Amaze us with your creativity !
|
| 16 |
@tool
|
| 17 |
+
def get_animal_image(animal_name: Annotated[str, "The animal name to search for."]) -> Annotated[np.ndarray, "A numpy array of the image."]:
|
| 18 |
+
"""Returns a random animal image from an online image API as a numpy array.
|
|
|
|
| 19 |
Args:
|
| 20 |
+
animal_name: The animal name to search for.
|
| 21 |
"""
|
| 22 |
+
# Use a real image API like Unsplash or Wikimedia
|
| 23 |
+
url = f"https://source.unsplash.com/600x400/?{animal_name}"
|
| 24 |
+
|
| 25 |
+
response = requests.get(url)
|
| 26 |
+
if response.status_code != 200:
|
| 27 |
+
raise RuntimeError("Failed to retrieve image.")
|
| 28 |
+
|
| 29 |
+
image = Image.open(BytesIO(response.content)).convert("RGB")
|
| 30 |
+
return np.array(image)
|
|
|
|
|
|
|
|
|
|
| 31 |
|
| 32 |
@tool
|
| 33 |
def get_current_time_in_timezone(timezone: str) -> str:
|