Spaces:
Runtime error
Runtime error
Luis
commited on
Update app.py
Browse files
app.py
CHANGED
|
@@ -11,17 +11,29 @@ from Gradio_UI import GradioUI
|
|
| 11 |
|
| 12 |
# Belo is an example of a tool that does nothing. Amaze us with your creativity !
|
| 13 |
@tool
|
| 14 |
-
def time_left_for_event(
|
| 15 |
"""A tool that calculates the time left for a certain event, and returns in a very convenient way the time between today and that events date
|
| 16 |
Args:
|
| 17 |
-
|
| 18 |
-
|
|
|
|
|
|
|
|
|
|
| 19 |
"""
|
| 20 |
|
| 21 |
-
|
| 22 |
-
|
| 23 |
-
|
| 24 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 25 |
|
| 26 |
|
| 27 |
|
|
|
|
| 11 |
|
| 12 |
# Belo is an example of a tool that does nothing. Amaze us with your creativity !
|
| 13 |
@tool
|
| 14 |
+
def time_left_for_event(event:str, date:str)-> str: #it's import to specify the return type
|
| 15 |
"""A tool that calculates the time left for a certain event, and returns in a very convenient way the time between today and that events date
|
| 16 |
Args:
|
| 17 |
+
event: the event name, this can be wedding, birthday, trip, travel, work event, reunion, etc..
|
| 18 |
+
sate: the day of that event in calendar time
|
| 19 |
+
|
| 20 |
+
Returns:
|
| 21 |
+
A string telling the user how many months, weeks or days are left before the event date
|
| 22 |
"""
|
| 23 |
|
| 24 |
+
try:
|
| 25 |
+
# Calculate Todays date
|
| 26 |
+
today = datetime.datetime.now()
|
| 27 |
+
# calculate the events date difference
|
| 28 |
+
difference = event_date - today
|
| 29 |
+
# Convert the difference into months, weeks or days
|
| 30 |
+
if difference < 7:
|
| 31 |
+
ans = f"{difference} days"
|
| 32 |
+
elif difference > 7:
|
| 33 |
+
ans = f"{difference} weeks"
|
| 34 |
+
return f"you have the following time: {ans}"
|
| 35 |
+
except Exception as e:
|
| 36 |
+
return f"Error: {e}"
|
| 37 |
|
| 38 |
|
| 39 |
|