Spaces:
Build error
Build error
add a tool
Browse files
app.py
CHANGED
|
@@ -8,15 +8,40 @@ from tools.final_answer import FinalAnswerTool
|
|
| 8 |
from Gradio_UI import GradioUI
|
| 9 |
|
| 10 |
# Below is an example of a tool that does nothing. Amaze us with your creativity!
|
|
|
|
|
|
|
|
|
|
| 11 |
@tool
|
| 12 |
-
def
|
| 13 |
-
|
| 14 |
-
|
|
|
|
| 15 |
Args:
|
| 16 |
-
|
| 17 |
-
|
| 18 |
"""
|
| 19 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 20 |
|
| 21 |
@tool
|
| 22 |
def get_current_time_in_timezone(timezone: str) -> str:
|
|
|
|
| 8 |
from Gradio_UI import GradioUI
|
| 9 |
|
| 10 |
# Below is an example of a tool that does nothing. Amaze us with your creativity!
|
| 11 |
+
import requests
|
| 12 |
+
from smolagents import tool
|
| 13 |
+
|
| 14 |
@tool
|
| 15 |
+
def city_team_weather(city: str, team: str) -> str:
|
| 16 |
+
"""
|
| 17 |
+
Provides a fun weather-and-sports mashup based on the city and team name.
|
| 18 |
+
|
| 19 |
Args:
|
| 20 |
+
city: The city to get the weather for (e.g., "Boston")
|
| 21 |
+
team: The sports team name (e.g., "Red Sox")
|
| 22 |
"""
|
| 23 |
+
try:
|
| 24 |
+
# Use Open-Meteo API (no API key required for basic access)
|
| 25 |
+
url = f"https://api.open-meteo.com/v1/forecast?latitude=0&longitude=0¤t_weather=true"
|
| 26 |
+
geo_url = f"https://geocoding-api.open-meteo.com/v1/search?name={city}&count=1"
|
| 27 |
+
|
| 28 |
+
geo_resp = requests.get(geo_url).json()
|
| 29 |
+
if not geo_resp.get("results"):
|
| 30 |
+
return f"Could not find weather data for {city}."
|
| 31 |
+
|
| 32 |
+
lat = geo_resp["results"][0]["latitude"]
|
| 33 |
+
lon = geo_resp["results"][0]["longitude"]
|
| 34 |
+
|
| 35 |
+
weather_url = f"https://api.open-meteo.com/v1/forecast?latitude={lat}&longitude={lon}¤t_weather=true"
|
| 36 |
+
weather_resp = requests.get(weather_url).json()
|
| 37 |
+
weather = weather_resp["current_weather"]["temperature"]
|
| 38 |
+
|
| 39 |
+
return (
|
| 40 |
+
f"In {city}, it's currently {weather}°C. "
|
| 41 |
+
f"The {team} are heating up too—maybe it's the weather, maybe it's just game day vibes!"
|
| 42 |
+
)
|
| 43 |
+
except Exception as e:
|
| 44 |
+
return f"Error retrieving data: {str(e)}"
|
| 45 |
|
| 46 |
@tool
|
| 47 |
def get_current_time_in_timezone(timezone: str) -> str:
|