ronak008 commited on
Commit
bc3d48b
·
verified ·
1 Parent(s): 58beba4

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +18 -5
app.py CHANGED
@@ -9,17 +9,30 @@ 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 my_name(name: str) -> str:
13
  """
14
  Fetches weather data for a given city using wttr.in and returns it as a formatted string.
15
 
16
- Args:
17
- city (str): The name of the city.
18
-
19
  Returns:
20
  str: Weather details including condition, temperature, humidity, and wind speed.
21
  """
22
- return("My name is Rtuek")
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
23
 
24
  @tool
25
  def get_current_time_in_timezone(timezone: str) -> str:
 
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) -> str:
13
  """
14
  Fetches weather data for a given city using wttr.in and returns it as a formatted string.
15
 
 
 
 
16
  Returns:
17
  str: Weather details including condition, temperature, humidity, and wind speed.
18
  """
19
+ url = f"https://wttr.in/{city}?format=%C+%t+%h+%w"
20
+
21
+ try:
22
+ response = requests.get(url)
23
+ if response.status_code == 200:
24
+ weather_data = response.text.strip().split()
25
+ if len(weather_data) == 4:
26
+ condition, temp, humidity, wind = weather_data
27
+ return f"Weather in {city}: Condition: {condition}, Temperature: {temp}, Humidity: {humidity}, Wind Speed: {wind}"
28
+ else:
29
+ return "Error: Unexpected weather data format."
30
+ else:
31
+ return f"Error: Unable to fetch weather data. Status code: {response.status_code}"
32
+ except Exception as e:
33
+ return f"Error: {e}"
34
+
35
+ final_answer = FinalAnswerTool()
36
 
37
  @tool
38
  def get_current_time_in_timezone(timezone: str) -> str: