Spaces:
Sleeping
Sleeping
Update app.py
Browse filesfeature: Add countdown tool to calculate time remaining until an event
app.py
CHANGED
|
@@ -4,19 +4,38 @@ import requests
|
|
| 4 |
import pytz
|
| 5 |
import yaml
|
| 6 |
from tools.final_answer import FinalAnswerTool
|
|
|
|
| 7 |
|
| 8 |
from Gradio_UI import GradioUI
|
| 9 |
|
| 10 |
-
|
| 11 |
@tool
|
| 12 |
-
def
|
| 13 |
-
|
| 14 |
-
|
| 15 |
Args:
|
| 16 |
-
|
| 17 |
-
|
|
|
|
|
|
|
|
|
|
| 18 |
"""
|
| 19 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 20 |
|
| 21 |
@tool
|
| 22 |
def get_current_time_in_timezone(timezone: str) -> str:
|
|
|
|
| 4 |
import pytz
|
| 5 |
import yaml
|
| 6 |
from tools.final_answer import FinalAnswerTool
|
| 7 |
+
import datetime
|
| 8 |
|
| 9 |
from Gradio_UI import GradioUI
|
| 10 |
|
| 11 |
+
|
| 12 |
@tool
|
| 13 |
+
def countdown_tool(event_date: str, duration: int) -> str:
|
| 14 |
+
"""A tool that calculates the remaining time until a specified event.
|
| 15 |
+
|
| 16 |
Args:
|
| 17 |
+
event_date (str): The event date in the format "YYYY-MM-DD HH:MM".
|
| 18 |
+
duration (int): An unused parameter, kept for structure.
|
| 19 |
+
|
| 20 |
+
Returns:
|
| 21 |
+
str: A message indicating the time remaining until the event.
|
| 22 |
"""
|
| 23 |
+
try:
|
| 24 |
+
event_datetime = datetime.datetime.strptime(event_date, "%Y-%m-%d %H:%M")
|
| 25 |
+
now = datetime.datetime.now()
|
| 26 |
+
diff = event_datetime - now
|
| 27 |
+
|
| 28 |
+
if diff.total_seconds() < 0:
|
| 29 |
+
return f"The specified date ({event_date}) has already passed!"
|
| 30 |
+
|
| 31 |
+
days = diff.days
|
| 32 |
+
hours, remainder = divmod(diff.seconds, 3600)
|
| 33 |
+
minutes, _ = divmod(remainder, 60)
|
| 34 |
+
|
| 35 |
+
return f"Time remaining until the event: {days} days, {hours} hours, {minutes} minutes."
|
| 36 |
+
except Exception as e:
|
| 37 |
+
return f"Error: Invalid date format ({event_date}). Expected format: YYYY-MM-DD HH:MM"
|
| 38 |
+
|
| 39 |
|
| 40 |
@tool
|
| 41 |
def get_current_time_in_timezone(timezone: str) -> str:
|