Akis Giannoukos commited on
Commit
91ec38e
·
1 Parent(s): 90061b0

Add advanced text input functionality to demo interface with submission handling for chatbot interactions

Browse files
Files changed (1) hide show
  1. app.py +21 -0
app.py CHANGED
@@ -748,6 +748,9 @@ def create_demo():
748
  with gr.TabItem("Advanced"):
749
  with gr.Column():
750
  chatbot = gr.Chatbot(height=360, type="tuples", label="Conversation")
 
 
 
751
  score_json = gr.JSON(label="PHQ-9 Assessment (live)")
752
  severity_label = gr.Label(label="Severity")
753
  threshold = gr.Slider(0.5, 1.0, value=CONFIDENCE_THRESHOLD_DEFAULT, step=0.05, label="Confidence Threshold (stop when min ≥ τ)")
@@ -800,6 +803,24 @@ def create_demo():
800
  api_name="message",
801
  )
802
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
803
  # Tap bubble to toggle microphone record/stop via JS
804
  # This JS is no longer needed as the bubble is the mic
805
  # voice_bubble.click(
 
748
  with gr.TabItem("Advanced"):
749
  with gr.Column():
750
  chatbot = gr.Chatbot(height=360, type="tuples", label="Conversation")
751
+ with gr.Row():
752
+ text_adv = gr.Textbox(placeholder="Type your message and press Enter", scale=4)
753
+ send_adv_btn = gr.Button("Send", scale=1)
754
  score_json = gr.JSON(label="PHQ-9 Assessment (live)")
755
  severity_label = gr.Label(label="Severity")
756
  threshold = gr.Slider(0.5, 1.0, value=CONFIDENCE_THRESHOLD_DEFAULT, step=0.05, label="Confidence Threshold (stop when min ≥ τ)")
 
803
  api_name="message",
804
  )
805
 
806
+ # Text input flow from Advanced tab
807
+ def _process_text_and_clear(text, chat, th, tts_on, finished, turns, scores, meta, provider, coqui_model, coqui_speaker):
808
+ res = _process_with_tts(None, text, chat, th, tts_on, finished, turns, scores, meta, provider, coqui_model, coqui_speaker)
809
+ return (*res, "")
810
+
811
+ text_adv.submit(
812
+ fn=_process_text_and_clear,
813
+ inputs=[text_adv, chatbot, threshold, tts_enable, finished_state, turns_state, scores_state, meta_state, tts_provider_dd, coqui_model_tb, coqui_speaker_dd],
814
+ outputs=[chatbot, score_json, severity_label, finished_state, turns_state, audio_main, text_main, tts_audio, tts_audio_main, main_summary, text_adv],
815
+ queue=True,
816
+ )
817
+ send_adv_btn.click(
818
+ fn=_process_text_and_clear,
819
+ inputs=[text_adv, chatbot, threshold, tts_enable, finished_state, turns_state, scores_state, meta_state, tts_provider_dd, coqui_model_tb, coqui_speaker_dd],
820
+ outputs=[chatbot, score_json, severity_label, finished_state, turns_state, audio_main, text_main, tts_audio, tts_audio_main, main_summary, text_adv],
821
+ queue=True,
822
+ )
823
+
824
  # Tap bubble to toggle microphone record/stop via JS
825
  # This JS is no longer needed as the bubble is the mic
826
  # voice_bubble.click(