21spl commited on
Commit
cff0905
·
verified ·
1 Parent(s): 6b1f82c

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +12 -4
app.py CHANGED
@@ -18,7 +18,7 @@ HF_TOKEN = os.getenv("HF_TOKEN", "default_hf_token_if_not_found")
18
 
19
  @tool
20
  def get_weather(city: str) -> str:
21
- """Fetches the current weather for a specified city using Open-Meteo API (No API Key Needed).
22
  Args:
23
  city: The name of the city.
24
  """
@@ -33,15 +33,23 @@ def get_weather(city: str) -> str:
33
  else:
34
  return f"Error: Unable to find location for '{city}'."
35
 
36
- # Fetch weather data
37
- weather_url = f"https://api.open-meteo.com/v1/forecast?latitude={lat}&longitude={lon}&current_weather=true"
38
  weather_response = requests.get(weather_url)
39
 
40
  if weather_response.status_code == 200:
41
  weather_data = weather_response.json()["current_weather"]
 
42
  temp = weather_data["temperature"]
43
  wind_speed = weather_data["windspeed"]
44
- return f"Weather in {city}: Temp: {temp}°C, Wind Speed: {wind_speed} m/s"
 
 
 
 
 
 
 
45
  else:
46
  return "Error fetching weather data."
47
 
 
18
 
19
  @tool
20
  def get_weather(city: str) -> str:
21
+ """Fetches detailed weather information for a specified city using Open-Meteo API (No API Key Needed).
22
  Args:
23
  city: The name of the city.
24
  """
 
33
  else:
34
  return f"Error: Unable to find location for '{city}'."
35
 
36
+ # Fetch detailed weather data
37
+ weather_url = f"https://api.open-meteo.com/v1/forecast?latitude={lat}&longitude={lon}&current_weather=true&hourly=precipitation_probability,temperature_2m,humidity_2m,wind_speed_10m"
38
  weather_response = requests.get(weather_url)
39
 
40
  if weather_response.status_code == 200:
41
  weather_data = weather_response.json()["current_weather"]
42
+ hourly_data = weather_response.json()["hourly"]
43
  temp = weather_data["temperature"]
44
  wind_speed = weather_data["windspeed"]
45
+ humidity = hourly_data["humidity_2m"][0]
46
+ precipitation_chance = hourly_data["precipitation_probability"][0]
47
+
48
+ return (f"Weather in {city}:\n"
49
+ f"Temperature: {temp}°C\n"
50
+ f"Humidity: {humidity}%\n"
51
+ f"Wind Speed: {wind_speed} m/s\n"
52
+ f"Chance of Rain: {precipitation_chance}%")
53
  else:
54
  return "Error fetching weather data."
55