Spaces:
Paused
Paused
Commit ·
2c610fe
1
Parent(s): 94fb797
fix: Ask voice question - null handling, answer visibility
Browse files- Handle None/empty question_txt from Gradio (was calling .strip() on None)
- Make answer_display visible when returning results
- Use gr.HTML(value=..., visible=True) for proper output updates
Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
app.py
CHANGED
|
@@ -942,17 +942,20 @@ with gr.Blocks(title="MomsVoice", css=css_code) as demo:
|
|
| 942 |
|
| 943 |
# 9. Submit question
|
| 944 |
def handle_question_submit(question_txt, question_audio_path, paragraphs, slider_val, profile_id):
|
| 945 |
-
|
|
|
|
|
|
|
|
|
|
| 946 |
answer_html = """
|
| 947 |
<div style="padding: 10px; background: #fef2f2; border: 1px solid #fecaca; border-radius: 10px; font-size: 12px; color: #991b1b;">
|
| 948 |
Please type a question or record one with the microphone.
|
| 949 |
</div>
|
| 950 |
"""
|
| 951 |
-
return answer_html, gr.Audio(visible=False)
|
| 952 |
|
| 953 |
# Step 9: Transcribe audio if text is empty (on-demand ASR)
|
| 954 |
-
if
|
| 955 |
-
q_text =
|
| 956 |
else:
|
| 957 |
try:
|
| 958 |
q_text = transcribe_audio(question_audio_path)
|
|
@@ -1009,8 +1012,8 @@ with gr.Blocks(title="MomsVoice", css=css_code) as demo:
|
|
| 1009 |
</div>
|
| 1010 |
"""
|
| 1011 |
if answer_audio_path:
|
| 1012 |
-
return answer_html, gr.Audio(value=answer_audio_path, visible=True)
|
| 1013 |
-
return answer_html, gr.Audio(visible=False)
|
| 1014 |
|
| 1015 |
submit_question_btn.click(
|
| 1016 |
handle_question_submit,
|
|
|
|
| 942 |
|
| 943 |
# 9. Submit question
|
| 944 |
def handle_question_submit(question_txt, question_audio_path, paragraphs, slider_val, profile_id):
|
| 945 |
+
q_txt = (question_txt or "").strip()
|
| 946 |
+
has_audio = question_audio_path is not None and question_audio_path != ""
|
| 947 |
+
|
| 948 |
+
if not q_txt and not has_audio:
|
| 949 |
answer_html = """
|
| 950 |
<div style="padding: 10px; background: #fef2f2; border: 1px solid #fecaca; border-radius: 10px; font-size: 12px; color: #991b1b;">
|
| 951 |
Please type a question or record one with the microphone.
|
| 952 |
</div>
|
| 953 |
"""
|
| 954 |
+
return gr.HTML(value=answer_html, visible=True), gr.Audio(visible=False)
|
| 955 |
|
| 956 |
# Step 9: Transcribe audio if text is empty (on-demand ASR)
|
| 957 |
+
if q_txt:
|
| 958 |
+
q_text = q_txt
|
| 959 |
else:
|
| 960 |
try:
|
| 961 |
q_text = transcribe_audio(question_audio_path)
|
|
|
|
| 1012 |
</div>
|
| 1013 |
"""
|
| 1014 |
if answer_audio_path:
|
| 1015 |
+
return gr.HTML(value=answer_html, visible=True), gr.Audio(value=answer_audio_path, visible=True)
|
| 1016 |
+
return gr.HTML(value=answer_html, visible=True), gr.Audio(visible=False)
|
| 1017 |
|
| 1018 |
submit_question_btn.click(
|
| 1019 |
handle_question_submit,
|