Spaces:
Runtime error
Runtime error
Update app.py
Browse files
app.py
CHANGED
|
@@ -9,17 +9,21 @@ 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_time_with_context(
|
| 13 |
#Keep this format for the description / args / args description but feel free to modify the tool
|
| 14 |
"""fetches the current local time in a specified timezone and provides a contextual message.
|
| 15 |
Args:
|
| 16 |
-
timezone: A valid timezone string (e.g., 'America/New_York', 'Asia/Tokyo').
|
|
|
|
| 17 |
|
| 18 |
-
"""
|
| 19 |
Returns:
|
| 20 |
-
A string with the current time and contextual greeting message.
|
| 21 |
-
|
| 22 |
try:
|
|
|
|
|
|
|
|
|
|
|
|
|
| 23 |
tz = pytz.timezone(timezone)
|
| 24 |
local_time = datetime.datetime.now(tz)
|
| 25 |
formatted_time = local_time.strftime("%Y-%m-%d %H:%M:%S")
|
|
@@ -37,7 +41,7 @@ def get_time_with_context(arg1:str, arg2:int)-> str: #it's import to specify the
|
|
| 37 |
return f"{greeting} The current local time in {timezone} is {formatted_time}."
|
| 38 |
|
| 39 |
except Exception as e:
|
| 40 |
-
return f"
|
| 41 |
|
| 42 |
|
| 43 |
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_time_with_context(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 |
"""fetches the current local time in a specified timezone and provides a contextual message.
|
| 15 |
Args:
|
| 16 |
+
timezone (str): A valid timezone string (e.g., 'America/New_York', 'Asia/Tokyo').
|
| 17 |
+
|
| 18 |
|
|
|
|
| 19 |
Returns:
|
| 20 |
+
str: A string with the current time and contextual greeting message.
|
| 21 |
+
"""
|
| 22 |
try:
|
| 23 |
+
# Validate timezone
|
| 24 |
+
if timezone not in pytz.all_timezones:
|
| 25 |
+
return f"⚠️ Error: '{timezone}' is not a recognized timezone. Please provide a valid timezone."
|
| 26 |
+
|
| 27 |
tz = pytz.timezone(timezone)
|
| 28 |
local_time = datetime.datetime.now(tz)
|
| 29 |
formatted_time = local_time.strftime("%Y-%m-%d %H:%M:%S")
|
|
|
|
| 41 |
return f"{greeting} The current local time in {timezone} is {formatted_time}."
|
| 42 |
|
| 43 |
except Exception as e:
|
| 44 |
+
return f"⚠️ Unexpected Error: {str(e)}"
|
| 45 |
|
| 46 |
|
| 47 |
final_answer = FinalAnswerTool()
|