Elifslh commited on
Commit
105bcaf
·
verified ·
1 Parent(s): ae7a494

Update app.py

Browse files

feature: Add countdown tool to calculate time remaining until an event

Files changed (1) hide show
  1. app.py +26 -7
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
- # Below is an example of a tool that does nothing. Amaze us with your creativity !
11
  @tool
12
- def my_custom_tool(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
- """A tool that does nothing yet
15
  Args:
16
- arg1: the first argument
17
- arg2: the second argument
 
 
 
18
  """
19
- return "What magic will you build ?"
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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: