Spaces:
Runtime error
Runtime error
Update app.py
Browse files
app.py
CHANGED
|
@@ -9,27 +9,33 @@ 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 |
-
"""
|
| 15 |
Args:
|
| 16 |
-
|
| 17 |
-
|
| 18 |
"""
|
| 19 |
-
return
|
|
|
|
| 20 |
|
| 21 |
-
@tool
|
| 22 |
-
def get_current_time_in_timezone(timezone: str) -> str:
|
| 23 |
-
"""A tool that fetches the current local time in a specified timezone.
|
| 24 |
-
Args:
|
| 25 |
-
timezone: A string representing a valid timezone (e.g., 'America/New_York').
|
| 26 |
-
"""
|
| 27 |
try:
|
| 28 |
-
# Create timezone object
|
| 29 |
tz = pytz.timezone(timezone)
|
| 30 |
-
|
| 31 |
-
|
| 32 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 33 |
except Exception as e:
|
| 34 |
return f"Error fetching time for timezone '{timezone}': {str(e)}"
|
| 35 |
|
|
|
|
| 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(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 |
+
"""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 |
+
return:
|
| 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")
|
| 26 |
+
|
| 27 |
+
# Determine time of day for a friendly greeting
|
| 28 |
+
hour = local_time.hour
|
| 29 |
+
if 5 <= hour < 12:
|
| 30 |
+
greeting = "Good morning! 🌅"
|
| 31 |
+
elif 12 <= hour < 18:
|
| 32 |
+
greeting = "Good afternoon! ☀️"
|
| 33 |
+
elif 18 <= hour < 22:
|
| 34 |
+
greeting = "Good evening! 🌆"
|
| 35 |
+
else:
|
| 36 |
+
greeting = "Good night! 🌙"
|
| 37 |
+
return f"{greeting} The current local time in {timezone} is {formatted_time}."
|
| 38 |
+
|
| 39 |
except Exception as e:
|
| 40 |
return f"Error fetching time for timezone '{timezone}': {str(e)}"
|
| 41 |
|