Spaces:
Paused
Paused
Commit
Β·
47159d2
1
Parent(s):
c6313e4
fix: modify user_message function to fallback to an empty .ical if none provided
Browse files-Fixed empty calendar scheduling by adding fallback to use next Monday when no base_date can be determined from pinned tasks
-Added earliest_monday_on_or_after fallback in solve_schedule_from_state method to prevent ScheduleInfo.base_date being None
-Resolved AttributeError in constraint solver when processing empty calendar files
- src/services/schedule.py +9 -0
- src/ui/pages/chat.py +23 -4
- tests/data/empty.ics +16 -0
src/services/schedule.py
CHANGED
@@ -126,6 +126,15 @@ class ScheduleService:
|
|
126 |
base_date = earliest_date
|
127 |
logger.info(f"ποΈ Determined base_date for schedule: {base_date}")
|
128 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
129 |
# Convert DataFrame to tasks
|
130 |
tasks = DataService.convert_dataframe_to_tasks(task_df, base_date)
|
131 |
|
|
|
126 |
base_date = earliest_date
|
127 |
logger.info(f"ποΈ Determined base_date for schedule: {base_date}")
|
128 |
|
129 |
+
# If no base_date found from pinned tasks, use next Monday as default
|
130 |
+
if base_date is None:
|
131 |
+
from factory.data.generators import earliest_monday_on_or_after
|
132 |
+
|
133 |
+
base_date = earliest_monday_on_or_after(date.today())
|
134 |
+
logger.info(
|
135 |
+
f"ποΈ No pinned tasks found, using next Monday as base_date: {base_date}"
|
136 |
+
)
|
137 |
+
|
138 |
# Convert DataFrame to tasks
|
139 |
tasks = DataService.convert_dataframe_to_tasks(task_df, base_date)
|
140 |
|
src/ui/pages/chat.py
CHANGED
@@ -84,10 +84,12 @@ def draw_chat_page(debug: bool = False):
|
|
84 |
# π¬ Chat Agent Demo
|
85 |
|
86 |
This is a chat agent demo for Yuga Planner!
|
87 |
-
Insert a task description to have the agent schedule it standalone or around your calendar.
|
88 |
|
89 |
-
|
90 |
-
|
|
|
|
|
|
|
91 |
"""
|
92 |
)
|
93 |
|
@@ -213,8 +215,10 @@ def create_chatbot_parameters() -> tuple[gr.Textbox, gr.Slider, gr.Slider, gr.Sl
|
|
213 |
def user_message(message, history, calendar_file_obj):
|
214 |
# Handle calendar file upload
|
215 |
enhanced_message = message
|
|
|
|
|
216 |
if calendar_file_obj is not None:
|
217 |
-
# Read and encode the calendar file
|
218 |
try:
|
219 |
import base64
|
220 |
|
@@ -229,6 +233,21 @@ def user_message(message, history, calendar_file_obj):
|
|
229 |
except Exception as e:
|
230 |
logger.error(f"Error reading calendar file: {e}")
|
231 |
enhanced_message += f"\n\n[Calendar file upload failed: {str(e)}]"
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
232 |
|
233 |
return (
|
234 |
"", # Clear input
|
|
|
84 |
# π¬ Chat Agent Demo
|
85 |
|
86 |
This is a chat agent demo for Yuga Planner!
|
|
|
87 |
|
88 |
+
Insert a task description to have the agent schedule it standalone or around your existing calendar.
|
89 |
+
|
90 |
+
If you provide a .ics file, the schedule will start from **the first occupied time slot in your calendar file**.
|
91 |
+
|
92 |
+
If you don't, the schedule will start from **next monday**.
|
93 |
"""
|
94 |
)
|
95 |
|
|
|
215 |
def user_message(message, history, calendar_file_obj):
|
216 |
# Handle calendar file upload
|
217 |
enhanced_message = message
|
218 |
+
|
219 |
+
# Use provided calendar file or default to empty.ics
|
220 |
if calendar_file_obj is not None:
|
221 |
+
# Read and encode the uploaded calendar file
|
222 |
try:
|
223 |
import base64
|
224 |
|
|
|
233 |
except Exception as e:
|
234 |
logger.error(f"Error reading calendar file: {e}")
|
235 |
enhanced_message += f"\n\n[Calendar file upload failed: {str(e)}]"
|
236 |
+
else:
|
237 |
+
# Use empty.ics as default when no calendar is provided
|
238 |
+
try:
|
239 |
+
import base64
|
240 |
+
|
241 |
+
empty_calendar_path = "tests/data/empty.ics"
|
242 |
+
with open(empty_calendar_path, "rb") as f:
|
243 |
+
file_content = f.read()
|
244 |
+
|
245 |
+
encoded_content = base64.b64encode(file_content).decode("utf-8")
|
246 |
+
enhanced_message += f"\n\n[Default empty calendar used]"
|
247 |
+
enhanced_message += f"\n[CALENDAR_DATA:{encoded_content}]"
|
248 |
+
except Exception as e:
|
249 |
+
logger.error(f"Error reading default empty calendar: {e}")
|
250 |
+
enhanced_message += f"\n\n[Default calendar load failed: {str(e)}]"
|
251 |
|
252 |
return (
|
253 |
"", # Clear input
|
tests/data/empty.ics
ADDED
@@ -0,0 +1,16 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
BEGIN:VCALENDAR
|
2 |
+
PRODID:-//Mozilla.org/NONSGML Mozilla Calendar V1.1//EN
|
3 |
+
VERSION:2.0
|
4 |
+
BEGIN:VTIMEZONE
|
5 |
+
TZID:Africa/Lagos
|
6 |
+
LAST-MODIFIED:20240422T053450Z
|
7 |
+
TZURL:https://www.tzurl.org/zoneinfo-outlook/Africa/Lagos
|
8 |
+
X-LIC-LOCATION:Africa/Lagos
|
9 |
+
BEGIN:STANDARD
|
10 |
+
TZNAME:WAT
|
11 |
+
TZOFFSETFROM:+0100
|
12 |
+
TZOFFSETTO:+0100
|
13 |
+
DTSTART:19700101T000000
|
14 |
+
END:STANDARD
|
15 |
+
END:VTIMEZONE
|
16 |
+
END:VCALENDAR
|