EMMA commited on
Commit
490a29b
·
1 Parent(s): 1740bed

update code

Browse files
Files changed (1) hide show
  1. app.py +61 -70
app.py CHANGED
@@ -550,14 +550,6 @@ def _load_session_transcript(user_data: dict, session_id):
550
 
551
  def create_gradio_interface(service_context, api_keys):
552
  custom_css = """
553
- .login-page-centered {
554
- max-width: 440px;
555
- margin: 60px auto !important;
556
- padding: 24px;
557
- border: 1px solid #e5e7eb;
558
- border-radius: 12px;
559
- box-shadow: 0 2px 12px rgba(0,0,0,0.06);
560
- }
561
  .send-btn {
562
  border: 3px solid #0066cc !important;
563
  border-radius: 12px !important;
@@ -661,31 +653,60 @@ body:has(.progress-level)::before {
661
 
662
  with gr.Row():
663
  # ==========================================
664
- # 1. LOGIN PAGE (Left Sidebar)
 
 
 
665
  # ==========================================
666
- with gr.Column(visible=True, elem_classes=["login-page-centered"]) as login_page:
667
- gr.Markdown("<h1 style='text-align: center;'>🧠 EMMA</h1><h3 style='text-align: center;'>Your Empathetic Mental Health Assistant</h3><br><p style='text-align: center;'>Please login or register to begin.</p>")
668
-
669
- username_input = gr.Textbox(label="Your Name (Required)", placeholder="e.g., Alex")
670
- password_input = gr.Textbox(label="Password (Required)", placeholder="Enter your password", type="password")
671
-
672
- login_status = gr.Textbox(
673
- visible=False,
674
- label="Status",
675
- interactive=False,
676
- lines=1,
677
- max_lines=10
678
- )
679
-
680
- check_user_btn = gr.Button("🔍 Login / Check", variant="primary", elem_classes=["login-btn"])
681
-
682
- with gr.Column(visible=False) as registration_fields:
683
- gr.Markdown("### ✨ New User Registration")
684
- age_input = gr.Textbox(label="Age", placeholder="e.g., 28")
685
- gender_input = gr.Dropdown(label="Gender", choices=["Male", "Female", "Other"])
686
- occupation_input = gr.Textbox(label="Occupation", placeholder="e.g., Student...")
687
- residence_input = gr.Textbox(label="Place of Residence", placeholder="e.g., Berlin")
688
- register_btn = gr.Button("🎯 Complete Registration", variant="primary", elem_classes=["login-btn"])
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
689
 
690
  # ==========================================
691
  # 2. CHAT PAGE (Main Column)
@@ -716,36 +737,6 @@ body:has(.progress-level)::before {
716
  switch_user_btn = gr.Button("👥 Logout", elem_classes=["action-btn"])
717
  system_msg = gr.Textbox(label="🔔 System Messages", interactive=False, max_lines=2)
718
 
719
- # ==========================================
720
- # 3. HISTORY SIDEBAR (hidden until logged in)
721
- # ==========================================
722
- # NOTE: gr.Sidebar's visibility toggle is `open`, not `visible` --
723
- # matching the pattern already used for login_page above, since
724
- # that's the property confirmed to work in this codebase.
725
- with gr.Sidebar(open=False, position="right") as history_sidebar:
726
- gr.Markdown("### 📜 Past Sessions")
727
- session_radio = gr.Radio(
728
- choices=[],
729
- label="Select a session to view",
730
- interactive=True,
731
- )
732
- history_viewer = gr.Chatbot(
733
- label="Viewing past session (read-only)",
734
- height=350,
735
- )
736
- resume_session_btn = gr.Button(
737
- "▶️ Resume This Session",
738
- variant="primary",
739
- elem_classes=["action-btn"],
740
- )
741
- with gr.Row():
742
- rename_input = gr.Textbox(
743
- placeholder="New name for selected session...",
744
- show_label=False,
745
- scale=3,
746
- )
747
- rename_btn = gr.Button("✏️ Rename", scale=1)
748
-
749
  # -------------------------------------------------------
750
  # Internal Functions
751
  # -------------------------------------------------------
@@ -782,7 +773,7 @@ body:has(.progress-level)::before {
782
  gr.update(value=f"<h2 style='text-align: center; color: #333;'>🧠 EMMA: Session for {name}</h2>"),
783
  gr.update(value=welcome_msg),
784
  new_state,
785
- gr.update(open=True),
786
  gr.update(choices=_build_session_choices(memory[name]), value=None),
787
  gr.update(value=[]),
788
  )
@@ -871,7 +862,7 @@ body:has(.progress-level)::before {
871
  ),
872
  gr.update(value=welcome_msg),
873
  new_state,
874
- gr.update(open=True),
875
  gr.update(choices=[], value=None), # brand-new user: no past sessions yet
876
  gr.update(value=[]),
877
  )
@@ -911,7 +902,7 @@ body:has(.progress-level)::before {
911
  gr.update(value=""),
912
  gr.update(value=""),
913
  gr.update(value=""),
914
- gr.update(open=False),
915
  gr.update(choices=[], value=None),
916
  gr.update(value=[]),
917
  gr.update(value="<h2 style='text-align: center; color: #333;'>🧠 EMMA: Session</h2>"),
@@ -1069,7 +1060,7 @@ body:has(.progress-level)::before {
1069
  gr.update(value=transcript),
1070
  state,
1071
  gr.update(value=new_header),
1072
- gr.update(open=False),
1073
  gr.update(choices=_build_session_choices(user_data), value=None),
1074
  gr.update(value=[]),
1075
  gr.update(value=f"✅ Resumed session: {resumed_label}.", visible=True),
@@ -1168,19 +1159,19 @@ body:has(.progress-level)::before {
1168
  check_user_btn.click(
1169
  handle_login_check,
1170
  inputs=[username_input, password_input, state],
1171
- outputs=[login_page, registration_fields, chat_page, login_status, active_header, system_msg, state, history_sidebar, session_radio, history_viewer],
1172
  )
1173
 
1174
  register_btn.click(
1175
  handle_register,
1176
  inputs=[username_input, password_input, age_input, gender_input, occupation_input, residence_input, state],
1177
- outputs=[login_page, registration_fields, chat_page, login_status, active_header, system_msg, state, history_sidebar, session_radio, history_viewer],
1178
  )
1179
 
1180
  switch_user_btn.click(
1181
  switch_user,
1182
  inputs=[state],
1183
- outputs=[login_page, registration_fields, chat_page, login_status, username_input, password_input, state, chatbot, age_input, gender_input, occupation_input, residence_input, system_msg, history_sidebar, session_radio, history_viewer, active_header],
1184
  )
1185
 
1186
  submit_btn.click(
@@ -1216,7 +1207,7 @@ body:has(.progress-level)::before {
1216
  resume_session_btn.click(
1217
  handle_resume_session,
1218
  inputs=[session_radio, state],
1219
- outputs=[chatbot, state, active_header, history_sidebar, session_radio, history_viewer, system_msg],
1220
  )
1221
 
1222
  rename_btn.click(
 
550
 
551
  def create_gradio_interface(service_context, api_keys):
552
  custom_css = """
 
 
 
 
 
 
 
 
553
  .send-btn {
554
  border: 3px solid #0066cc !important;
555
  border-radius: 12px !important;
 
653
 
654
  with gr.Row():
655
  # ==========================================
656
+ # 1. LEFT SIDEBAR -- combined login + history.
657
+ # A single gr.Sidebar (rather than a plain Column + a second
658
+ # Sidebar) so mobile gets Gradio's built-in responsive drawer
659
+ # behavior instead of two separate blocks stacking awkwardly.
660
  # ==========================================
661
+ with gr.Sidebar(open=True) as main_sidebar:
662
+
663
+ with gr.Column(visible=True) as login_section:
664
+ gr.Markdown("<h1 style='text-align: center;'>🧠 EMMA</h1><h3 style='text-align: center;'>Your Empathetic Mental Health Assistant</h3><br><p style='text-align: center;'>Please login or register to begin.</p>")
665
+
666
+ username_input = gr.Textbox(label="Your Name (Required)", placeholder="e.g., Alex")
667
+ password_input = gr.Textbox(label="Password (Required)", placeholder="Enter your password", type="password")
668
+
669
+ login_status = gr.Textbox(
670
+ visible=False,
671
+ label="Status",
672
+ interactive=False,
673
+ lines=1,
674
+ max_lines=10
675
+ )
676
+
677
+ check_user_btn = gr.Button("🔍 Login / Check", variant="primary", elem_classes=["login-btn"])
678
+
679
+ with gr.Column(visible=False) as registration_fields:
680
+ gr.Markdown("### ✨ New User Registration")
681
+ age_input = gr.Textbox(label="Age", placeholder="e.g., 28")
682
+ gender_input = gr.Dropdown(label="Gender", choices=["Male", "Female", "Other"])
683
+ occupation_input = gr.Textbox(label="Occupation", placeholder="e.g., Student...")
684
+ residence_input = gr.Textbox(label="Place of Residence", placeholder="e.g., Berlin")
685
+ register_btn = gr.Button("🎯 Complete Registration", variant="primary", elem_classes=["login-btn"])
686
+
687
+ with gr.Column(visible=False) as history_section:
688
+ gr.Markdown("### 📜 Past Sessions")
689
+ session_radio = gr.Radio(
690
+ choices=[],
691
+ label="Select a session to view",
692
+ interactive=True,
693
+ )
694
+ history_viewer = gr.Chatbot(
695
+ label="Viewing past session (read-only)",
696
+ height=350,
697
+ )
698
+ resume_session_btn = gr.Button(
699
+ "▶️ Resume This Session",
700
+ variant="primary",
701
+ elem_classes=["action-btn"],
702
+ )
703
+ with gr.Row():
704
+ rename_input = gr.Textbox(
705
+ placeholder="New name for selected session...",
706
+ show_label=False,
707
+ scale=3,
708
+ )
709
+ rename_btn = gr.Button("✏️ Rename", scale=1)
710
 
711
  # ==========================================
712
  # 2. CHAT PAGE (Main Column)
 
737
  switch_user_btn = gr.Button("👥 Logout", elem_classes=["action-btn"])
738
  system_msg = gr.Textbox(label="🔔 System Messages", interactive=False, max_lines=2)
739
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
740
  # -------------------------------------------------------
741
  # Internal Functions
742
  # -------------------------------------------------------
 
773
  gr.update(value=f"<h2 style='text-align: center; color: #333;'>🧠 EMMA: Session for {name}</h2>"),
774
  gr.update(value=welcome_msg),
775
  new_state,
776
+ gr.update(visible=True),
777
  gr.update(choices=_build_session_choices(memory[name]), value=None),
778
  gr.update(value=[]),
779
  )
 
862
  ),
863
  gr.update(value=welcome_msg),
864
  new_state,
865
+ gr.update(visible=True),
866
  gr.update(choices=[], value=None), # brand-new user: no past sessions yet
867
  gr.update(value=[]),
868
  )
 
902
  gr.update(value=""),
903
  gr.update(value=""),
904
  gr.update(value=""),
905
+ gr.update(visible=False),
906
  gr.update(choices=[], value=None),
907
  gr.update(value=[]),
908
  gr.update(value="<h2 style='text-align: center; color: #333;'>🧠 EMMA: Session</h2>"),
 
1060
  gr.update(value=transcript),
1061
  state,
1062
  gr.update(value=new_header),
1063
+ gr.update(),
1064
  gr.update(choices=_build_session_choices(user_data), value=None),
1065
  gr.update(value=[]),
1066
  gr.update(value=f"✅ Resumed session: {resumed_label}.", visible=True),
 
1159
  check_user_btn.click(
1160
  handle_login_check,
1161
  inputs=[username_input, password_input, state],
1162
+ outputs=[login_section, registration_fields, chat_page, login_status, active_header, system_msg, state, history_section, session_radio, history_viewer],
1163
  )
1164
 
1165
  register_btn.click(
1166
  handle_register,
1167
  inputs=[username_input, password_input, age_input, gender_input, occupation_input, residence_input, state],
1168
+ outputs=[login_section, registration_fields, chat_page, login_status, active_header, system_msg, state, history_section, session_radio, history_viewer],
1169
  )
1170
 
1171
  switch_user_btn.click(
1172
  switch_user,
1173
  inputs=[state],
1174
+ outputs=[login_section, registration_fields, chat_page, login_status, username_input, password_input, state, chatbot, age_input, gender_input, occupation_input, residence_input, system_msg, history_section, session_radio, history_viewer, active_header],
1175
  )
1176
 
1177
  submit_btn.click(
 
1207
  resume_session_btn.click(
1208
  handle_resume_session,
1209
  inputs=[session_radio, state],
1210
+ outputs=[chatbot, state, active_header, history_section, session_radio, history_viewer, system_msg],
1211
  )
1212
 
1213
  rename_btn.click(