Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
|
@@ -8,6 +8,7 @@ import json
|
|
| 8 |
import time
|
| 9 |
from requests_sse import EventSource
|
| 10 |
from Gradio_UI import GradioUI
|
|
|
|
| 11 |
|
| 12 |
# Below is an example of a tool that does nothing. Amaze us with your creativity !
|
| 13 |
@tool
|
|
@@ -71,6 +72,47 @@ def get_current_time_in_timezone(timezone: str) -> str:
|
|
| 71 |
return f"Error fetching time for timezone '{timezone}': {str(e)}"
|
| 72 |
|
| 73 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 74 |
final_answer = FinalAnswerTool()
|
| 75 |
|
| 76 |
# If the agent does not answer, the model is overloaded, please use another model or the following Hugging Face Endpoint that also contains qwen2.5 coder:
|
|
|
|
| 8 |
import time
|
| 9 |
from requests_sse import EventSource
|
| 10 |
from Gradio_UI import GradioUI
|
| 11 |
+
from dateutil.relativedelta import relativedelta
|
| 12 |
|
| 13 |
# Below is an example of a tool that does nothing. Amaze us with your creativity !
|
| 14 |
@tool
|
|
|
|
| 72 |
return f"Error fetching time for timezone '{timezone}': {str(e)}"
|
| 73 |
|
| 74 |
|
| 75 |
+
@tool
|
| 76 |
+
def get_time_difference(time1: str, timezone1: str, time2: str, timezone2: str) -> str:
|
| 77 |
+
"""A tool that calculates the time difference between two timestamps in different time zones.
|
| 78 |
+
Args:
|
| 79 |
+
time1: First timestamp in "YYYY-MM-DD HH:MM:SS" format.
|
| 80 |
+
timezone1: Time zone of the first timestamp (e.g., "America/New_York").
|
| 81 |
+
time2: Second timestamp in "YYYY-MM-DD HH:MM:SS" format.
|
| 82 |
+
timezone2: Time zone of the second timestamp (e.g., "Asia/Kolkata").
|
| 83 |
+
Returns:
|
| 84 |
+
str: Time difference as a human-readable string (e.g., "0 years, 0 months, 3 days, 4 hours, 2 minutes, 15 seconds").
|
| 85 |
+
"""
|
| 86 |
+
try:
|
| 87 |
+
# Convert input strings to timezone-aware datetime objects
|
| 88 |
+
tz1 = pytz.timezone(timezone1)
|
| 89 |
+
tz2 = pytz.timezone(timezone2)
|
| 90 |
+
|
| 91 |
+
dt1 = tz1.localize(datetime.datetime.strptime(time1, "%Y-%m-%d %H:%M:%S"))
|
| 92 |
+
dt2 = tz2.localize(datetime.datetime.strptime(time2, "%Y-%m-%d %H:%M:%S"))
|
| 93 |
+
|
| 94 |
+
# Calculate absolute difference
|
| 95 |
+
if dt1 > dt2:
|
| 96 |
+
dt1, dt2 = dt2, dt1 # Ensure dt1 is earlier for proper calculations
|
| 97 |
+
|
| 98 |
+
diff = relativedelta(dt2, dt1)
|
| 99 |
+
|
| 100 |
+
# Convert difference to human-readable format
|
| 101 |
+
result = []
|
| 102 |
+
if diff.years: result.append(f"{diff.years} years")
|
| 103 |
+
if diff.months: result.append(f"{diff.months} months")
|
| 104 |
+
if diff.days: result.append(f"{diff.days} days")
|
| 105 |
+
if diff.hours: result.append(f"{diff.hours} hours")
|
| 106 |
+
if diff.minutes: result.append(f"{diff.minutes} minutes")
|
| 107 |
+
if diff.seconds: result.append(f"{diff.seconds} seconds")
|
| 108 |
+
|
| 109 |
+
return ", ".join(result) if result else "0 seconds"
|
| 110 |
+
|
| 111 |
+
except Exception as e:
|
| 112 |
+
return f"Error calculating time difference: {str(e)}"
|
| 113 |
+
|
| 114 |
+
|
| 115 |
+
|
| 116 |
final_answer = FinalAnswerTool()
|
| 117 |
|
| 118 |
# If the agent does not answer, the model is overloaded, please use another model or the following Hugging Face Endpoint that also contains qwen2.5 coder:
|