rchrdgwr commited on
Commit
e50ddd0
·
verified ·
1 Parent(s): fc127f3
Files changed (1) hide show
  1. app.py +13 -10
app.py CHANGED
@@ -11,6 +11,7 @@ from Gradio_UI import GradioUI
11
  from typing import TypedDict
12
 
13
  class SimpleWeather(TypedDict):
 
14
  city: str
15
  temperature: float
16
  condition: str
@@ -57,27 +58,29 @@ def get_population(country:str)-> str: #it's import to specify the return type
57
 
58
  @tool
59
  def get_weather(city:str) -> SimpleWeather:
60
- """Fetches weather data from WeatherAPI and returns a simplified weather report.
61
 
62
  Args:
63
  city (str): The name of the city to fetch weather data for.
64
 
65
  Returns:
66
- SimpleWeather: A dictionary containing the city's weather details.
 
 
 
 
 
 
 
 
 
67
  """
68
  API_KEY = os.getenv("WAPI")
69
  URL = f"http://api.weatherapi.com/v1/current.json?key={API_KEY}&q={city}&aqi=no"
70
  response = requests.get(URL)
71
  if response.status_code == 200:
72
  data = response.json()
73
- temperature = data["current"]["temp_f"]
74
- condition = data["current"]["condition"]["text"]
75
- humidity = data["current"]["humidity"]
76
- wind_speed = data["current"]["wind_kph"]
77
-
78
- print(f"Weather in {city}: {temperature}°F, {condition}")
79
- print(f"Humidity: {humidity}%")
80
- print(f"Wind Speed: {wind_speed} km/h")
81
  else:
82
  print(f"Error fetching weather data: {response.status_code}")
83
  return {
 
11
  from typing import TypedDict
12
 
13
  class SimpleWeather(TypedDict):
14
+ """Defines the simplified weather response object."""
15
  city: str
16
  temperature: float
17
  condition: str
 
58
 
59
  @tool
60
  def get_weather(city:str) -> SimpleWeather:
61
+ """Fetches the current weather for a specified city using WeatherAPI.
62
 
63
  Args:
64
  city (str): The name of the city to fetch weather data for.
65
 
66
  Returns:
67
+ SimpleWeather: A dictionary containing the following weather details:
68
+ - city (str): The city's name.
69
+ - temperature (float): The current temperature in Celsius.
70
+ - condition (str): The current weather condition (e.g., "Cloudy").
71
+ - humidity (int): The humidity percentage.
72
+ - wind_speed (float): The wind speed in km/h.
73
+
74
+ Raises:
75
+ ValueError: If the API key is missing.
76
+ requests.exceptions.RequestException: If the request fails.
77
  """
78
  API_KEY = os.getenv("WAPI")
79
  URL = f"http://api.weatherapi.com/v1/current.json?key={API_KEY}&q={city}&aqi=no"
80
  response = requests.get(URL)
81
  if response.status_code == 200:
82
  data = response.json()
83
+
 
 
 
 
 
 
 
84
  else:
85
  print(f"Error fetching weather data: {response.status_code}")
86
  return {