Spaces:
Sleeping
Sleeping
Akis Giannoukos
commited on
Commit
·
4d0050b
1
Parent(s):
3ef822b
Added clean main tab with voice-first interaction
Browse files
app.py
CHANGED
|
@@ -465,6 +465,7 @@ def process_turn(
|
|
| 465 |
None,
|
| 466 |
None,
|
| 467 |
None,
|
|
|
|
| 468 |
)
|
| 469 |
|
| 470 |
patient_text = (text_input or "").strip()
|
|
@@ -489,6 +490,7 @@ def process_turn(
|
|
| 489 |
None,
|
| 490 |
None,
|
| 491 |
None,
|
|
|
|
| 492 |
)
|
| 493 |
|
| 494 |
# Add patient's message
|
|
@@ -561,6 +563,7 @@ def process_turn(
|
|
| 561 |
None,
|
| 562 |
None,
|
| 563 |
tts_path,
|
|
|
|
| 564 |
)
|
| 565 |
|
| 566 |
|
|
@@ -586,15 +589,16 @@ def create_demo():
|
|
| 586 |
)
|
| 587 |
|
| 588 |
with gr.Tabs():
|
| 589 |
-
with gr.TabItem("
|
| 590 |
with gr.Column():
|
| 591 |
-
chatbot = gr.Chatbot(height=
|
| 592 |
with gr.Row():
|
| 593 |
-
|
| 594 |
-
|
| 595 |
with gr.Row():
|
| 596 |
-
|
| 597 |
-
|
|
|
|
| 598 |
with gr.TabItem("Advanced"):
|
| 599 |
with gr.Column():
|
| 600 |
score_json = gr.JSON(label="PHQ-9 Assessment (live)")
|
|
@@ -619,15 +623,22 @@ def create_demo():
|
|
| 619 |
demo.load(_on_load_init, inputs=None, outputs=[chatbot, scores_state, meta_state, finished_state, turns_state])
|
| 620 |
|
| 621 |
# Wire interactions
|
| 622 |
-
|
| 623 |
fn=process_turn,
|
| 624 |
-
inputs=[
|
| 625 |
-
outputs=[chatbot, score_json, severity_label, finished_state, turns_state,
|
| 626 |
queue=True,
|
| 627 |
api_name="message",
|
| 628 |
)
|
| 629 |
|
| 630 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 631 |
|
| 632 |
# Model switch handlers
|
| 633 |
def _on_apply_model(mid: str):
|
|
|
|
| 465 |
None,
|
| 466 |
None,
|
| 467 |
None,
|
| 468 |
+
None,
|
| 469 |
)
|
| 470 |
|
| 471 |
patient_text = (text_input or "").strip()
|
|
|
|
| 490 |
None,
|
| 491 |
None,
|
| 492 |
None,
|
| 493 |
+
None,
|
| 494 |
)
|
| 495 |
|
| 496 |
# Add patient's message
|
|
|
|
| 563 |
None,
|
| 564 |
None,
|
| 565 |
tts_path,
|
| 566 |
+
tts_path,
|
| 567 |
)
|
| 568 |
|
| 569 |
|
|
|
|
| 589 |
)
|
| 590 |
|
| 591 |
with gr.Tabs():
|
| 592 |
+
with gr.TabItem("Main"):
|
| 593 |
with gr.Column():
|
| 594 |
+
chatbot = gr.Chatbot(height=480, type="tuples", label="Conversation")
|
| 595 |
with gr.Row():
|
| 596 |
+
audio_main = gr.Audio(sources=["microphone"], type="filepath", label="Speak")
|
| 597 |
+
text_main = gr.Textbox(lines=1, placeholder="Type a message and press Enter")
|
| 598 |
with gr.Row():
|
| 599 |
+
reset_btn_main = gr.Button("Reset")
|
| 600 |
+
tts_audio_main = gr.Audio(label="Clinician voice", interactive=False, autoplay=True, show_label=False)
|
| 601 |
+
|
| 602 |
with gr.TabItem("Advanced"):
|
| 603 |
with gr.Column():
|
| 604 |
score_json = gr.JSON(label="PHQ-9 Assessment (live)")
|
|
|
|
| 623 |
demo.load(_on_load_init, inputs=None, outputs=[chatbot, scores_state, meta_state, finished_state, turns_state])
|
| 624 |
|
| 625 |
# Wire interactions
|
| 626 |
+
audio_main.change(
|
| 627 |
fn=process_turn,
|
| 628 |
+
inputs=[audio_main, text_main, chatbot, threshold, tts_enable, finished_state, turns_state, scores_state, meta_state],
|
| 629 |
+
outputs=[chatbot, score_json, severity_label, finished_state, turns_state, audio_main, text_main, tts_audio, tts_audio_main],
|
| 630 |
queue=True,
|
| 631 |
api_name="message",
|
| 632 |
)
|
| 633 |
|
| 634 |
+
text_main.submit(
|
| 635 |
+
fn=process_turn,
|
| 636 |
+
inputs=[audio_main, text_main, chatbot, threshold, tts_enable, finished_state, turns_state, scores_state, meta_state],
|
| 637 |
+
outputs=[chatbot, score_json, severity_label, finished_state, turns_state, audio_main, text_main, tts_audio, tts_audio_main],
|
| 638 |
+
queue=True,
|
| 639 |
+
)
|
| 640 |
+
|
| 641 |
+
reset_btn_main.click(fn=reset_app, inputs=None, outputs=[chatbot, scores_state, meta_state, finished_state, turns_state])
|
| 642 |
|
| 643 |
# Model switch handlers
|
| 644 |
def _on_apply_model(mid: str):
|