BoxOfColors commited on
Commit
9ef3cf6
·
1 Parent(s): 41d322f

Fix Too many arguments: separate gr.Group visibility from generation outputs

Browse files

In Gradio 5 SSR mode, including gr.Group updates in the same outputs list
as gr.Video/gr.HTML/gr.State causes argument count mismatches. Fix by:
- Removing gr.Group from btn.click() outputs (now: vids+waves+states = 24)
- Adding .then(fn=_update_slot_visibility) after click for group visibility
- Applies to all three tabs: TARO, MMAudio, HunyuanFoley

Files changed (1) hide show
  1. app.py +27 -12
app.py CHANGED
@@ -1363,10 +1363,11 @@ def _unpack_outputs(flat: list, n: int, tab_prefix: str) -> list:
1363
  """Turn a flat _pad_outputs list into Gradio update lists.
1364
 
1365
  flat has MAX_SLOTS * 3 items: [vid0, aud0, meta0, vid1, aud1, meta1, ...]
1366
- Returns updates for: grps + vids + waveforms + seg_states
 
 
1367
  """
1368
  n = int(n)
1369
- grp_updates = [gr.update(visible=(i < n)) for i in range(MAX_SLOTS)]
1370
  vid_updates = []
1371
  wave_updates = []
1372
  state_updates= []
@@ -1386,7 +1387,7 @@ def _unpack_outputs(flat: list, n: int, tab_prefix: str) -> list:
1386
  value="<p style='color:#888;font-size:12px'>Generate audio to see waveform.</p>"
1387
  ))
1388
  state_updates.append(None)
1389
- return grp_updates + vid_updates + wave_updates + state_updates
1390
 
1391
 
1392
  def _on_video_upload_taro(video_file, num_steps, crossfade_s):
@@ -1553,12 +1554,18 @@ with gr.Blocks(title="Generate Audio for Video", css=_SLOT_CSS, js=_GLOBAL_JS) a
1553
  flat[i * 3 + 2] = meta
1554
  return _unpack_outputs(flat, n, "taro")
1555
 
1556
- taro_btn.click(
 
 
1557
  fn=_run_taro,
1558
  inputs=[taro_video, taro_seed, taro_cfg, taro_steps, taro_mode,
1559
  taro_cf_dur, taro_cf_db, taro_samples],
1560
- outputs=taro_slot_grps + taro_slot_vids + taro_slot_waves + taro_slot_states,
1561
- )
 
 
 
 
1562
 
1563
  # Per-slot regen trigger wiring for TARO
1564
  for _i, _rtrig in enumerate(taro_slot_rtrigs):
@@ -1624,12 +1631,16 @@ with gr.Blocks(title="Generate Audio for Video", css=_SLOT_CSS, js=_GLOBAL_JS) a
1624
  flat[i * 3 + 2] = meta
1625
  return _unpack_outputs(flat, n, "mma")
1626
 
1627
- mma_btn.click(
1628
  fn=_run_mmaudio,
1629
  inputs=[mma_video, mma_prompt, mma_neg, mma_seed,
1630
  mma_cfg, mma_steps, mma_cf_dur, mma_cf_db, mma_samples],
1631
- outputs=mma_slot_grps + mma_slot_vids + mma_slot_waves + mma_slot_states,
1632
- )
 
 
 
 
1633
 
1634
  for _i, _rtrig in enumerate(mma_slot_rtrigs):
1635
  _slot_id = f"mma_{_i}"
@@ -1695,12 +1706,16 @@ with gr.Blocks(title="Generate Audio for Video", css=_SLOT_CSS, js=_GLOBAL_JS) a
1695
  flat[i * 3 + 2] = meta
1696
  return _unpack_outputs(flat, n, "hf")
1697
 
1698
- hf_btn.click(
1699
  fn=_run_hunyuan,
1700
  inputs=[hf_video, hf_prompt, hf_neg, hf_seed,
1701
  hf_guidance, hf_steps, hf_size, hf_cf_dur, hf_cf_db, hf_samples],
1702
- outputs=hf_slot_grps + hf_slot_vids + hf_slot_waves + hf_slot_states,
1703
- )
 
 
 
 
1704
 
1705
  for _i, _rtrig in enumerate(hf_slot_rtrigs):
1706
  _slot_id = f"hf_{_i}"
 
1363
  """Turn a flat _pad_outputs list into Gradio update lists.
1364
 
1365
  flat has MAX_SLOTS * 3 items: [vid0, aud0, meta0, vid1, aud1, meta1, ...]
1366
+ Returns updates for vids + waveforms + seg_states only (NOT grps).
1367
+ Group visibility is handled separately via .then() to avoid Gradio 5 SSR
1368
+ 'Too many arguments' caused by mixing gr.Group updates with other outputs.
1369
  """
1370
  n = int(n)
 
1371
  vid_updates = []
1372
  wave_updates = []
1373
  state_updates= []
 
1387
  value="<p style='color:#888;font-size:12px'>Generate audio to see waveform.</p>"
1388
  ))
1389
  state_updates.append(None)
1390
+ return vid_updates + wave_updates + state_updates
1391
 
1392
 
1393
  def _on_video_upload_taro(video_file, num_steps, crossfade_s):
 
1554
  flat[i * 3 + 2] = meta
1555
  return _unpack_outputs(flat, n, "taro")
1556
 
1557
+ # Split group visibility into a separate .then() to avoid Gradio 5 SSR
1558
+ # "Too many arguments" caused by including gr.Group in mixed output lists.
1559
+ (taro_btn.click(
1560
  fn=_run_taro,
1561
  inputs=[taro_video, taro_seed, taro_cfg, taro_steps, taro_mode,
1562
  taro_cf_dur, taro_cf_db, taro_samples],
1563
+ outputs=taro_slot_vids + taro_slot_waves + taro_slot_states,
1564
+ ).then(
1565
+ fn=_update_slot_visibility,
1566
+ inputs=[taro_samples],
1567
+ outputs=taro_slot_grps,
1568
+ ))
1569
 
1570
  # Per-slot regen trigger wiring for TARO
1571
  for _i, _rtrig in enumerate(taro_slot_rtrigs):
 
1631
  flat[i * 3 + 2] = meta
1632
  return _unpack_outputs(flat, n, "mma")
1633
 
1634
+ (mma_btn.click(
1635
  fn=_run_mmaudio,
1636
  inputs=[mma_video, mma_prompt, mma_neg, mma_seed,
1637
  mma_cfg, mma_steps, mma_cf_dur, mma_cf_db, mma_samples],
1638
+ outputs=mma_slot_vids + mma_slot_waves + mma_slot_states,
1639
+ ).then(
1640
+ fn=_update_slot_visibility,
1641
+ inputs=[mma_samples],
1642
+ outputs=mma_slot_grps,
1643
+ ))
1644
 
1645
  for _i, _rtrig in enumerate(mma_slot_rtrigs):
1646
  _slot_id = f"mma_{_i}"
 
1706
  flat[i * 3 + 2] = meta
1707
  return _unpack_outputs(flat, n, "hf")
1708
 
1709
+ (hf_btn.click(
1710
  fn=_run_hunyuan,
1711
  inputs=[hf_video, hf_prompt, hf_neg, hf_seed,
1712
  hf_guidance, hf_steps, hf_size, hf_cf_dur, hf_cf_db, hf_samples],
1713
+ outputs=hf_slot_vids + hf_slot_waves + hf_slot_states,
1714
+ ).then(
1715
+ fn=_update_slot_visibility,
1716
+ inputs=[hf_samples],
1717
+ outputs=hf_slot_grps,
1718
+ ))
1719
 
1720
  for _i, _rtrig in enumerate(hf_slot_rtrigs):
1721
  _slot_id = f"hf_{_i}"