Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
@@ -227,8 +227,8 @@ def show_emergency_resources(region):
|
|
227 |
# Get available times for selected therapist
|
228 |
def get_available_times(therapist):
|
229 |
if therapist and therapist in therapists:
|
230 |
-
return
|
231 |
-
return
|
232 |
|
233 |
# Create MIME message for Gmail API
|
234 |
def create_message(to, subject, message_text):
|
@@ -246,11 +246,14 @@ def send_emails(therapist, time_slot, date, user_email, therapist_email, state):
|
|
246 |
|
247 |
therapist_body = f"""
|
248 |
Dear {therapist},
|
|
|
249 |
You have a new appointment:
|
250 |
- Date: {date}
|
251 |
- Time: {time_slot}
|
252 |
- Client Email: {user_email}
|
|
|
253 |
Please confirm with the client.
|
|
|
254 |
Best,
|
255 |
Healora
|
256 |
"""
|
@@ -258,11 +261,14 @@ Healora
|
|
258 |
|
259 |
user_body = f"""
|
260 |
Dear User,
|
|
|
261 |
Your appointment has been successfully booked! We’re here to support your mental health journey. You’ll hear from your therapist soon to confirm the details.
|
|
|
262 |
Details:
|
263 |
- Therapist: {therapist}
|
264 |
- Date: {date}
|
265 |
- Time: {time_slot}
|
|
|
266 |
Best,
|
267 |
Healora
|
268 |
"""
|
@@ -320,8 +326,8 @@ def schedule_appointment(therapist, time_slot, date, user_email, state):
|
|
320 |
return "Invalid date format (use YYYY-MM-DD).", state
|
321 |
|
322 |
try:
|
323 |
-
#
|
324 |
-
|
325 |
if time_slot not in therapists[therapist]["times"]:
|
326 |
return f"Time {time_slot} is not available for {therapist}.", state
|
327 |
except ValueError:
|
@@ -414,7 +420,8 @@ with gr.Blocks(title="Healora Chatbot", css=custom_css) as demo:
|
|
414 |
with gr.Accordion("Appointments"):
|
415 |
therapist = gr.Dropdown(
|
416 |
choices=list(therapists.keys()),
|
417 |
-
label="Select Therapist"
|
|
|
418 |
)
|
419 |
date = gr.Textbox(
|
420 |
label="Date",
|
@@ -425,6 +432,7 @@ with gr.Blocks(title="Healora Chatbot", css=custom_css) as demo:
|
|
425 |
choices=["Select time"],
|
426 |
label="Time",
|
427 |
interactive=True,
|
|
|
428 |
allow_custom_value=True
|
429 |
)
|
430 |
user_email = gr.Textbox(
|
@@ -467,7 +475,7 @@ with gr.Blocks(title="Healora Chatbot", css=custom_css) as demo:
|
|
467 |
therapist.change(
|
468 |
fn=get_available_times,
|
469 |
inputs=therapist,
|
470 |
-
outputs=
|
471 |
)
|
472 |
schedule_btn.click(
|
473 |
fn=schedule_appointment,
|
|
|
227 |
# Get available times for selected therapist
|
228 |
def get_available_times(therapist):
|
229 |
if therapist and therapist in therapists:
|
230 |
+
return therapists[therapist]["times"]
|
231 |
+
return ["Select time"]
|
232 |
|
233 |
# Create MIME message for Gmail API
|
234 |
def create_message(to, subject, message_text):
|
|
|
246 |
|
247 |
therapist_body = f"""
|
248 |
Dear {therapist},
|
249 |
+
|
250 |
You have a new appointment:
|
251 |
- Date: {date}
|
252 |
- Time: {time_slot}
|
253 |
- Client Email: {user_email}
|
254 |
+
|
255 |
Please confirm with the client.
|
256 |
+
|
257 |
Best,
|
258 |
Healora
|
259 |
"""
|
|
|
261 |
|
262 |
user_body = f"""
|
263 |
Dear User,
|
264 |
+
|
265 |
Your appointment has been successfully booked! We’re here to support your mental health journey. You’ll hear from your therapist soon to confirm the details.
|
266 |
+
|
267 |
Details:
|
268 |
- Therapist: {therapist}
|
269 |
- Date: {date}
|
270 |
- Time: {time_slot}
|
271 |
+
|
272 |
Best,
|
273 |
Healora
|
274 |
"""
|
|
|
326 |
return "Invalid date format (use YYYY-MM-DD).", state
|
327 |
|
328 |
try:
|
329 |
+
# Validate 12-hour format
|
330 |
+
datetime.strptime(time_slot, "%I:%M %p")
|
331 |
if time_slot not in therapists[therapist]["times"]:
|
332 |
return f"Time {time_slot} is not available for {therapist}.", state
|
333 |
except ValueError:
|
|
|
420 |
with gr.Accordion("Appointments"):
|
421 |
therapist = gr.Dropdown(
|
422 |
choices=list(therapists.keys()),
|
423 |
+
label="Select Therapist",
|
424 |
+
value=None
|
425 |
)
|
426 |
date = gr.Textbox(
|
427 |
label="Date",
|
|
|
432 |
choices=["Select time"],
|
433 |
label="Time",
|
434 |
interactive=True,
|
435 |
+
value=None,
|
436 |
allow_custom_value=True
|
437 |
)
|
438 |
user_email = gr.Textbox(
|
|
|
475 |
therapist.change(
|
476 |
fn=get_available_times,
|
477 |
inputs=therapist,
|
478 |
+
outputs=time_slot
|
479 |
)
|
480 |
schedule_btn.click(
|
481 |
fn=schedule_appointment,
|