Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
@@ -9,14 +9,29 @@ 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 |
-
|
|
|
18 |
"""
|
19 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
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 convert_timezone(time:str, input_timezone:str, output_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 returns given time with timezone to the user's requested timezone
|
15 |
Args:
|
16 |
+
time: A string representing a time in this formate (%Y-%m-%d %H:%M:%S)
|
17 |
+
input_timezone: A string representing a valid timezone (e.g., 'America/New_York')
|
18 |
+
output_timezone: A string representing a valid timezone, that users want to get time in that
|
19 |
"""
|
20 |
+
try:
|
21 |
+
input_time = datetime.strptime(time, "%Y-%m-%d %H:%M:%S")
|
22 |
+
|
23 |
+
# Localize to input timezone
|
24 |
+
input_timezone = pytz.timezone(input_tz)
|
25 |
+
localized_time = input_timezone.localize(input_time)
|
26 |
+
|
27 |
+
# Convert to output timezone
|
28 |
+
output_timezone = pytz.timezone(output_tz)
|
29 |
+
converted_time = localized_time.astimezone(output_timezone)
|
30 |
+
|
31 |
+
# Return formatted string
|
32 |
+
return f"The time in {output_timezone} is: {converted_time.strftime("%Y-%m-%d %H:%M:%S")}"
|
33 |
+
except Exception as e:
|
34 |
+
return f"Error converting time: {str(e)}"
|
35 |
|
36 |
@tool
|
37 |
def get_current_time_in_timezone(timezone: str) -> str:
|