Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
|
@@ -19,19 +19,29 @@ def my_cutom_tool(arg1:str, arg2:int)-> str: #it's import to specify the return
|
|
| 19 |
return "What magic will you build ?"
|
| 20 |
|
| 21 |
@tool
|
| 22 |
-
def get_current_time_in_timezone(timezone: str) ->
|
| 23 |
-
"""
|
|
|
|
| 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 |
|
| 36 |
|
| 37 |
final_answer = FinalAnswerTool()
|
|
|
|
| 19 |
return "What magic will you build ?"
|
| 20 |
|
| 21 |
@tool
|
| 22 |
+
def get_current_time_in_timezone(timezone: str) -> dict:
|
| 23 |
+
"""Fetches the current local time in a specified timezone and provides a human-friendly description.
|
| 24 |
+
|
| 25 |
Args:
|
| 26 |
timezone: A string representing a valid timezone (e.g., 'America/New_York').
|
| 27 |
+
|
| 28 |
+
Returns:
|
| 29 |
+
A dictionary containing the raw datetime string and a human-readable message.
|
| 30 |
"""
|
| 31 |
try:
|
|
|
|
| 32 |
tz = pytz.timezone(timezone)
|
| 33 |
+
local_time = datetime.datetime.now(tz)
|
| 34 |
+
formatted_time = local_time.strftime("%Y-%m-%d %H:%M:%S")
|
| 35 |
+
|
| 36 |
+
response = {
|
| 37 |
+
"datetime": formatted_time,
|
| 38 |
+
"message": f"The current local time in {timezone.replace('_', ' ')} is {formatted_time}."
|
| 39 |
+
}
|
| 40 |
+
return response
|
| 41 |
+
|
| 42 |
except Exception as e:
|
| 43 |
+
return {"error": f"Error fetching time for timezone '{timezone}': {str(e)}"}
|
| 44 |
+
|
| 45 |
|
| 46 |
|
| 47 |
final_answer = FinalAnswerTool()
|