Ujeshhh commited on
Commit
2897fd5
·
verified ·
1 Parent(s): deccd69

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +28 -130
app.py CHANGED
@@ -32,12 +32,12 @@ def get_gmail_service():
32
  # Coping Strategies Library
33
  coping_strategies = {
34
  "happy": [
35
- "Keep the positivity flowing! Try writing down three things youre grateful for today.",
36
  "Share your joy! Call a friend or loved one to spread the good vibes."
37
  ],
38
  "sad": [
39
- "Its okay to feel this way. Try a gentle activity like listening to calming music or taking a short walk.",
40
- "Write down your thoughts in a journal to process whats on your mind."
41
  ],
42
  "anxious": [
43
  "Take slow, deep breaths: inhale for 4 seconds, hold for 4, exhale for 4.",
@@ -48,7 +48,7 @@ coping_strategies = {
48
  "Break tasks into smaller steps and tackle one at a time."
49
  ],
50
  "other": [
51
- "Reflect on whats on your mind with a quick mindfulness moment: focus on your breath for 60 seconds.",
52
  "Engage in a favorite hobby to lift your spirits."
53
  ]
54
  }
@@ -138,7 +138,7 @@ def chatbot_function(message, mood, conversation_mode, region, state):
138
  response = model.generate_content(prompt)
139
  response_text = response.text
140
  except Exception as e:
141
- response_text = f"I'm here for you, but something went wrong: {str(e)}. Please try again."
142
 
143
  if mood and mood != "Select mood":
144
  mood_key = mood.lower()
@@ -324,109 +324,8 @@ 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
- # Custom CSS for clean UI
328
- custom_css = """
329
- body {
330
- font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, Arial, sans-serif;
331
- background: #f5f7fa;
332
- color: #1a202c;
333
- }
334
-
335
- .gradio-container {
336
- max-width: 800px;
337
- margin: 20px auto;
338
- padding: 24px;
339
- background: #ffffff;
340
- border-radius: 12px;
341
- box-shadow: 0 2px 8px rgba(0, 0, 0, 0.1);
342
- }
343
-
344
- h1 {
345
- font-size: 1.8em;
346
- color: #2d3748;
347
- text-align: center;
348
- margin-bottom: 16px;
349
- }
350
-
351
- h2, h3 {
352
- color: #4a5568;
353
- }
354
-
355
- input, select, textarea {
356
- border: 1px solid #e2e8f0 !important;
357
- border-radius: 6px !important;
358
- padding: 8px !important;
359
- font-size: 1em !important;
360
- width: 100% !important;
361
- box-sizing: border-box;
362
- }
363
-
364
- input:focus, select:focus, textarea:focus {
365
- border-color: #3182ce !important;
366
- outline: none;
367
- box-shadow: 0 0 0 2px rgba(49, 130, 206, 0.2);
368
- }
369
-
370
- button {
371
- background: #3182ce !important;
372
- color: #ffffff !important;
373
- border: none !important;
374
- border-radius: 6px !important;
375
- padding: 10px 20px !important;
376
- font-size: 1em !important;
377
- cursor: pointer;
378
- transition: background 0.2s;
379
- }
380
-
381
- button:hover {
382
- background: #2b6cb0 !important;
383
- }
384
-
385
- textarea[readonly] {
386
- background: #edf2f7 !important;
387
- border-radius: 6px !important;
388
- padding: 12px !important;
389
- font-size: 1em;
390
- }
391
-
392
- #appointment-section .gr-box {
393
- background: #f7fafc !important;
394
- border-radius: 8px !important;
395
- padding: 16px !important;
396
- }
397
-
398
- #date-picker {
399
- width: 100%;
400
- }
401
-
402
- @media (max-width: 600px) {
403
- .gradio-container {
404
- padding: 16px;
405
- margin: 10px;
406
- }
407
- button {
408
- padding: 8px 16px !important;
409
- }
410
- }
411
- """
412
-
413
- # JavaScript for date picker
414
- custom_js = """
415
- document.addEventListener('DOMContentLoaded', function() {
416
- try {
417
- const dateInput = document.querySelector('#date-picker input');
418
- if (dateInput) {
419
- dateInput.type = 'date';
420
- dateInput.placeholder = 'YYYY-MM-DD';
421
- }
422
- } catch (e) {
423
- console.error('Date picker initialization failed:', e);
424
- }
425
- });
426
- """
427
-
428
  # Gradio Interface
429
- with gr.Blocks(title="Mental Health Support Chatbot", css=custom_css, js=custom_js) as demo:
430
  state = gr.State({"chat_history": [], "mood_journal": [], "feedback": [], "appointments": [], "failed_emails": []})
431
 
432
  gr.Markdown("## Mental Health Support Chatbot")
@@ -441,7 +340,7 @@ with gr.Blocks(title="Mental Health Support Chatbot", css=custom_css, js=custom_
441
  )
442
  conversation_mode = gr.Radio(
443
  choices=["Neutral", "Calm", "Motivational"],
444
- label="Style",
445
  value="Neutral"
446
  )
447
  region = gr.Dropdown(
@@ -451,57 +350,56 @@ with gr.Blocks(title="Mental Health Support Chatbot", css=custom_css, js=custom_
451
  )
452
  with gr.Column(scale=2):
453
  chatbot = gr.Textbox(
454
- label="Chat",
455
  value="",
456
  interactive=False,
457
  lines=10,
458
  show_copy_button=True
459
  )
460
  user_input = gr.Textbox(
461
- placeholder="Type your message...",
462
- label="Message",
463
  lines=2
464
  )
465
  with gr.Row():
466
- submit_btn = gr.Button("Send")
467
- clear_btn = gr.Button("Clear")
468
 
469
- emergency_btn = gr.Button("Crisis Support")
470
  emergency_output = gr.Markdown("")
471
 
472
  with gr.Accordion("Mood Journal"):
473
  log_mood_btn = gr.Button("Log Mood")
474
- mood_log_output = gr.Textbox(label="Status", interactive=False)
475
- mood_trend_btn = gr.Button("View Trends")
476
  mood_trend_output = gr.Plot()
477
 
478
- with gr.Accordion("Feedback"):
479
- feedback_text = gr.Textbox(label="Feedback", placeholder="Your thoughts...")
480
  feedback_rating = gr.Slider(minimum=1, maximum=5, step=1, label="Rating")
481
- feedback_btn = gr.Button("Submit")
482
- feedback_output = gr.Textbox(label="Status", interactive=False)
483
 
484
- with gr.Accordion("Schedule Appointment", elem_id="appointment-section"):
485
  therapist = gr.Dropdown(
486
  choices=list(therapists.keys()),
487
- label="Therapist"
488
  )
489
  date = gr.Textbox(
490
- label="Date",
491
- placeholder="YYYY-MM-DD",
492
- elem_id="date-picker"
493
  )
494
  time_slot = gr.Dropdown(
495
  choices=[],
496
- label="Time",
497
  interactive=True
498
  )
499
  user_email = gr.Textbox(
500
- label="Email",
501
- placeholder="[email protected]"
502
  )
503
- schedule_btn = gr.Button("Book")
504
- schedule_output = gr.Textbox(label="Status", interactive=False)
505
 
506
  submit_btn.click(
507
  fn=chatbot_function,
 
32
  # Coping Strategies Library
33
  coping_strategies = {
34
  "happy": [
35
+ "Keep the positivity flowing! Try writing down three things you're grateful for today.",
36
  "Share your joy! Call a friend or loved one to spread the good vibes."
37
  ],
38
  "sad": [
39
+ "It's okay to feel this way. Try a gentle activity like listening to calming music or taking a short walk.",
40
+ "Write down your thoughts in a journal to process what's on your mind."
41
  ],
42
  "anxious": [
43
  "Take slow, deep breaths: inhale for 4 seconds, hold for 4, exhale for 4.",
 
48
  "Break tasks into smaller steps and tackle one at a time."
49
  ],
50
  "other": [
51
+ "Reflect on what's on your mind with a quick mindfulness moment: focus on your breath for 60 seconds.",
52
  "Engage in a favorite hobby to lift your spirits."
53
  ]
54
  }
 
138
  response = model.generate_content(prompt)
139
  response_text = response.text
140
  except Exception as e:
141
+ response_text = "I'm here for you, but something went wrong. Please try again."
142
 
143
  if mood and mood != "Select mood":
144
  mood_key = mood.lower()
 
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
  # Gradio Interface
328
+ with gr.Blocks(title="Mental Health Support Chatbot") as demo:
329
  state = gr.State({"chat_history": [], "mood_journal": [], "feedback": [], "appointments": [], "failed_emails": []})
330
 
331
  gr.Markdown("## Mental Health Support Chatbot")
 
340
  )
341
  conversation_mode = gr.Radio(
342
  choices=["Neutral", "Calm", "Motivational"],
343
+ label="Conversation Style",
344
  value="Neutral"
345
  )
346
  region = gr.Dropdown(
 
350
  )
351
  with gr.Column(scale=2):
352
  chatbot = gr.Textbox(
353
+ label="Conversation",
354
  value="",
355
  interactive=False,
356
  lines=10,
357
  show_copy_button=True
358
  )
359
  user_input = gr.Textbox(
360
+ placeholder="Type your message here...",
361
+ label="Your Message",
362
  lines=2
363
  )
364
  with gr.Row():
365
+ submit_btn = gr.Button("Send Message")
366
+ clear_btn = gr.Button("Clear Chat")
367
 
368
+ emergency_btn = gr.Button("Show Crisis Support")
369
  emergency_output = gr.Markdown("")
370
 
371
  with gr.Accordion("Mood Journal"):
372
  log_mood_btn = gr.Button("Log Mood")
373
+ mood_log_output = gr.Textbox(label="Mood Log Status", interactive=False)
374
+ mood_trend_btn = gr.Button("View Mood Trends")
375
  mood_trend_output = gr.Plot()
376
 
377
+ with gr.Accordion("Provide Feedback"):
378
+ feedback_text = gr.Textbox(label="Your Feedback", placeholder="How can we improve?")
379
  feedback_rating = gr.Slider(minimum=1, maximum=5, step=1, label="Rating")
380
+ feedback_btn = gr.Button("Submit Feedback")
381
+ feedback_output = gr.Textbox(label="Feedback Status", interactive=False)
382
 
383
+ with gr.Accordion("Schedule Appointment"):
384
  therapist = gr.Dropdown(
385
  choices=list(therapists.keys()),
386
+ label="Select Therapist"
387
  )
388
  date = gr.Textbox(
389
+ label="Appointment Date",
390
+ placeholder="Enter date (YYYY-MM-DD)"
 
391
  )
392
  time_slot = gr.Dropdown(
393
  choices=[],
394
+ label="Appointment Time",
395
  interactive=True
396
  )
397
  user_email = gr.Textbox(
398
+ label="Your Email",
399
+ placeholder="e.g., [email protected]"
400
  )
401
+ schedule_btn = gr.Button("Book Appointment")
402
+ schedule_output = gr.Textbox(label="Booking Status", interactive=False)
403
 
404
  submit_btn.click(
405
  fn=chatbot_function,