ApeMaster commited on
Commit
3401eb9
·
verified ·
1 Parent(s): 727630e

Update app.py

Browse files

updated weather tool -- modify weather tool display

Files changed (1) hide show
  1. app.py +8 -3
app.py CHANGED
@@ -15,6 +15,9 @@ from tools.final_answer import FinalAnswerTool
15
  from Gradio_UI import GradioUI
16
 
17
 
 
 
 
18
  # ---------------------------------------------------------------------------
19
  # Custom tool 1: Real-time weather (Open-Meteo — free, no API key required)
20
  # ---------------------------------------------------------------------------
@@ -36,7 +39,7 @@ def get_weather(city: str) -> str:
36
  loc = geo["results"][0]
37
  lat, lon = loc["latitude"], loc["longitude"]
38
 
39
- # 2) Fetch current weather at that location
40
  weather = requests.get(
41
  "https://api.open-meteo.com/v1/forecast",
42
  params={
@@ -44,12 +47,14 @@ def get_weather(city: str) -> str:
44
  "longitude": lon,
45
  "current_weather": "true",
46
  "timezone": "auto",
 
 
47
  },
48
  timeout=15,
49
  ).json()
50
 
51
  cur = weather.get("current_weather", {})
52
- temp_c = cur.get("temperature")
53
  windspeed = cur.get("windspeed")
54
  wmo = cur.get("weathercode", 0)
55
 
@@ -67,7 +72,7 @@ def get_weather(city: str) -> str:
67
 
68
  return (
69
  f"Current weather in {loc['name']}: {desc}, "
70
- f"{temp_c}°C, wind {windspeed} km/h."
71
  )
72
  except Exception as e:
73
  return f"Error fetching weather for '{city}': {str(e)}"
 
15
  from Gradio_UI import GradioUI
16
 
17
 
18
+ # ---------------------------------------------------------------------------
19
+ # Custom tool 1: Real-time weather (Open-Meteo — free, no API key required)
20
+ # ---------------------------------------------------------------------------
21
  # ---------------------------------------------------------------------------
22
  # Custom tool 1: Real-time weather (Open-Meteo — free, no API key required)
23
  # ---------------------------------------------------------------------------
 
39
  loc = geo["results"][0]
40
  lat, lon = loc["latitude"], loc["longitude"]
41
 
42
+ # 2) Fetch current weather at that location (request imperial units directly)
43
  weather = requests.get(
44
  "https://api.open-meteo.com/v1/forecast",
45
  params={
 
47
  "longitude": lon,
48
  "current_weather": "true",
49
  "timezone": "auto",
50
+ "temperature_unit": "fahrenheit",
51
+ "windspeed_unit": "mph",
52
  },
53
  timeout=15,
54
  ).json()
55
 
56
  cur = weather.get("current_weather", {})
57
+ temp_f = cur.get("temperature")
58
  windspeed = cur.get("windspeed")
59
  wmo = cur.get("weathercode", 0)
60
 
 
72
 
73
  return (
74
  f"Current weather in {loc['name']}: {desc}, "
75
+ f"{temp_f}°F, wind {windspeed} mph."
76
  )
77
  except Exception as e:
78
  return f"Error fetching weather for '{city}': {str(e)}"