Spaces:
Sleeping
Sleeping
Update app.py
#1
by
Gaston1704
- opened
app.py
CHANGED
|
@@ -9,14 +9,30 @@ 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:
|
|
|
|
| 9 |
|
| 10 |
# Below is an example of a tool that does nothing. Amaze us with your creativity !
|
| 11 |
@tool
|
| 12 |
+
def get_tunisia_weather() -> dict:
|
| 13 |
+
"""Fetches the current weather for all major cities in Tunisia."""
|
| 14 |
+
import requests
|
| 15 |
+
|
| 16 |
+
cities = ["Tunis", "Sfax", "Sousse", "Gabès", "Bizerte", "Nabeul", "Kairouan", "Gafsa", "Monastir", "Mahdia"]
|
| 17 |
+
api_key = "YOUR_API_KEY"
|
| 18 |
+
base_url = "http://api.openweathermap.org/data/2.5/weather"
|
| 19 |
+
|
| 20 |
+
weather_data = {}
|
| 21 |
+
|
| 22 |
+
for city in cities:
|
| 23 |
+
response = requests.get(base_url, params={"q": city + ",TN", "appid": api_key, "units": "metric"})
|
| 24 |
+
if response.status_code == 200:
|
| 25 |
+
data = response.json()
|
| 26 |
+
weather_data[city] = {
|
| 27 |
+
"temperature": data["main"]["temp"],
|
| 28 |
+
"humidity": data["main"]["humidity"],
|
| 29 |
+
"weather": data["weather"][0]["description"]
|
| 30 |
+
}
|
| 31 |
+
else:
|
| 32 |
+
weather_data[city] = "Weather data unavailable"
|
| 33 |
+
|
| 34 |
+
return weather_data
|
| 35 |
+
|
| 36 |
|
| 37 |
@tool
|
| 38 |
def get_current_time_in_timezone(timezone: str) -> str:
|