Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
@@ -202,8 +202,9 @@ def show_emergency_resources():
|
|
202 |
# Get available times for selected therapist
|
203 |
def get_available_times(therapist):
|
204 |
if therapist and therapist in therapists:
|
205 |
-
|
206 |
-
|
|
|
207 |
|
208 |
# Create MIME message for Gmail API
|
209 |
def create_message(to, subject, message_text):
|
@@ -286,8 +287,8 @@ Mental Health Chatbot
|
|
286 |
def schedule_appointment(therapist, time_slot, date, user_email, state):
|
287 |
if not therapist or therapist not in therapists:
|
288 |
return "Please select a therapist.", state
|
289 |
-
if not time_slot
|
290 |
-
return "Please select a time
|
291 |
if not date:
|
292 |
return "Please select a date.", state
|
293 |
if not user_email or not re.match(r"[^@]+@[^@]+\.[^@]+", user_email):
|
@@ -303,7 +304,7 @@ def schedule_appointment(therapist, time_slot, date, user_email, state):
|
|
303 |
try:
|
304 |
appointment_time = datetime.strptime(time_slot, "%H:%M").strftime("%H:%M")
|
305 |
if appointment_time not in therapists[therapist]["times"]:
|
306 |
-
return f"Time {appointment_time} is not available for {therapist}.", state
|
307 |
except ValueError:
|
308 |
return "Invalid time format (use HH:MM).", state
|
309 |
|
@@ -324,28 +325,40 @@ def schedule_appointment(therapist, time_slot, date, user_email, state):
|
|
324 |
return (f"Appointment booked with {therapist} on {date} at {appointment_time}. "
|
325 |
f"Email sending failed: {error_msg}. Please contact {therapist_email}."), state
|
326 |
|
327 |
-
# Minimal CSS for date
|
328 |
custom_css = """
|
329 |
-
#date-picker input[type="date"] {
|
330 |
width: 100%;
|
331 |
-
padding:
|
332 |
-
border: 1px solid #
|
333 |
-
border-radius:
|
334 |
font-size: 16px;
|
|
|
335 |
}
|
336 |
-
#date-picker input[type="date"]
|
|
|
|
|
|
|
|
|
|
|
|
|
337 |
cursor: pointer;
|
338 |
}
|
339 |
"""
|
340 |
|
341 |
-
# JavaScript for date
|
342 |
custom_js = """
|
343 |
document.addEventListener('DOMContentLoaded', function() {
|
344 |
const dateInput = document.querySelector('#date-picker input');
|
|
|
345 |
if (dateInput) {
|
346 |
dateInput.type = 'date';
|
347 |
dateInput.placeholder = 'YYYY-MM-DD';
|
348 |
}
|
|
|
|
|
|
|
|
|
349 |
});
|
350 |
"""
|
351 |
|
@@ -415,12 +428,12 @@ with gr.Blocks(title="Mental Health Support Chatbot", css=custom_css, js=custom_
|
|
415 |
placeholder="Select date (YYYY-MM-DD)",
|
416 |
elem_id="date-picker"
|
417 |
)
|
418 |
-
time_slot = gr.
|
419 |
-
choices=["Select time"],
|
420 |
label="Appointment Time",
|
421 |
-
|
422 |
-
|
423 |
)
|
|
|
424 |
user_email = gr.Textbox(
|
425 |
label="Your Email",
|
426 |
placeholder="e.g., [email protected]"
|
@@ -466,7 +479,7 @@ with gr.Blocks(title="Mental Health Support Chatbot", css=custom_css, js=custom_
|
|
466 |
therapist.change(
|
467 |
fn=get_available_times,
|
468 |
inputs=therapist,
|
469 |
-
outputs=[time_slot,
|
470 |
)
|
471 |
schedule_btn.click(
|
472 |
fn=schedule_appointment,
|
|
|
202 |
# Get available times for selected therapist
|
203 |
def get_available_times(therapist):
|
204 |
if therapist and therapist in therapists:
|
205 |
+
times = therapists[therapist]["times"]
|
206 |
+
return times, f"Available times for {therapist}: {', '.join(times)}"
|
207 |
+
return [], "Please select a therapist."
|
208 |
|
209 |
# Create MIME message for Gmail API
|
210 |
def create_message(to, subject, message_text):
|
|
|
287 |
def schedule_appointment(therapist, time_slot, date, user_email, state):
|
288 |
if not therapist or therapist not in therapists:
|
289 |
return "Please select a therapist.", state
|
290 |
+
if not time_slot:
|
291 |
+
return "Please select a time.", state
|
292 |
if not date:
|
293 |
return "Please select a date.", state
|
294 |
if not user_email or not re.match(r"[^@]+@[^@]+\.[^@]+", user_email):
|
|
|
304 |
try:
|
305 |
appointment_time = datetime.strptime(time_slot, "%H:%M").strftime("%H:%M")
|
306 |
if appointment_time not in therapists[therapist]["times"]:
|
307 |
+
return f"Time {appointment_time} is not available for {therapist}. Please choose from available times.", state
|
308 |
except ValueError:
|
309 |
return "Invalid time format (use HH:MM).", state
|
310 |
|
|
|
325 |
return (f"Appointment booked with {therapist} on {date} at {appointment_time}. "
|
326 |
f"Email sending failed: {error_msg}. Please contact {therapist_email}."), state
|
327 |
|
328 |
+
# Minimal CSS for date and time pickers
|
329 |
custom_css = """
|
330 |
+
#date-picker input[type="date"], #time-picker input[type="time"] {
|
331 |
width: 100%;
|
332 |
+
padding: 10px;
|
333 |
+
border: 1px solid #d1d5db;
|
334 |
+
border-radius: 6px;
|
335 |
font-size: 16px;
|
336 |
+
box-sizing: border-box;
|
337 |
}
|
338 |
+
#date-picker input[type="date"]:focus, #time-picker input[type="time"]:focus {
|
339 |
+
border-color: #3b82f6;
|
340 |
+
outline: none;
|
341 |
+
box-shadow: 0 0 0 2px rgba(59, 130, 246, 0.2);
|
342 |
+
}
|
343 |
+
#date-picker input[type="date"]::-webkit-calendar-picker-indicator,
|
344 |
+
#time-picker input[type="time"]::-webkit-calendar-picker-indicator {
|
345 |
cursor: pointer;
|
346 |
}
|
347 |
"""
|
348 |
|
349 |
+
# JavaScript for date and time pickers
|
350 |
custom_js = """
|
351 |
document.addEventListener('DOMContentLoaded', function() {
|
352 |
const dateInput = document.querySelector('#date-picker input');
|
353 |
+
const timeInput = document.querySelector('#time-picker input');
|
354 |
if (dateInput) {
|
355 |
dateInput.type = 'date';
|
356 |
dateInput.placeholder = 'YYYY-MM-DD';
|
357 |
}
|
358 |
+
if (timeInput) {
|
359 |
+
timeInput.type = 'time';
|
360 |
+
timeInput.placeholder = 'HH:MM';
|
361 |
+
}
|
362 |
});
|
363 |
"""
|
364 |
|
|
|
428 |
placeholder="Select date (YYYY-MM-DD)",
|
429 |
elem_id="date-picker"
|
430 |
)
|
431 |
+
time_slot = gr.Textbox(
|
|
|
432 |
label="Appointment Time",
|
433 |
+
placeholder="Select time (HH:MM)",
|
434 |
+
elem_id="time-picker"
|
435 |
)
|
436 |
+
time_suggestions = gr.Markdown("Select a therapist to see available times.")
|
437 |
user_email = gr.Textbox(
|
438 |
label="Your Email",
|
439 |
placeholder="e.g., [email protected]"
|
|
|
479 |
therapist.change(
|
480 |
fn=get_available_times,
|
481 |
inputs=therapist,
|
482 |
+
outputs=[time_slot, time_suggestions]
|
483 |
)
|
484 |
schedule_btn.click(
|
485 |
fn=schedule_appointment,
|