Spaces:
Sleeping
Sleeping
feat: add custom structure_daily_tasks_tool
Browse files
app.py
CHANGED
|
@@ -9,14 +9,46 @@ 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
|
| 13 |
-
|
| 14 |
-
|
|
|
|
| 15 |
Args:
|
| 16 |
-
|
| 17 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
| 18 |
"""
|
| 19 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 20 |
|
| 21 |
@tool
|
| 22 |
def get_current_time_in_timezone(timezone: str) -> str:
|
|
@@ -62,7 +94,7 @@ agent = CodeAgent(
|
|
| 62 |
get_current_time_in_timezone,
|
| 63 |
image_generation_tool,
|
| 64 |
web_search_tool,
|
| 65 |
-
|
| 66 |
], ## add your tools here (don't remove final answer)
|
| 67 |
max_steps=6,
|
| 68 |
verbosity_level=1,
|
|
|
|
| 9 |
|
| 10 |
# Below is an example of a tool that does nothing. Amaze us with your creativity !
|
| 11 |
@tool
|
| 12 |
+
def structure_daily_tasks_tool(tasks: list, start_time: str, end_time: str) -> str:
|
| 13 |
+
"""
|
| 14 |
+
Structure daily tasks within a given time frame.
|
| 15 |
+
|
| 16 |
Args:
|
| 17 |
+
tasks (list[str]): A list of tasks to be scheduled.
|
| 18 |
+
start_time (str): The start time in the format "HH:MM".
|
| 19 |
+
end_time (str): The end time in the format "HH:MM".
|
| 20 |
+
|
| 21 |
+
Returns:
|
| 22 |
+
str: A string representing the schedule of tasks with start and end times.
|
| 23 |
"""
|
| 24 |
+
from datetime import datetime, timedelta
|
| 25 |
+
|
| 26 |
+
# Convert start_time and end_time to datetime objects
|
| 27 |
+
start = datetime.strptime(start_time, "%H:%M")
|
| 28 |
+
end = datetime.strptime(end_time, "%H:%M")
|
| 29 |
+
|
| 30 |
+
# Calculate total available time in minutes
|
| 31 |
+
total_minutes = (end - start).seconds // 60
|
| 32 |
+
|
| 33 |
+
# Calculate the number of tasks
|
| 34 |
+
num_tasks = len(tasks)
|
| 35 |
+
|
| 36 |
+
# Calculate the average time per task
|
| 37 |
+
if num_tasks == 0:
|
| 38 |
+
return "No tasks to schedule."
|
| 39 |
+
|
| 40 |
+
average_time_per_task = total_minutes // num_tasks
|
| 41 |
+
|
| 42 |
+
# Create a schedule
|
| 43 |
+
schedule = []
|
| 44 |
+
current_time = start
|
| 45 |
+
|
| 46 |
+
for task in tasks:
|
| 47 |
+
task_end_time = current_time + timedelta(minutes=average_time_per_task)
|
| 48 |
+
schedule.append(f"{current_time.strftime('%H:%M')} - {task_end_time.strftime('%H:%M')}: {task}")
|
| 49 |
+
current_time = task_end_time
|
| 50 |
+
|
| 51 |
+
return "\n".join(schedule)
|
| 52 |
|
| 53 |
@tool
|
| 54 |
def get_current_time_in_timezone(timezone: str) -> str:
|
|
|
|
| 94 |
get_current_time_in_timezone,
|
| 95 |
image_generation_tool,
|
| 96 |
web_search_tool,
|
| 97 |
+
structure_daily_tasks_tool,
|
| 98 |
], ## add your tools here (don't remove final answer)
|
| 99 |
max_steps=6,
|
| 100 |
verbosity_level=1,
|