Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
@@ -316,4 +316,253 @@ def schedule_appointment(therapist, time_slot, date, user_email, state):
|
|
316 |
|
317 |
# Custom CSS for beautiful UI
|
318 |
custom_css = """
|
319 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
316 |
|
317 |
# Custom CSS for beautiful UI
|
318 |
custom_css = """
|
319 |
+
/* General Styling */
|
320 |
+
body {
|
321 |
+
font-family: 'Inter', sans-serif;
|
322 |
+
background-color: #f0f4f8;
|
323 |
+
}
|
324 |
+
|
325 |
+
/* Containers */
|
326 |
+
.gradio-container {
|
327 |
+
max-width: 900px;
|
328 |
+
margin: 0 auto;
|
329 |
+
padding: 20px;
|
330 |
+
background: white;
|
331 |
+
border-radius: 16px;
|
332 |
+
box-shadow: 0 4px 20px rgba(0, 0, 0, 0.1);
|
333 |
+
}
|
334 |
+
|
335 |
+
/* Headings */
|
336 |
+
h1 {
|
337 |
+
color: #2c3e50;
|
338 |
+
font-size: 2.5em;
|
339 |
+
text-align: center;
|
340 |
+
margin-bottom: 10px;
|
341 |
+
}
|
342 |
+
|
343 |
+
h2, h3 {
|
344 |
+
color: #34495e;
|
345 |
+
}
|
346 |
+
|
347 |
+
/* Inputs and Buttons */
|
348 |
+
input, select, textarea {
|
349 |
+
border-radius: 8px !important;
|
350 |
+
border: 1px solid #d1d9e0 !important;
|
351 |
+
padding: 10px !important;
|
352 |
+
transition: border-color 0.2s;
|
353 |
+
}
|
354 |
+
|
355 |
+
input:focus, select:focus, textarea:focus {
|
356 |
+
border-color: #3498db !important;
|
357 |
+
outline: none;
|
358 |
+
}
|
359 |
+
|
360 |
+
button {
|
361 |
+
background: linear-gradient(90deg, #3498db, #2980b9) !important;
|
362 |
+
color: white !important;
|
363 |
+
border: none !important;
|
364 |
+
border-radius: 8px !important;
|
365 |
+
padding: 12px 24px !important;
|
366 |
+
font-weight: 600 !important;
|
367 |
+
transition: transform 0.2s, box-shadow 0.2s !important;
|
368 |
+
}
|
369 |
+
|
370 |
+
button:hover {
|
371 |
+
transform: translateY(-2px) !important;
|
372 |
+
box-shadow: 0 4px 12px rgba(0, 0, 0, 0.2) !important;
|
373 |
+
}
|
374 |
+
|
375 |
+
/* Chatbox */
|
376 |
+
textarea[readonly] {
|
377 |
+
background: #f8fafc !important;
|
378 |
+
border-radius: 12px !important;
|
379 |
+
padding: 15px !important;
|
380 |
+
}
|
381 |
+
|
382 |
+
/* Appointment Section */
|
383 |
+
#appointment-section .gr-box {
|
384 |
+
background: #e6f0fa !important;
|
385 |
+
border-radius: 12px !important;
|
386 |
+
padding: 20px !important;
|
387 |
+
}
|
388 |
+
|
389 |
+
/* Date and Time Pickers */
|
390 |
+
#date-picker input, #time-picker input {
|
391 |
+
width: 100%;
|
392 |
+
padding: 10px;
|
393 |
+
border: 1px solid #d1d9e0;
|
394 |
+
border-radius: 8px;
|
395 |
+
font-size: 1em;
|
396 |
+
cursor: pointer;
|
397 |
+
}
|
398 |
+
|
399 |
+
#date-picker input::-webkit-calendar-picker-indicator,
|
400 |
+
#time-picker input::-webkit-calendar-picker-indicator {
|
401 |
+
cursor: pointer;
|
402 |
+
}
|
403 |
+
|
404 |
+
/* Responsive Design */
|
405 |
+
@media (max-width: 600px) {
|
406 |
+
.gradio-container {
|
407 |
+
padding: 15px;
|
408 |
+
}
|
409 |
+
button {
|
410 |
+
padding: 10px 20px !important;
|
411 |
+
}
|
412 |
+
}
|
413 |
+
"""
|
414 |
+
|
415 |
+
# JavaScript to convert textboxes to date/time pickers
|
416 |
+
custom_js = """
|
417 |
+
document.addEventListener('DOMContentLoaded', function() {
|
418 |
+
// Convert date textbox to date picker
|
419 |
+
const dateInput = document.querySelector('#date-picker input');
|
420 |
+
if (dateInput) {
|
421 |
+
dateInput.type = 'date';
|
422 |
+
dateInput.placeholder = 'Select a date';
|
423 |
+
}
|
424 |
+
|
425 |
+
// Convert time textbox to time picker
|
426 |
+
const timeInput = document.querySelector('#time-picker input');
|
427 |
+
if (timeInput) {
|
428 |
+
timeInput.type = 'time';
|
429 |
+
timeInput.step = '1800'; // 30-minute intervals
|
430 |
+
timeInput.placeholder = 'Select a time';
|
431 |
+
}
|
432 |
+
});
|
433 |
+
"""
|
434 |
+
|
435 |
+
# Gradio Interface
|
436 |
+
with gr.Blocks(title="Mental Health Support Chatbot", css=custom_css, js=custom_js) as demo:
|
437 |
+
state = gr.State({"chat_history": [], "mood_journal": [], "feedback": [], "appointments": [], "failed_emails": []})
|
438 |
+
|
439 |
+
gr.Markdown("# Mental Health Support Chatbot")
|
440 |
+
gr.Markdown("A safe space to share how you're feeling, with tools to support your well-being.")
|
441 |
+
|
442 |
+
with gr.Row():
|
443 |
+
with gr.Column(scale=3):
|
444 |
+
mood = gr.Dropdown(
|
445 |
+
choices=["Select mood (optional)", "Happy", "Sad", "Anxious", "Stressed", "Other"],
|
446 |
+
label="How are you feeling today?",
|
447 |
+
value="Select mood (optional)"
|
448 |
+
)
|
449 |
+
conversation_mode = gr.Radio(
|
450 |
+
choices=["Neutral", "Calm", "Motivational"],
|
451 |
+
label="Conversation Style",
|
452 |
+
value="Neutral"
|
453 |
+
)
|
454 |
+
region = gr.Dropdown(
|
455 |
+
choices=["USA", "India", "UK", "Global"],
|
456 |
+
label="Your Region",
|
457 |
+
value="Global"
|
458 |
+
)
|
459 |
+
with gr.Column(scale=7):
|
460 |
+
chatbot = gr.Textbox(
|
461 |
+
label="Conversation",
|
462 |
+
value="",
|
463 |
+
interactive=False,
|
464 |
+
lines=12,
|
465 |
+
show_copy_button=True
|
466 |
+
)
|
467 |
+
user_input = gr.Textbox(
|
468 |
+
placeholder="Type your message here...",
|
469 |
+
label="Your Message",
|
470 |
+
lines=2
|
471 |
+
)
|
472 |
+
with gr.Row():
|
473 |
+
submit_btn = gr.Button("Send")
|
474 |
+
clear_btn = gr.Button("Clear Chat")
|
475 |
+
|
476 |
+
emergency_btn = gr.Button("Emergency Resources")
|
477 |
+
emergency_output = gr.Markdown("")
|
478 |
+
|
479 |
+
with gr.Accordion("Mood Journal"):
|
480 |
+
log_mood_btn = gr.Button("Log Mood")
|
481 |
+
mood_log_output = gr.Textbox(label="Mood Log Status", interactive=False)
|
482 |
+
mood_trend_btn = gr.Button("Show Mood Trends")
|
483 |
+
mood_trend_output = gr.Plot()
|
484 |
+
|
485 |
+
with gr.Accordion("Provide Feedback"):
|
486 |
+
feedback_text = gr.Textbox(label="Your Feedback", placeholder="How can we improve?")
|
487 |
+
feedback_rating = gr.Slider(minimum=1, maximum=5, step=1, label="Rate this interaction")
|
488 |
+
feedback_btn = gr.Button("Submit Feedback")
|
489 |
+
feedback_output = gr.Textbox(label="Feedback Status", interactive=False)
|
490 |
+
|
491 |
+
with gr.Accordion("Schedule Appointment", elem_id="appointment-section"):
|
492 |
+
therapist = gr.Dropdown(
|
493 |
+
choices=list(therapists.keys()),
|
494 |
+
label="Select a Therapist"
|
495 |
+
)
|
496 |
+
date = gr.Textbox(
|
497 |
+
label="Appointment Date",
|
498 |
+
placeholder="Select a date (YYYY-MM-DD)",
|
499 |
+
elem_id="date-picker"
|
500 |
+
)
|
501 |
+
time_slot = gr.Textbox(
|
502 |
+
label="Appointment Time",
|
503 |
+
placeholder="Select a time (HH:MM)",
|
504 |
+
elem_id="time-picker"
|
505 |
+
)
|
506 |
+
user_email = gr.Textbox(
|
507 |
+
label="Your Email Address",
|
508 |
+
placeholder="e.g., [email protected]"
|
509 |
+
)
|
510 |
+
schedule_btn = gr.Button("Book Appointment")
|
511 |
+
schedule_output = gr.Textbox(label="Booking Status", interactive=False)
|
512 |
+
|
513 |
+
submit_btn.click(
|
514 |
+
fn=chatbot_function,
|
515 |
+
inputs=[user_input, mood, conversation_mode, region, state],
|
516 |
+
outputs=[chatbot, state]
|
517 |
+
)
|
518 |
+
user_input.submit(
|
519 |
+
fn=chatbot_function,
|
520 |
+
inputs=[user_input, mood, conversation_mode, region, state],
|
521 |
+
outputs=[chatbot, state]
|
522 |
+
)
|
523 |
+
clear_btn.click(
|
524 |
+
fn=clear_chat,
|
525 |
+
inputs=[state],
|
526 |
+
outputs=[chatbot, state]
|
527 |
+
)
|
528 |
+
emergency_btn.click(
|
529 |
+
fn=show_emergency_resources,
|
530 |
+
inputs=None,
|
531 |
+
outputs=emergency_output
|
532 |
+
)
|
533 |
+
log_mood_btn.click(
|
534 |
+
fn=log_mood,
|
535 |
+
inputs=[mood, state],
|
536 |
+
outputs=[mood_log_output, state]
|
537 |
+
)
|
538 |
+
mood_trend_btn.click(
|
539 |
+
fn=show_mood_trends,
|
540 |
+
inputs=[state],
|
541 |
+
outputs=[mood_trend_output, state]
|
542 |
+
)
|
543 |
+
feedback_btn.click(
|
544 |
+
fn=submit_feedback,
|
545 |
+
inputs=[feedback_text, feedback_rating, state],
|
546 |
+
outputs=[feedback_output, state]
|
547 |
+
)
|
548 |
+
therapist.change(
|
549 |
+
fn=get_available_times,
|
550 |
+
inputs=therapist,
|
551 |
+
outputs=schedule_output
|
552 |
+
)
|
553 |
+
schedule_btn.click(
|
554 |
+
fn=schedule_appointment,
|
555 |
+
inputs=[therapist, time_slot, date, user_email, state],
|
556 |
+
outputs=[schedule_output, state]
|
557 |
+
)
|
558 |
+
|
559 |
+
gr.Markdown("""
|
560 |
+
---
|
561 |
+
**Helpful Resources:**
|
562 |
+
- [National Suicide Prevention Lifeline](https://suicidepreventionlifeline.org/)
|
563 |
+
- [MentalHealth.gov](https://www.mentalhealth.gov/)
|
564 |
+
- [Crisis Text Line](https://www.crisistextline.org/)
|
565 |
+
""")
|
566 |
+
|
567 |
+
if __name__ == "__main__":
|
568 |
+
demo.launch()
|