sshtel commited on
Commit
f30d5ae
Β·
1 Parent(s): 4798cd4

Fix record button

Browse files
Files changed (1) hide show
  1. app.py +5 -38
app.py CHANGED
@@ -1048,23 +1048,6 @@ with gr.Blocks(title="MomsVoice", css=css_code) as demo:
1048
  inputs=[],
1049
  outputs=[player_status_bar, play_btn, pause_btn, ask_btn, resume_btn, qa_panel, qa_input_group, answer_display, answer_audio],
1050
  cancels=[play_event],
1051
- js="""() => {
1052
- // Auto-click Record within user gesture window (100ms).
1053
- // The Ask button click IS the user gesture, so mic permission should be granted.
1054
- setTimeout(() => {
1055
- const el = document.querySelector('#qa_audio_input');
1056
- if (!el) return;
1057
- const btn = el.querySelector('button[aria-label="Record"], button.record-button');
1058
- if (btn) { btn.click(); return; }
1059
- // Fallback: find any button with record icon
1060
- const allBtns = el.querySelectorAll('button');
1061
- for (const b of allBtns) {
1062
- if (b.querySelector('svg') || b.textContent.trim() === '') {
1063
- b.click(); break;
1064
- }
1065
- }
1066
- }, 100);
1067
- }"""
1068
  )
1069
 
1070
  # 9. Submit question β€” LFM2.5-Audio end-to-end (single model: audio-in β†’ audio+text-out)
@@ -1113,34 +1096,18 @@ with gr.Blocks(title="MomsVoice", css=css_code) as demo:
1113
  outputs=[answer_display, answer_audio]
1114
  )
1115
 
1116
- # Auto-submit when voice recording completes. .change() fires after the
1117
- # recorded audio file path is committed. Dedup prevents double-submit if
1118
- # the user also clicks "Get Answer" manually.
1119
- def auto_submit_on_audio(audio_path, question_txt, paragraphs, slider_val, profile_id):
1120
- """Auto-submit when a recording is available."""
1121
  if not audio_path:
1122
  return gr.update(), gr.update()
1123
  if not claim_audio_submission(audio_path):
1124
  return gr.update(), gr.update()
1125
  return handle_question_submit(question_txt, audio_path, paragraphs, slider_val, profile_id)
1126
 
1127
- question_audio.change(
1128
- auto_submit_on_audio,
1129
- inputs=[question_audio, question_text, paragraphs_state, timeline_slider, voice_profile_state],
1130
- outputs=[answer_display, answer_audio]
1131
- )
1132
-
1133
- # Also trigger on stop_recording with JS fallback to click submit button
1134
  question_audio.stop_recording(
1135
- fn=None,
1136
- inputs=None,
1137
- outputs=None,
1138
- js="""() => {
1139
- setTimeout(() => {
1140
- const btn = document.querySelector('#qa_submit_btn button, #qa_submit_btn');
1141
- if (btn) btn.click();
1142
- }, 600);
1143
- }"""
1144
  )
1145
 
1146
  # 10. Resume button β€” dismiss Q&A panel, show Play to continue
 
1048
  inputs=[],
1049
  outputs=[player_status_bar, play_btn, pause_btn, ask_btn, resume_btn, qa_panel, qa_input_group, answer_display, answer_audio],
1050
  cancels=[play_event],
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1051
  )
1052
 
1053
  # 9. Submit question β€” LFM2.5-Audio end-to-end (single model: audio-in β†’ audio+text-out)
 
1096
  outputs=[answer_display, answer_audio]
1097
  )
1098
 
1099
+ # Auto-submit immediately when recording stops β€” directly calls inference
1100
+ def auto_submit_on_stop(audio_path, question_txt, paragraphs, slider_val, profile_id):
 
 
 
1101
  if not audio_path:
1102
  return gr.update(), gr.update()
1103
  if not claim_audio_submission(audio_path):
1104
  return gr.update(), gr.update()
1105
  return handle_question_submit(question_txt, audio_path, paragraphs, slider_val, profile_id)
1106
 
 
 
 
 
 
 
 
1107
  question_audio.stop_recording(
1108
+ auto_submit_on_stop,
1109
+ inputs=[question_audio, question_text, paragraphs_state, timeline_slider, voice_profile_state],
1110
+ outputs=[answer_display, answer_audio],
 
 
 
 
 
 
1111
  )
1112
 
1113
  # 10. Resume button β€” dismiss Q&A panel, show Play to continue