nizar125 commited on
Commit
dacd7cb
·
verified ·
1 Parent(s): 773857a
Files changed (1) hide show
  1. app.py +10 -8
app.py CHANGED
@@ -9,23 +9,24 @@ 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
  @tool
13
  def get_weather(city: str) -> str:
14
  """
15
- Gets current weather for a given city using OpenWeatherMap API.
16
-
17
  Args:
18
- city: City name (e.g., "Tunis", "London")
19
-
20
  Returns:
21
- Weather description and temperature.
22
  """
23
  try:
24
  import requests
25
 
26
  api_key = "5499415a1e8327b9200f4df7eb114c11"
27
 
28
- # Step 1: Get coordinates from city name
29
  geo_url = f"http://api.openweathermap.org/geo/1.0/direct?q={city}&limit=1&appid={api_key}"
30
  geo_response = requests.get(geo_url).json()
31
 
@@ -35,7 +36,7 @@ def get_weather(city: str) -> str:
35
  lat = geo_response[0]["lat"]
36
  lon = geo_response[0]["lon"]
37
 
38
- # Step 2: Get current weather using coordinates
39
  weather_url = f"https://api.openweathermap.org/data/3.0/onecall?lat={lat}&lon={lon}&exclude=minutely,hourly,daily,alerts&appid={api_key}&units=metric"
40
  weather_data = requests.get(weather_url).json()
41
 
@@ -45,7 +46,8 @@ def get_weather(city: str) -> str:
45
  return f"The current weather in {city} is '{description}' with a temperature of {temp}°C."
46
 
47
  except Exception as e:
48
- return f"Error fetching weather data: {str(e)}"
 
49
 
50
 
51
  @tool
 
9
 
10
  # Below is an example of a tool that does nothing. Amaze us with your creativity !
11
  @tool
12
+
13
  @tool
14
  def get_weather(city: str) -> str:
15
  """
16
+ Fetches current weather for a given city using OpenWeatherMap API.
17
+
18
  Args:
19
+ city: Name of the city (e.g., "Paris", "Tunis")
20
+
21
  Returns:
22
+ A string describing the current weather.
23
  """
24
  try:
25
  import requests
26
 
27
  api_key = "5499415a1e8327b9200f4df7eb114c11"
28
 
29
+ # Step 1: Get coordinates
30
  geo_url = f"http://api.openweathermap.org/geo/1.0/direct?q={city}&limit=1&appid={api_key}"
31
  geo_response = requests.get(geo_url).json()
32
 
 
36
  lat = geo_response[0]["lat"]
37
  lon = geo_response[0]["lon"]
38
 
39
+ # Step 2: Get weather
40
  weather_url = f"https://api.openweathermap.org/data/3.0/onecall?lat={lat}&lon={lon}&exclude=minutely,hourly,daily,alerts&appid={api_key}&units=metric"
41
  weather_data = requests.get(weather_url).json()
42
 
 
46
  return f"The current weather in {city} is '{description}' with a temperature of {temp}°C."
47
 
48
  except Exception as e:
49
+ return f"Error fetching weather: {str(e)}"
50
+
51
 
52
 
53
  @tool