Spaces:
Sleeping
Sleeping
Akis Giannoukos
commited on
Commit
·
e8b82b0
1
Parent(s):
aec1268
Add patient and clinician summaries to display after assessment completion.
Browse files
app.py
CHANGED
|
@@ -293,6 +293,37 @@ def transcript_to_text(chat_history: List[Tuple[str, str]]) -> str:
|
|
| 293 |
return "\n".join(lines)
|
| 294 |
|
| 295 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 296 |
def generate_recording_agent_reply(chat_history: List[Tuple[str, str]]) -> str:
|
| 297 |
transcript = transcript_to_text(chat_history)
|
| 298 |
system_prompt = (
|
|
@@ -688,6 +719,8 @@ def create_demo():
|
|
| 688 |
text_main = gr.Textbox(value="", visible=False)
|
| 689 |
# Autoplay clinician voice output (player hidden with CSS)
|
| 690 |
tts_audio_main = gr.Audio(label=None, interactive=False, autoplay=True, show_label=False, elem_id="tts-player")
|
|
|
|
|
|
|
| 691 |
|
| 692 |
with gr.TabItem("Advanced"):
|
| 693 |
with gr.Column():
|
|
@@ -728,12 +761,18 @@ def create_demo():
|
|
| 728 |
new_path = synthesize_tts(chat_history[-1][1], provider=provider, coqui_model_name=coqui_model, coqui_speaker=coqui_speaker)
|
| 729 |
else:
|
| 730 |
new_path = None
|
| 731 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 732 |
|
| 733 |
audio_main.stop_recording(
|
| 734 |
fn=_process_with_tts,
|
| 735 |
inputs=[audio_main, text_main, chatbot, threshold, tts_enable, finished_state, turns_state, scores_state, meta_state, tts_provider_dd, coqui_model_tb, coqui_speaker_dd],
|
| 736 |
-
outputs=[chatbot, score_json, severity_label, finished_state, turns_state, audio_main, text_main, tts_audio, tts_audio_main],
|
| 737 |
queue=True,
|
| 738 |
api_name="message",
|
| 739 |
)
|
|
|
|
| 293 |
return "\n".join(lines)
|
| 294 |
|
| 295 |
|
| 296 |
+
def build_patient_summary(chat_history: List[Tuple[str, str]], meta: Dict[str, Any], display_json: Dict[str, Any]) -> str:
|
| 297 |
+
severity = meta.get("Severity") or display_json.get("Severity")
|
| 298 |
+
total = meta.get("Total_Score") or display_json.get("Total_Score")
|
| 299 |
+
transcript_text = transcript_to_text(chat_history)
|
| 300 |
+
return (
|
| 301 |
+
f"### Summary for You\n\n"
|
| 302 |
+
f"Thank you for your time. Here is a copy of our conversation so you can review it later.\n\n"
|
| 303 |
+
f"```") + transcript_text + "\n```"
|
| 304 |
+
)
|
| 305 |
+
|
| 306 |
+
|
| 307 |
+
def build_clinician_summary(chat_history: List[Tuple[str, str]], meta: Dict[str, Any], display_json: Dict[str, Any]) -> str:
|
| 308 |
+
scores = display_json.get("PHQ9_Scores", {})
|
| 309 |
+
confidences = display_json.get("Confidences", [])
|
| 310 |
+
severity = meta.get("Severity") or display_json.get("Severity")
|
| 311 |
+
total = meta.get("Total_Score") or display_json.get("Total_Score")
|
| 312 |
+
risk = display_json.get("High_Risk")
|
| 313 |
+
transcript_text = transcript_to_text(chat_history)
|
| 314 |
+
scores_lines = "\n".join([f"- {k}: {v}" for k, v in scores.items()])
|
| 315 |
+
conf_str = ", ".join([f"{c:.2f}" for c in confidences]) if confidences else ""
|
| 316 |
+
return (
|
| 317 |
+
f"### Clinician Summary\n\n"
|
| 318 |
+
f"- Severity: **{severity}** \n"
|
| 319 |
+
f"- PHQ‑9 Total: **{total}** \n"
|
| 320 |
+
f"- High Risk: **{risk}**\n\n"
|
| 321 |
+
f"#### Item Scores\n{scores_lines}\n\n"
|
| 322 |
+
f"#### Item Confidences\n{conf_str}\n\n"
|
| 323 |
+
f"#### Conversation Transcript\n\n"
|
| 324 |
+
f"```") + transcript_text + "\n```"
|
| 325 |
+
)
|
| 326 |
+
|
| 327 |
def generate_recording_agent_reply(chat_history: List[Tuple[str, str]]) -> str:
|
| 328 |
transcript = transcript_to_text(chat_history)
|
| 329 |
system_prompt = (
|
|
|
|
| 719 |
text_main = gr.Textbox(value="", visible=False)
|
| 720 |
# Autoplay clinician voice output (player hidden with CSS)
|
| 721 |
tts_audio_main = gr.Audio(label=None, interactive=False, autoplay=True, show_label=False, elem_id="tts-player")
|
| 722 |
+
# Final summaries (shown after assessment ends)
|
| 723 |
+
main_summary = gr.Markdown(visible=False)
|
| 724 |
|
| 725 |
with gr.TabItem("Advanced"):
|
| 726 |
with gr.Column():
|
|
|
|
| 761 |
new_path = synthesize_tts(chat_history[-1][1], provider=provider, coqui_model_name=coqui_model, coqui_speaker=coqui_speaker)
|
| 762 |
else:
|
| 763 |
new_path = None
|
| 764 |
+
# If finished, hide the mic and display summaries in Main
|
| 765 |
+
if finished_o:
|
| 766 |
+
patient_md = build_patient_summary(chat_history, {"Severity": severity, "Total_Score": display_json.get("Total_Score")}, display_json)
|
| 767 |
+
clinician_md = build_clinician_summary(chat_history, {"Severity": severity, "Total_Score": display_json.get("Total_Score")}, display_json)
|
| 768 |
+
summary_md = patient_md + "\n\n---\n\n" + clinician_md
|
| 769 |
+
return chat_history, display_json, severity, finished_o, turns_o, gr.update(visible=False), None, new_path, new_path, gr.update(value=summary_md, visible=True)
|
| 770 |
+
return chat_history, display_json, severity, finished_o, turns_o, None, None, new_path, new_path, gr.update(visible=False)
|
| 771 |
|
| 772 |
audio_main.stop_recording(
|
| 773 |
fn=_process_with_tts,
|
| 774 |
inputs=[audio_main, text_main, chatbot, threshold, tts_enable, finished_state, turns_state, scores_state, meta_state, tts_provider_dd, coqui_model_tb, coqui_speaker_dd],
|
| 775 |
+
outputs=[chatbot, score_json, severity_label, finished_state, turns_state, audio_main, text_main, tts_audio, tts_audio_main, main_summary],
|
| 776 |
queue=True,
|
| 777 |
api_name="message",
|
| 778 |
)
|