Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
|
@@ -34,6 +34,32 @@ def get_current_time_in_timezone(timezone: str) -> str:
|
|
| 34 |
return f"Error fetching time for timezone '{timezone}': {str(e)}"
|
| 35 |
|
| 36 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 37 |
final_answer = FinalAnswerTool()
|
| 38 |
|
| 39 |
# If the agent does not answer, the model is overloaded, please use another model or the following Hugging Face Endpoint that also contains qwen2.5 coder:
|
|
|
|
| 34 |
return f"Error fetching time for timezone '{timezone}': {str(e)}"
|
| 35 |
|
| 36 |
|
| 37 |
+
@tool
|
| 38 |
+
def get_city_weather_brief(city: str) -> str:
|
| 39 |
+
"""Fetch today's temperature and rain chance for a city (using Open-Meteo geocoding + forecast).
|
| 40 |
+
Args:
|
| 41 |
+
city: City name, e.g., 'London'
|
| 42 |
+
"""
|
| 43 |
+
try:
|
| 44 |
+
geo = requests.get("https://geocoding-api.open-meteo.com/v1/search", params={"name": city, "count": 1}).json()
|
| 45 |
+
if not geo.get("results"):
|
| 46 |
+
return f"Could not find coordinates for '{city}'."
|
| 47 |
+
lat = geo["results"][0]["latitude"]
|
| 48 |
+
lon = geo["results"][0]["longitude"]
|
| 49 |
+
forecast = requests.get("https://api.open-meteo.com/v1/forecast", params={
|
| 50 |
+
"latitude": lat, "longitude": lon, "hourly": "temperature_2m,precipitation_probability",
|
| 51 |
+
"current_weather": True, "timezone": "auto"
|
| 52 |
+
}).json()
|
| 53 |
+
cw = forecast.get("current_weather", {})
|
| 54 |
+
temp = cw.get("temperature")
|
| 55 |
+
rain_probs = forecast.get("hourly", {}).get("precipitation_probability", [])
|
| 56 |
+
likely_rain = max(rain_probs[:12]) if rain_probs else 0
|
| 57 |
+
suggestion = "Great for a walk." if (temp is not None and temp >= 18 and likely_rain < 30) else "Maybe plan indoor activities."
|
| 58 |
+
return f"{city}: {temp}°C now. Max rain chance (next 12h): {likely_rain}%. Suggestion: {suggestion}"
|
| 59 |
+
except Exception as e:
|
| 60 |
+
return f"Weather error for '{city}': {e}"
|
| 61 |
+
|
| 62 |
+
|
| 63 |
final_answer = FinalAnswerTool()
|
| 64 |
|
| 65 |
# If the agent does not answer, the model is overloaded, please use another model or the following Hugging Face Endpoint that also contains qwen2.5 coder:
|