Spaces:
Running on Zero
Running on Zero
perf: eliminate mode-switch lag — clear all audio on toggle
Browse files- src/ui/event_wiring.py +33 -13
src/ui/event_wiring.py
CHANGED
|
@@ -95,17 +95,30 @@ def _wire_input_mode_toggle(c):
|
|
| 95 |
gr.update(visible=is_link), # link_panel
|
| 96 |
gr.update(visible=is_upload), # upload_panel
|
| 97 |
gr.update(visible=is_record), # record_panel
|
| 98 |
-
# Clear
|
| 99 |
gr.update(value=""), # url_input
|
| 100 |
gr.update(value="Download", variant="secondary",
|
| 101 |
interactive=False), # url_download_btn
|
| 102 |
gr.update(visible=False), # url_audio_player
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 103 |
)
|
| 104 |
|
| 105 |
_toggle_outputs = [
|
| 106 |
c.mode_link, c.mode_upload, c.mode_record,
|
| 107 |
c.link_panel, c.upload_panel, c.record_panel,
|
| 108 |
c.url_input, c.url_download_btn, c.url_audio_player,
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 109 |
]
|
| 110 |
c.mode_link.click(fn=lambda: _switch_to("Link"), inputs=[], outputs=_toggle_outputs, api_name=False)
|
| 111 |
c.mode_upload.click(fn=lambda: _switch_to("Upload"), inputs=[], outputs=_toggle_outputs, api_name=False)
|
|
@@ -179,6 +192,7 @@ def _wire_audio_input(c):
|
|
| 179 |
return (audio_path, *_on_audio_change(audio_path))
|
| 180 |
|
| 181 |
# Upload/record → set audio_input State + reset UI (single round-trip)
|
|
|
|
| 182 |
_reset_outputs = [
|
| 183 |
c.output_html, c.output_json, c.export_file,
|
| 184 |
c.cached_speech_intervals, c.cached_is_complete, c.cached_audio, c.cached_sample_rate,
|
|
@@ -188,20 +202,26 @@ def _wire_audio_input(c):
|
|
| 188 |
c.model_accordion, c.seg_accordion,
|
| 189 |
]
|
| 190 |
_ready_outputs = [c.audio_input] + _reset_outputs
|
| 191 |
-
c.audio_upload.change(fn=_on_audio_ready, inputs=[c.audio_upload], outputs=_ready_outputs, api_name=False, show_progress="hidden")
|
| 192 |
-
c.audio_record.change(fn=_on_audio_ready, inputs=[c.audio_record], outputs=_ready_outputs, api_name=False, show_progress="hidden")
|
| 193 |
|
| 194 |
-
|
| 195 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 196 |
_ex_outputs = [c.audio_upload, c.device_radio, c.is_preset]
|
| 197 |
-
c.btn_ex_112.click(fn=lambda: ("data/112.mp3", "GPU", True), inputs=[], outputs=_ex_outputs, api_name=False)
|
| 198 |
-
|
| 199 |
-
c.
|
| 200 |
-
|
| 201 |
-
|
| 202 |
-
|
| 203 |
-
c.
|
| 204 |
-
|
| 205 |
|
| 206 |
|
| 207 |
def _wire_extract_chain(c):
|
|
|
|
| 95 |
gr.update(visible=is_link), # link_panel
|
| 96 |
gr.update(visible=is_upload), # upload_panel
|
| 97 |
gr.update(visible=is_record), # record_panel
|
| 98 |
+
# Clear all input panels so switching starts fresh
|
| 99 |
gr.update(value=""), # url_input
|
| 100 |
gr.update(value="Download", variant="secondary",
|
| 101 |
interactive=False), # url_download_btn
|
| 102 |
gr.update(visible=False), # url_audio_player
|
| 103 |
+
None, # audio_upload
|
| 104 |
+
None, # audio_record
|
| 105 |
+
None, # audio_input (State)
|
| 106 |
+
# Clear pipeline UI
|
| 107 |
+
*_on_audio_change(None),
|
| 108 |
)
|
| 109 |
|
| 110 |
_toggle_outputs = [
|
| 111 |
c.mode_link, c.mode_upload, c.mode_record,
|
| 112 |
c.link_panel, c.upload_panel, c.record_panel,
|
| 113 |
c.url_input, c.url_download_btn, c.url_audio_player,
|
| 114 |
+
c.audio_upload, c.audio_record, c.audio_input,
|
| 115 |
+
# _on_audio_change returns 21 values:
|
| 116 |
+
c.output_html, c.output_json, c.export_file,
|
| 117 |
+
c.cached_speech_intervals, c.cached_is_complete, c.cached_audio, c.cached_sample_rate,
|
| 118 |
+
c.cached_intervals, c.cached_model_name, c.cached_segment_dir, c.cached_log_row,
|
| 119 |
+
c.extract_btn, c.pipeline_progress, c.compute_ts_btn, c.compute_ts_progress, c.animate_all_html,
|
| 120 |
+
c.resegment_toggle_btn, c.retranscribe_btn, c.resegment_panel,
|
| 121 |
+
c.model_accordion, c.seg_accordion,
|
| 122 |
]
|
| 123 |
c.mode_link.click(fn=lambda: _switch_to("Link"), inputs=[], outputs=_toggle_outputs, api_name=False)
|
| 124 |
c.mode_upload.click(fn=lambda: _switch_to("Upload"), inputs=[], outputs=_toggle_outputs, api_name=False)
|
|
|
|
| 192 |
return (audio_path, *_on_audio_change(audio_path))
|
| 193 |
|
| 194 |
# Upload/record → set audio_input State + reset UI (single round-trip)
|
| 195 |
+
# Uses .input() (not .change()) so programmatic clears from mode-switch don't cascade.
|
| 196 |
_reset_outputs = [
|
| 197 |
c.output_html, c.output_json, c.export_file,
|
| 198 |
c.cached_speech_intervals, c.cached_is_complete, c.cached_audio, c.cached_sample_rate,
|
|
|
|
| 202 |
c.model_accordion, c.seg_accordion,
|
| 203 |
]
|
| 204 |
_ready_outputs = [c.audio_input] + _reset_outputs
|
|
|
|
|
|
|
| 205 |
|
| 206 |
+
def _on_audio_ready_reset_preset(audio_path):
|
| 207 |
+
"""Bridge audio to State + reset UI + clear is_preset in one round-trip."""
|
| 208 |
+
return (*_on_audio_ready(audio_path), False)
|
| 209 |
+
|
| 210 |
+
_ready_preset_outputs = _ready_outputs + [c.is_preset]
|
| 211 |
+
c.audio_upload.input(fn=_on_audio_ready_reset_preset, inputs=[c.audio_upload], outputs=_ready_preset_outputs, api_name=False, show_progress="hidden")
|
| 212 |
+
c.audio_record.input(fn=_on_audio_ready_reset_preset, inputs=[c.audio_record], outputs=_ready_preset_outputs, api_name=False, show_progress="hidden")
|
| 213 |
+
|
| 214 |
+
# Example buttons: set audio_upload (for waveform) + device + preset flag,
|
| 215 |
+
# then chain _on_audio_ready since .input() won't fire for programmatic sets.
|
| 216 |
_ex_outputs = [c.audio_upload, c.device_radio, c.is_preset]
|
| 217 |
+
c.btn_ex_112.click(fn=lambda: ("data/112.mp3", "GPU", True), inputs=[], outputs=_ex_outputs, api_name=False).then(
|
| 218 |
+
fn=_on_audio_ready, inputs=[c.audio_upload], outputs=_ready_outputs, api_name=False, show_progress="hidden")
|
| 219 |
+
c.btn_ex_84.click(fn=lambda: ("data/84.mp3", "GPU", True), inputs=[], outputs=_ex_outputs, api_name=False).then(
|
| 220 |
+
fn=_on_audio_ready, inputs=[c.audio_upload], outputs=_ready_outputs, api_name=False, show_progress="hidden")
|
| 221 |
+
c.btn_ex_7.click(fn=lambda: ("data/7.mp3", "GPU", True), inputs=[], outputs=_ex_outputs, api_name=False).then(
|
| 222 |
+
fn=_on_audio_ready, inputs=[c.audio_upload], outputs=_ready_outputs, api_name=False, show_progress="hidden")
|
| 223 |
+
c.btn_ex_juz30.click(fn=lambda: ("data/Juz' 30.mp3", "GPU", True), inputs=[], outputs=_ex_outputs, api_name=False).then(
|
| 224 |
+
fn=_on_audio_ready, inputs=[c.audio_upload], outputs=_ready_outputs, api_name=False, show_progress="hidden")
|
| 225 |
|
| 226 |
|
| 227 |
def _wire_extract_chain(c):
|