myatsu commited on
Commit
588447c
·
verified ·
1 Parent(s): 6ff8cc5

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +19 -11
app.py CHANGED
@@ -4,26 +4,34 @@ import requests
4
  import pytz
5
  import yaml
6
  from tools.final_answer import FinalAnswerTool
 
 
7
 
8
  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
- def get_weather(city)-> str: #it's import to specify the return type
13
  #Keep this format for the description / args / args description but feel free to modify the tool
14
  """A tool that retrives weather from a specified city
15
  city : the name of the city you want to know the weather
16
  """
17
- import requests
18
- api_url = f"https://api.weather.com/v1/location/{city}?apiKey=fc5de4ef7812c4aa77860ca1874f8ef9"
19
- response = requests.get(api_url)
20
- if response.status_code ==200:
21
- data = response.json()
22
- return data.get("weather", "No weather information available")
23
- else:
24
- return "Error: Unable to fetch weather data"
25
- result = get_weather(city)
26
- return f"The current weather in {city} is {result}."
 
 
 
 
 
 
27
 
28
  @tool
29
  def get_current_time_in_timezone(timezone: str) -> str:
 
4
  import pytz
5
  import yaml
6
  from tools.final_answer import FinalAnswerTool
7
+ import requests
8
+ from typing import str
9
 
10
  from Gradio_UI import GradioUI
11
 
12
  # Below is an example of a tool that does nothing. Amaze us with your creativity !
13
  @tool
14
+ def get_weather(city: str)-> str: #it's import to specify the return type
15
  #Keep this format for the description / args / args description but feel free to modify the tool
16
  """A tool that retrives weather from a specified city
17
  city : the name of the city you want to know the weather
18
  """
19
+ try:
20
+ api_url = f"https://api.weather.com/v1/location/{city}"
21
+ header = {
22
+ "Authorization" : "Bearer fc5de4ef7812c4aa77860ca1874f8ef9"
23
+ }
24
+ response = requests.get(api_url, header = headers, timeout = 10)
25
+ if response.status_code ==200:
26
+ data = response.json()
27
+ weather_info = data.get("weather", "No weather information available")
28
+ return f"The current weather in {city} is {weather_info}."
29
+ else:
30
+ return "Error: Unable to fetch weather data"
31
+ except requests.RequestException as e:
32
+ return f"Error: Network request failed - {str(e)}"
33
+ except Exception as e:
34
+ return f"Error: {str(e)}"
35
 
36
  @tool
37
  def get_current_time_in_timezone(timezone: str) -> str: