Spaces:
Paused
Paused
Commit ·
37bfdc1
1
Parent(s): 3b13a44
fix: auto-submit - JS clicks submit 500ms after stop_recording + .change backup
Browse files- stop_recording uses JS-only to click submit button after delay
- .change() handles actual Python logic when audio value commits
- Removed all trigger word references
- question_text is fully hidden (visible=False)
Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
app.py
CHANGED
|
@@ -1098,21 +1098,22 @@ with gr.Blocks(title="MomsVoice", css=css_code) as demo:
|
|
| 1098 |
)
|
| 1099 |
|
| 1100 |
# Auto-submit when voice recording completes
|
| 1101 |
-
# .stop_recording
|
|
|
|
| 1102 |
question_audio.stop_recording(
|
| 1103 |
-
|
| 1104 |
-
inputs=
|
| 1105 |
-
outputs=
|
| 1106 |
js="""() => {
|
| 1107 |
-
//
|
| 1108 |
setTimeout(() => {
|
| 1109 |
-
const btn = document.querySelector('#qa_submit_btn');
|
| 1110 |
if (btn) btn.click();
|
| 1111 |
-
},
|
| 1112 |
}"""
|
| 1113 |
)
|
| 1114 |
|
| 1115 |
-
#
|
| 1116 |
def auto_submit_on_audio(audio_path, question_txt, paragraphs, slider_val, profile_id):
|
| 1117 |
"""Auto-submit when a recording is available."""
|
| 1118 |
if not audio_path:
|
|
|
|
| 1098 |
)
|
| 1099 |
|
| 1100 |
# Auto-submit when voice recording completes
|
| 1101 |
+
# In Gradio 5.35, .stop_recording may not pass audio value reliably.
|
| 1102 |
+
# Use .stop_recording with a small delay via JS to click the submit button.
|
| 1103 |
question_audio.stop_recording(
|
| 1104 |
+
fn=None,
|
| 1105 |
+
inputs=None,
|
| 1106 |
+
outputs=None,
|
| 1107 |
js="""() => {
|
| 1108 |
+
// Wait for audio value to be committed, then click submit
|
| 1109 |
setTimeout(() => {
|
| 1110 |
+
const btn = document.querySelector('#qa_submit_btn button, #qa_submit_btn');
|
| 1111 |
if (btn) btn.click();
|
| 1112 |
+
}, 500);
|
| 1113 |
}"""
|
| 1114 |
)
|
| 1115 |
|
| 1116 |
+
# .change() as primary Python handler — fires after audio value is committed
|
| 1117 |
def auto_submit_on_audio(audio_path, question_txt, paragraphs, slider_val, profile_id):
|
| 1118 |
"""Auto-submit when a recording is available."""
|
| 1119 |
if not audio_path:
|