Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
@@ -7,28 +7,41 @@ from tools.final_answer import FinalAnswerTool
|
|
7 |
|
8 |
from Gradio_UI import GradioUI
|
9 |
|
10 |
-
WEATHER_API_KEY = "52305581a21f4c9f93d144513250109"
|
11 |
|
|
|
|
|
|
|
|
|
|
|
|
|
12 |
|
13 |
@tool
|
14 |
def get_weather(city:str)-> str:
|
15 |
-
"""
|
|
|
|
|
16 |
Args:
|
17 |
-
city (str):
|
|
|
18 |
Returns:
|
19 |
-
str:
|
20 |
"""
|
21 |
-
|
22 |
try:
|
23 |
-
|
|
|
|
|
|
|
|
|
24 |
response = requests.get(url)
|
25 |
-
if response.
|
26 |
-
|
27 |
-
|
28 |
-
|
29 |
-
|
30 |
-
|
31 |
-
|
|
|
|
|
32 |
except Exception as e:
|
33 |
return f"Error: {str(e)}"
|
34 |
|
|
|
7 |
|
8 |
from Gradio_UI import GradioUI
|
9 |
|
|
|
10 |
|
11 |
+
CITY_COORDINATES = {
|
12 |
+
"Paris": (48.8566, 2.3522),
|
13 |
+
"Dakar": (14.6928, -17.4467),
|
14 |
+
"New York": (40.7128, -74.0060),
|
15 |
+
"Tokyo": (35.6895, 139.6917),
|
16 |
+
}
|
17 |
|
18 |
@tool
|
19 |
def get_weather(city:str)-> str:
|
20 |
+
"""
|
21 |
+
Fetch the current weather for a given city using Open-Meteo.
|
22 |
+
|
23 |
Args:
|
24 |
+
city (str): Name of the city (must be in CITY_COORDINATES)
|
25 |
+
|
26 |
Returns:
|
27 |
+
str: Text summary of the current temperature and wind speed.
|
28 |
"""
|
|
|
29 |
try:
|
30 |
+
if city not in CITY_COORDINATES:
|
31 |
+
return f"City '{city}' not found in coordinates table."
|
32 |
+
|
33 |
+
lat, lon = CITY_COORDINATES[city]
|
34 |
+
url = f"https://api.open-meteo.com/v1/forecast?latitude={lat}&longitude={lon}¤t_weather=true"
|
35 |
response = requests.get(url)
|
36 |
+
if response.status_code != 200:
|
37 |
+
return f"Error fetching weather for {city} (status: {response.status_code})"
|
38 |
+
|
39 |
+
data = response.json()
|
40 |
+
weather = data["current_weather"]
|
41 |
+
temp = weather["temperature"]
|
42 |
+
wind = weather["windspeed"]
|
43 |
+
return f"The current weather in {city}: {temp}°C, wind {wind} km/h"
|
44 |
+
|
45 |
except Exception as e:
|
46 |
return f"Error: {str(e)}"
|
47 |
|