Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
|
@@ -7,16 +7,37 @@ from tools.final_answer import FinalAnswerTool
|
|
| 7 |
|
| 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 |
-
|
| 16 |
-
|
| 17 |
-
|
| 18 |
-
""
|
| 19 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 20 |
|
| 21 |
@tool
|
| 22 |
def get_current_time_in_timezone(timezone: str) -> str:
|
|
@@ -55,7 +76,7 @@ with open("prompts.yaml", 'r') as stream:
|
|
| 55 |
|
| 56 |
agent = CodeAgent(
|
| 57 |
model=model,
|
| 58 |
-
tools=[final_answer], ## add your tools here (don't remove final answer)
|
| 59 |
max_steps=6,
|
| 60 |
verbosity_level=1,
|
| 61 |
grammar=None,
|
|
|
|
| 7 |
|
| 8 |
from Gradio_UI import GradioUI
|
| 9 |
|
|
|
|
| 10 |
@tool
|
| 11 |
+
def get_weather(city: str) -> dict:
|
| 12 |
+
import requests
|
| 13 |
+
|
| 14 |
+
# 1. Geocodificación: convertir ciudad -> lat/lon
|
| 15 |
+
geo_url = f"https://geocoding-api.open-meteo.com/v1/search?name={city}&count=1&language=en&format=json"
|
| 16 |
+
geo_response = requests.get(geo_url)
|
| 17 |
+
if geo_response.status_code != 200 or "results" not in geo_response.json():
|
| 18 |
+
return "Error: City not found"
|
| 19 |
+
|
| 20 |
+
location = geo_response.json()["results"][0]
|
| 21 |
+
lat, lon = location["latitude"], location["longitude"]
|
| 22 |
+
|
| 23 |
+
# 2. Obtener datos de tiempo actual
|
| 24 |
+
api_url = f"https://api.open-meteo.com/v1/forecast?latitude={lat}&longitude={lon}¤t_weather=true"
|
| 25 |
+
response = requests.get(api_url)
|
| 26 |
+
|
| 27 |
+
if response.status_code == 200:
|
| 28 |
+
data = response.json()
|
| 29 |
+
weather = data.get("current_weather", {})
|
| 30 |
+
if weather:
|
| 31 |
+
return {
|
| 32 |
+
"temperature": weather.get("temperature"),
|
| 33 |
+
"windspeed": weather.get("windspeed"),
|
| 34 |
+
"weathercode": weather.get("weathercode"),
|
| 35 |
+
"time": weather.get("time")
|
| 36 |
+
}
|
| 37 |
+
else:
|
| 38 |
+
return {"Error": "No weather information available"}
|
| 39 |
+
else:
|
| 40 |
+
return {"Error": "Unable to fetch weather data."}
|
| 41 |
|
| 42 |
@tool
|
| 43 |
def get_current_time_in_timezone(timezone: str) -> str:
|
|
|
|
| 76 |
|
| 77 |
agent = CodeAgent(
|
| 78 |
model=model,
|
| 79 |
+
tools=[final_answer, get_weather], ## add your tools here (don't remove final answer)
|
| 80 |
max_steps=6,
|
| 81 |
verbosity_level=1,
|
| 82 |
grammar=None,
|