Commit ·
7cacbd0
1
Parent(s): 3847eb5
Disable Generate button and show busy label during generation
Browse filesPrevents double-clicking Generate from firing overlapping requests on
the same slot, and gives clearer feedback that a job is in flight.
Wired via .then() (not .success()) on all three tabs so the button
re-enables even if the generate call raises.
app.py
CHANGED
|
@@ -2537,6 +2537,20 @@ def _update_slot_visibility(n):
|
|
| 2537 |
return [gr.update(visible=(i < n)) for i in range(MAX_SLOTS)]
|
| 2538 |
|
| 2539 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 2540 |
# ================================================================== #
|
| 2541 |
# GRADIO UI #
|
| 2542 |
# ================================================================== #
|
|
@@ -3042,6 +3056,10 @@ with gr.Blocks(title="Generate Audio for Video", css=_SLOT_CSS, js=_GLOBAL_JS) a
|
|
| 3042 |
# Split group visibility into a separate .then() to avoid Gradio 5 SSR
|
| 3043 |
# "Too many arguments" caused by including gr.Group in mixed output lists.
|
| 3044 |
(taro_btn.click(
|
|
|
|
|
|
|
|
|
|
|
|
|
| 3045 |
fn=_run_taro,
|
| 3046 |
inputs=[taro_video, taro_seed, taro_cfg, taro_steps, taro_mode,
|
| 3047 |
taro_cf_dur, taro_cf_db, taro_samples],
|
|
@@ -3050,6 +3068,10 @@ with gr.Blocks(title="Generate Audio for Video", css=_SLOT_CSS, js=_GLOBAL_JS) a
|
|
| 3050 |
fn=_update_slot_visibility,
|
| 3051 |
inputs=[taro_samples],
|
| 3052 |
outputs=taro_slot_grps,
|
|
|
|
|
|
|
|
|
|
|
|
|
| 3053 |
))
|
| 3054 |
|
| 3055 |
# Per-slot regen handlers — JS calls /gradio_api/queue/join with
|
|
@@ -3098,6 +3120,10 @@ with gr.Blocks(title="Generate Audio for Video", css=_SLOT_CSS, js=_GLOBAL_JS) a
|
|
| 3098 |
return _unpack_outputs(flat, n, "mma")
|
| 3099 |
|
| 3100 |
(mma_btn.click(
|
|
|
|
|
|
|
|
|
|
|
|
|
| 3101 |
fn=_run_mmaudio,
|
| 3102 |
inputs=[mma_video, mma_prompt, mma_neg, mma_seed,
|
| 3103 |
mma_cfg, mma_steps, mma_cf_dur, mma_cf_db, mma_samples],
|
|
@@ -3106,6 +3132,10 @@ with gr.Blocks(title="Generate Audio for Video", css=_SLOT_CSS, js=_GLOBAL_JS) a
|
|
| 3106 |
fn=_update_slot_visibility,
|
| 3107 |
inputs=[mma_samples],
|
| 3108 |
outputs=mma_slot_grps,
|
|
|
|
|
|
|
|
|
|
|
|
|
| 3109 |
))
|
| 3110 |
|
| 3111 |
mma_regen_btns = _register_regen_handlers(
|
|
@@ -3153,6 +3183,10 @@ with gr.Blocks(title="Generate Audio for Video", css=_SLOT_CSS, js=_GLOBAL_JS) a
|
|
| 3153 |
return _unpack_outputs(flat, n, "hf")
|
| 3154 |
|
| 3155 |
(hf_btn.click(
|
|
|
|
|
|
|
|
|
|
|
|
|
| 3156 |
fn=_run_hunyuan,
|
| 3157 |
inputs=[hf_video, hf_prompt, hf_neg, hf_seed,
|
| 3158 |
hf_guidance, hf_steps, hf_size, hf_cf_dur, hf_cf_db, hf_samples],
|
|
@@ -3161,6 +3195,10 @@ with gr.Blocks(title="Generate Audio for Video", css=_SLOT_CSS, js=_GLOBAL_JS) a
|
|
| 3161 |
fn=_update_slot_visibility,
|
| 3162 |
inputs=[hf_samples],
|
| 3163 |
outputs=hf_slot_grps,
|
|
|
|
|
|
|
|
|
|
|
|
|
| 3164 |
))
|
| 3165 |
|
| 3166 |
hf_regen_btns = _register_regen_handlers(
|
|
|
|
| 2537 |
return [gr.update(visible=(i < n)) for i in range(MAX_SLOTS)]
|
| 2538 |
|
| 2539 |
|
| 2540 |
+
def _btn_generating():
|
| 2541 |
+
"""Disable a Generate button and show a busy label. Chained as the first
|
| 2542 |
+
.click() step so it fires immediately, before the (possibly slow) generate
|
| 2543 |
+
call starts."""
|
| 2544 |
+
return gr.update(value="Generating…", interactive=False)
|
| 2545 |
+
|
| 2546 |
+
|
| 2547 |
+
def _btn_ready():
|
| 2548 |
+
"""Re-enable a Generate button. Chained via .then() (not .success()) so it
|
| 2549 |
+
always runs — even if an earlier step in the chain raised — otherwise a
|
| 2550 |
+
crashed generation would leave the button stuck disabled."""
|
| 2551 |
+
return gr.update(value="Generate", interactive=True)
|
| 2552 |
+
|
| 2553 |
+
|
| 2554 |
# ================================================================== #
|
| 2555 |
# GRADIO UI #
|
| 2556 |
# ================================================================== #
|
|
|
|
| 3056 |
# Split group visibility into a separate .then() to avoid Gradio 5 SSR
|
| 3057 |
# "Too many arguments" caused by including gr.Group in mixed output lists.
|
| 3058 |
(taro_btn.click(
|
| 3059 |
+
fn=_btn_generating,
|
| 3060 |
+
inputs=None,
|
| 3061 |
+
outputs=[taro_btn],
|
| 3062 |
+
).then(
|
| 3063 |
fn=_run_taro,
|
| 3064 |
inputs=[taro_video, taro_seed, taro_cfg, taro_steps, taro_mode,
|
| 3065 |
taro_cf_dur, taro_cf_db, taro_samples],
|
|
|
|
| 3068 |
fn=_update_slot_visibility,
|
| 3069 |
inputs=[taro_samples],
|
| 3070 |
outputs=taro_slot_grps,
|
| 3071 |
+
).then(
|
| 3072 |
+
fn=_btn_ready,
|
| 3073 |
+
inputs=None,
|
| 3074 |
+
outputs=[taro_btn],
|
| 3075 |
))
|
| 3076 |
|
| 3077 |
# Per-slot regen handlers — JS calls /gradio_api/queue/join with
|
|
|
|
| 3120 |
return _unpack_outputs(flat, n, "mma")
|
| 3121 |
|
| 3122 |
(mma_btn.click(
|
| 3123 |
+
fn=_btn_generating,
|
| 3124 |
+
inputs=None,
|
| 3125 |
+
outputs=[mma_btn],
|
| 3126 |
+
).then(
|
| 3127 |
fn=_run_mmaudio,
|
| 3128 |
inputs=[mma_video, mma_prompt, mma_neg, mma_seed,
|
| 3129 |
mma_cfg, mma_steps, mma_cf_dur, mma_cf_db, mma_samples],
|
|
|
|
| 3132 |
fn=_update_slot_visibility,
|
| 3133 |
inputs=[mma_samples],
|
| 3134 |
outputs=mma_slot_grps,
|
| 3135 |
+
).then(
|
| 3136 |
+
fn=_btn_ready,
|
| 3137 |
+
inputs=None,
|
| 3138 |
+
outputs=[mma_btn],
|
| 3139 |
))
|
| 3140 |
|
| 3141 |
mma_regen_btns = _register_regen_handlers(
|
|
|
|
| 3183 |
return _unpack_outputs(flat, n, "hf")
|
| 3184 |
|
| 3185 |
(hf_btn.click(
|
| 3186 |
+
fn=_btn_generating,
|
| 3187 |
+
inputs=None,
|
| 3188 |
+
outputs=[hf_btn],
|
| 3189 |
+
).then(
|
| 3190 |
fn=_run_hunyuan,
|
| 3191 |
inputs=[hf_video, hf_prompt, hf_neg, hf_seed,
|
| 3192 |
hf_guidance, hf_steps, hf_size, hf_cf_dur, hf_cf_db, hf_samples],
|
|
|
|
| 3195 |
fn=_update_slot_visibility,
|
| 3196 |
inputs=[hf_samples],
|
| 3197 |
outputs=hf_slot_grps,
|
| 3198 |
+
).then(
|
| 3199 |
+
fn=_btn_ready,
|
| 3200 |
+
inputs=None,
|
| 3201 |
+
outputs=[hf_btn],
|
| 3202 |
))
|
| 3203 |
|
| 3204 |
hf_regen_btns = _register_regen_handlers(
|