Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
|
@@ -5,25 +5,39 @@ import pytz
|
|
| 5 |
import yaml
|
| 6 |
from tools.final_answer import FinalAnswerTool
|
| 7 |
from datetime import datetime, timedelta
|
|
|
|
| 8 |
from Gradio_UI import GradioUI
|
| 9 |
|
|
|
|
| 10 |
# Below is the new deadline calculator tool
|
| 11 |
@tool
|
| 12 |
-
def deadline_calculator(start_date: str, days: int) ->
|
| 13 |
-
"""
|
|
|
|
|
|
|
| 14 |
Args:
|
| 15 |
-
start_date: The starting date in 'YYYY-MM-DD'
|
| 16 |
-
days: The number of days until the deadline.
|
|
|
|
| 17 |
Returns:
|
| 18 |
-
A
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 19 |
"""
|
| 20 |
try:
|
| 21 |
start = datetime.strptime(start_date, "%Y-%m-%d")
|
| 22 |
deadline = start + timedelta(days=days)
|
| 23 |
weekday = deadline.strftime("%A")
|
| 24 |
-
|
| 25 |
except ValueError:
|
| 26 |
-
|
|
|
|
|
|
|
| 27 |
|
| 28 |
# Example usage:
|
| 29 |
# print(deadline_calculator("2025-02-18", 10))
|
|
|
|
| 5 |
import yaml
|
| 6 |
from tools.final_answer import FinalAnswerTool
|
| 7 |
from datetime import datetime, timedelta
|
| 8 |
+
import json
|
| 9 |
from Gradio_UI import GradioUI
|
| 10 |
|
| 11 |
+
|
| 12 |
# Below is the new deadline calculator tool
|
| 13 |
@tool
|
| 14 |
+
def deadline_calculator(start_date: str, days: int) -> str:
|
| 15 |
+
"""
|
| 16 |
+
A tool that calculates the deadline date based on a given start date and duration in days.
|
| 17 |
+
|
| 18 |
Args:
|
| 19 |
+
start_date (str): The starting date in the format 'YYYY-MM-DD'.
|
| 20 |
+
days (int): The number of days until the deadline.
|
| 21 |
+
|
| 22 |
Returns:
|
| 23 |
+
str: A JSON-formatted string containing:
|
| 24 |
+
- "Deadline" (str): The calculated deadline date in 'YYYY-MM-DD' format.
|
| 25 |
+
- "Day of Week" (str): The corresponding day of the week for the deadline.
|
| 26 |
+
- "Error" (str, optional): If an invalid date format is provided, an error message is returned.
|
| 27 |
+
|
| 28 |
+
Example:
|
| 29 |
+
>>> deadline_calculator("2025-02-18", 10)
|
| 30 |
+
'{"Deadline": "2025-02-28", "Day of Week": "Friday"}'
|
| 31 |
"""
|
| 32 |
try:
|
| 33 |
start = datetime.strptime(start_date, "%Y-%m-%d")
|
| 34 |
deadline = start + timedelta(days=days)
|
| 35 |
weekday = deadline.strftime("%A")
|
| 36 |
+
result = {"Deadline": deadline.strftime("%Y-%m-%d"), "Day of Week": weekday}
|
| 37 |
except ValueError:
|
| 38 |
+
result = {"Error": "Invalid date format. Please use 'YYYY-MM-DD'."}
|
| 39 |
+
|
| 40 |
+
return json.dumps(result) # Converts dictionary to a string
|
| 41 |
|
| 42 |
# Example usage:
|
| 43 |
# print(deadline_calculator("2025-02-18", 10))
|