Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
@@ -121,7 +121,7 @@ therapists = {
|
|
121 |
}
|
122 |
|
123 |
# Initialize Gemini model
|
124 |
-
model = genai.GenerativeModel("
|
125 |
generation_config={"temperature": 0.7, "max_output_tokens": 200})
|
126 |
|
127 |
# Chatbot function
|
@@ -185,7 +185,7 @@ def chatbot_function(message, mood, conversation_mode, region, state):
|
|
185 |
if user_msg:
|
186 |
chat_display += f"🧑: {user_msg}\n\n"
|
187 |
if bot_msg:
|
188 |
-
chat_display += f"
|
189 |
|
190 |
return chat_display, state
|
191 |
|
@@ -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 therapists[therapist]["times"]
|
231 |
-
return ["Select time"]
|
232 |
|
233 |
# Create MIME message for Gmail API
|
234 |
def create_message(to, subject, message_text):
|
@@ -246,14 +246,11 @@ def send_emails(therapist, time_slot, date, user_email, therapist_email, state):
|
|
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,14 +258,11 @@ Healora
|
|
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,8 +320,8 @@ def schedule_appointment(therapist, time_slot, date, user_email, state):
|
|
326 |
return "Invalid date format (use YYYY-MM-DD).", state
|
327 |
|
328 |
try:
|
329 |
-
#
|
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,8 +414,7 @@ with gr.Blocks(title="Healora Chatbot", css=custom_css) as demo:
|
|
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,7 +425,6 @@ with gr.Blocks(title="Healora Chatbot", css=custom_css) as demo:
|
|
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,7 +467,7 @@ with gr.Blocks(title="Healora Chatbot", css=custom_css) as demo:
|
|
475 |
therapist.change(
|
476 |
fn=get_available_times,
|
477 |
inputs=therapist,
|
478 |
-
outputs=time_slot
|
479 |
)
|
480 |
schedule_btn.click(
|
481 |
fn=schedule_appointment,
|
|
|
121 |
}
|
122 |
|
123 |
# Initialize Gemini model
|
124 |
+
model = genai.GenerativeModel("gemini-1.5-flash",
|
125 |
generation_config={"temperature": 0.7, "max_output_tokens": 200})
|
126 |
|
127 |
# Chatbot function
|
|
|
185 |
if user_msg:
|
186 |
chat_display += f"🧑: {user_msg}\n\n"
|
187 |
if bot_msg:
|
188 |
+
chat_display += f"🤗: {bot_msg}\n\n"
|
189 |
|
190 |
return chat_display, state
|
191 |
|
|
|
227 |
# Get available times for selected therapist
|
228 |
def get_available_times(therapist):
|
229 |
if therapist and therapist in therapists:
|
230 |
+
return gr.update(choices=therapists[therapist]["times"], value=None), f"Available times for {therapist} loaded."
|
231 |
+
return gr.update(choices=["Select time"], value=None), "Please select a therapist."
|
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 |
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 |
|
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 |
return "Invalid date format (use YYYY-MM-DD).", state
|
321 |
|
322 |
try:
|
323 |
+
# Convert 12-hour format to 24-hour for validation
|
324 |
+
appointment_time = datetime.strptime(time_slot, "%I:%M %p").strftime("%H:%M")
|
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 |
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 |
choices=["Select time"],
|
426 |
label="Time",
|
427 |
interactive=True,
|
|
|
428 |
allow_custom_value=True
|
429 |
)
|
430 |
user_email = gr.Textbox(
|
|
|
467 |
therapist.change(
|
468 |
fn=get_available_times,
|
469 |
inputs=therapist,
|
470 |
+
outputs=[time_slot, schedule_output]
|
471 |
)
|
472 |
schedule_btn.click(
|
473 |
fn=schedule_appointment,
|