ronak008 commited on
Commit
0163bef
·
verified ·
1 Parent(s): 212bdd4

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +23 -6
app.py CHANGED
@@ -9,14 +9,31 @@ 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_custom_tool(arg1:str, arg2:int)-> 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 does nothing yet
 
15
  Args:
16
- arg1: the first argument
17
- arg2: the second argument
 
 
18
  """
19
- return "What magic will you build ?"
 
 
 
 
 
 
 
 
 
 
 
 
 
 
20
 
21
  @tool
22
  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_wttr(city: 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
+ url = f"https://wttr.in/{city}?format=%C+%t+%h+%w"
23
+
24
+ try:
25
+ response = requests.get(url)
26
+ if response.status_code == 200:
27
+ weather_data = response.text.strip().split()
28
+ if len(weather_data) == 4:
29
+ condition, temp, humidity, wind = weather_data
30
+ return f"Weather in {city}: Condition: {condition}, Temperature: {temp}, Humidity: {humidity}, Wind Speed: {wind}"
31
+ else:
32
+ return "Error: Unexpected weather data format."
33
+ else:
34
+ return f"Error: Unable to fetch weather data. Status code: {response.status_code}"
35
+ except Exception as e:
36
+ return f"Error: {e}"
37
 
38
  @tool
39
  def get_current_time_in_timezone(timezone: str) -> str: