Update app.py
#216
by
Gulzat
- opened
app.py
CHANGED
@@ -9,29 +9,37 @@ 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
|
13 |
#Keep this format for the description / args / args description but feel free to modify the tool
|
14 |
-
"""A tool that
|
15 |
Args:
|
16 |
-
|
17 |
-
arg2: the second argument
|
18 |
"""
|
19 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
20 |
|
21 |
@tool
|
22 |
-
def
|
23 |
-
"""A tool that fetches the current
|
24 |
Args:
|
25 |
-
|
26 |
"""
|
27 |
try:
|
28 |
-
|
29 |
-
|
30 |
# Get current time in that timezone
|
31 |
-
|
32 |
-
|
|
|
|
|
|
|
33 |
except Exception as e:
|
34 |
-
return f"Error fetching
|
35 |
|
36 |
|
37 |
final_answer = FinalAnswerTool()
|
|
|
9 |
|
10 |
# Below is an example of a tool that does nothing. Amaze us with your creativity !
|
11 |
@tool
|
12 |
+
def get_current_time_in_timezone(timezone: str)-> 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 fetches the current local time in a specified timezone
|
15 |
Args:
|
16 |
+
timezone: A string representing a valid timezone (e.g., 'America/New_York').
|
|
|
17 |
"""
|
18 |
+
|
19 |
+
try:
|
20 |
+
tz = pytz.timezone(timezone)
|
21 |
+
local_time = datetime.datetime.now(tz).strftime("%Y-%m-%d %H:%M:%S")
|
22 |
+
return f"The current local time in {timezone} is: {local_time}"
|
23 |
+
except Exception as e:
|
24 |
+
return f"Error fetching time for timezone '{timezone}': {str(e)}"
|
25 |
|
26 |
@tool
|
27 |
+
def get_weather(city: str) -> str:
|
28 |
+
"""A tool that fetches the current weather for a given city.
|
29 |
Args:
|
30 |
+
city: Name of the city (e.g., 'New York').
|
31 |
"""
|
32 |
try:
|
33 |
+
url = f"https://wttr.in{city}?format=%C+%t"
|
34 |
+
response = requests.get(url)
|
35 |
# Get current time in that timezone
|
36 |
+
if response.status_code == 200:
|
37 |
+
return f"The current weather in {city} is: {respnonse.text}"
|
38 |
+
else:
|
39 |
+
return "Failed to retrieve weather data."
|
40 |
+
|
41 |
except Exception as e:
|
42 |
+
return f"Error fetching weather: {str(e)}"
|
43 |
|
44 |
|
45 |
final_answer = FinalAnswerTool()
|