Spaces:
Paused
Paused
Commit ·
e942657
1
Parent(s): 2b743ed
fix: auto-submit question - use .change() instead of .stop_recording()
Browse files.stop_recording fires before audio value is committed in Gradio 5.35.
.change fires after the value is set, ensuring audio_path is available.
Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
app.py
CHANGED
|
@@ -1099,10 +1099,18 @@ with gr.Blocks(title="MomsVoice", css=css_code) as demo:
|
|
| 1099 |
outputs=[answer_display, answer_audio]
|
| 1100 |
)
|
| 1101 |
|
| 1102 |
-
# Auto-submit when voice recording
|
| 1103 |
-
|
| 1104 |
-
|
| 1105 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1106 |
outputs=[answer_display, answer_audio]
|
| 1107 |
)
|
| 1108 |
|
|
|
|
| 1099 |
outputs=[answer_display, answer_audio]
|
| 1100 |
)
|
| 1101 |
|
| 1102 |
+
# Auto-submit when voice recording completes
|
| 1103 |
+
# .stop_recording may fire before audio value is committed in Gradio 5.35
|
| 1104 |
+
# .change fires after the value is set — use it with a guard to avoid triggering on clear
|
| 1105 |
+
def auto_submit_on_audio_change(audio_path, question_txt, paragraphs, slider_val, profile_id):
|
| 1106 |
+
"""Auto-submit only when a new recording is available (not on clear)."""
|
| 1107 |
+
if not audio_path:
|
| 1108 |
+
return gr.update(), gr.update()
|
| 1109 |
+
return handle_question_submit(question_txt, audio_path, paragraphs, slider_val, profile_id)
|
| 1110 |
+
|
| 1111 |
+
question_audio.change(
|
| 1112 |
+
auto_submit_on_audio_change,
|
| 1113 |
+
inputs=[question_audio, question_text, paragraphs_state, timeline_slider, voice_profile_state],
|
| 1114 |
outputs=[answer_display, answer_audio]
|
| 1115 |
)
|
| 1116 |
|