BoxOfColors commited on
Commit
5c4d5d2
Β·
1 Parent(s): 8ced419

Fix regen: embed state in trigger value, remove seg_state from inputs

Browse files
Files changed (1) hide show
  1. app.py +59 -35
app.py CHANGED
@@ -1421,9 +1421,13 @@ def _make_output_slots(tab_prefix: str) -> tuple:
1421
  label="",
1422
  show_label=False,
1423
  ))
1424
- # State textbox: also CSS-hidden for same reason.
 
 
 
1425
  seg_states.append(gr.Textbox(
1426
  value="",
 
1427
  elem_classes=["wf-hidden-input"],
1428
  label="",
1429
  show_label=False,
@@ -1547,9 +1551,21 @@ _GLOBAL_JS = """
1547
 
1548
  function fireRegen(slot_id, idx) {
1549
  const el = document.getElementById('regen_trigger_' + slot_id);
1550
- if (!el) { console.warn('[fireRegen] element not found: regen_trigger_' + slot_id); return; }
1551
  const input = el.querySelector('input, textarea');
1552
- if (!input) { console.warn('[fireRegen] no input inside regen_trigger_' + slot_id); return; }
 
 
 
 
 
 
 
 
 
 
 
 
1553
 
1554
  // Use native setter to bypass React's controlled-input tracking.
1555
  // Clear to '' first so a repeat click on the same segment still fires .change().
@@ -1561,10 +1577,12 @@ _GLOBAL_JS = """
1561
  input.dispatchEvent(new Event('input', {bubbles: true}));
1562
  input.dispatchEvent(new Event('change', {bubbles: true}));
1563
  }
 
 
1564
  setNative('');
1565
  setTimeout(function() {
1566
- setNative(slot_id + '|' + idx);
1567
- console.log('[fireRegen] fired', slot_id + '|' + idx);
1568
  }, 50);
1569
 
1570
  const lbl = document.getElementById('wf_seglabel_' + slot_id);
@@ -1667,17 +1685,19 @@ with gr.Blocks(title="Generate Audio for Video", css=_SLOT_CSS, js=_GLOBAL_JS) a
1667
  for _i, _rtrig in enumerate(taro_slot_rtrigs):
1668
  _slot_id = f"taro_{_i}"
1669
  def _make_taro_regen(_si, _sid):
1670
- def _do(trigger_val, video, seed, cfg, steps, mode, cf_dur, cf_db, state_json):
1671
- print(f"[regen TARO] trigger_val={trigger_val!r} state_json_len={len(state_json) if state_json else 0} video={video!r}")
1672
- if not trigger_val or not state_json:
1673
- print(f"[regen TARO] early-exit: trigger_val empty={not trigger_val} state empty={not state_json}")
1674
  return gr.update(), gr.update(), gr.update(value="")
1675
- parts = trigger_val.split("|")
1676
- if len(parts) != 2 or parts[0] != _sid:
1677
- print(f"[regen TARO] early-exit: parts={parts} expected slot={_sid}")
 
1678
  return gr.update(), gr.update(), gr.update(value="")
1679
- seg_idx = int(parts[1])
1680
- print(f"[regen TARO] slot={_sid} seg_idx={seg_idx} β€” acquiring lock")
 
1681
  lock = _get_slot_lock(_sid)
1682
  with lock:
1683
  print(f"[regen TARO] slot={_sid} seg_idx={seg_idx} β€” lock acquired, showing spinner")
@@ -1702,7 +1722,7 @@ with gr.Blocks(title="Generate Audio for Video", css=_SLOT_CSS, js=_GLOBAL_JS) a
1702
  _rtrig.change(
1703
  fn=_make_taro_regen(_i, _slot_id),
1704
  inputs=[_rtrig, taro_video, taro_seed, taro_cfg, taro_steps,
1705
- taro_mode, taro_cf_dur, taro_cf_db, taro_slot_states[_i]],
1706
  outputs=[taro_slot_vids[_i], taro_slot_waves[_i], taro_slot_states[_i]],
1707
  )
1708
 
@@ -1757,17 +1777,19 @@ with gr.Blocks(title="Generate Audio for Video", css=_SLOT_CSS, js=_GLOBAL_JS) a
1757
  for _i, _rtrig in enumerate(mma_slot_rtrigs):
1758
  _slot_id = f"mma_{_i}"
1759
  def _make_mma_regen(_si, _sid):
1760
- def _do(trigger_val, video, prompt, neg, seed, cfg, steps, cf_dur, cf_db, state_json):
1761
- print(f"[regen MMA] trigger_val={trigger_val!r} state_json_len={len(state_json) if state_json else 0} video={video!r}")
1762
- if not trigger_val or not state_json:
1763
- print(f"[regen MMA] early-exit: trigger_val empty={not trigger_val} state empty={not state_json}")
1764
  return gr.update(), gr.update(), gr.update(value="")
1765
- parts = trigger_val.split("|")
1766
- if len(parts) != 2 or parts[0] != _sid:
1767
- print(f"[regen MMA] early-exit: parts={parts} expected slot={_sid}")
 
1768
  return gr.update(), gr.update(), gr.update(value="")
1769
- seg_idx = int(parts[1])
1770
- print(f"[regen MMA] slot={_sid} seg_idx={seg_idx} β€” acquiring lock")
 
1771
  lock = _get_slot_lock(_sid)
1772
  with lock:
1773
  print(f"[regen MMA] slot={_sid} seg_idx={seg_idx} β€” lock acquired, showing spinner")
@@ -1792,7 +1814,7 @@ with gr.Blocks(title="Generate Audio for Video", css=_SLOT_CSS, js=_GLOBAL_JS) a
1792
  _rtrig.change(
1793
  fn=_make_mma_regen(_i, _slot_id),
1794
  inputs=[_rtrig, mma_video, mma_prompt, mma_neg, mma_seed,
1795
- mma_cfg, mma_steps, mma_cf_dur, mma_cf_db, mma_slot_states[_i]],
1796
  outputs=[mma_slot_vids[_i], mma_slot_waves[_i], mma_slot_states[_i]],
1797
  )
1798
 
@@ -1848,17 +1870,19 @@ with gr.Blocks(title="Generate Audio for Video", css=_SLOT_CSS, js=_GLOBAL_JS) a
1848
  for _i, _rtrig in enumerate(hf_slot_rtrigs):
1849
  _slot_id = f"hf_{_i}"
1850
  def _make_hf_regen(_si, _sid):
1851
- def _do(trigger_val, video, prompt, neg, seed, guidance, steps, size, cf_dur, cf_db, state_json):
1852
- print(f"[regen HF] trigger_val={trigger_val!r} state_json_len={len(state_json) if state_json else 0} video={video!r}")
1853
- if not trigger_val or not state_json:
1854
- print(f"[regen HF] early-exit: trigger_val empty={not trigger_val} state empty={not state_json}")
1855
  return gr.update(), gr.update(), gr.update(value="")
1856
- parts = trigger_val.split("|")
1857
- if len(parts) != 2 or parts[0] != _sid:
1858
- print(f"[regen HF] early-exit: parts={parts} expected slot={_sid}")
 
1859
  return gr.update(), gr.update(), gr.update(value="")
1860
- seg_idx = int(parts[1])
1861
- print(f"[regen HF] slot={_sid} seg_idx={seg_idx} β€” acquiring lock")
 
1862
  lock = _get_slot_lock(_sid)
1863
  with lock:
1864
  print(f"[regen HF] slot={_sid} seg_idx={seg_idx} β€” lock acquired, showing spinner")
@@ -1883,7 +1907,7 @@ with gr.Blocks(title="Generate Audio for Video", css=_SLOT_CSS, js=_GLOBAL_JS) a
1883
  _rtrig.change(
1884
  fn=_make_hf_regen(_i, _slot_id),
1885
  inputs=[_rtrig, hf_video, hf_prompt, hf_neg, hf_seed,
1886
- hf_guidance, hf_steps, hf_size, hf_cf_dur, hf_cf_db, hf_slot_states[_i]],
1887
  outputs=[hf_slot_vids[_i], hf_slot_waves[_i], hf_slot_states[_i]],
1888
  )
1889
 
 
1421
  label="",
1422
  show_label=False,
1423
  ))
1424
+ # State textbox: CSS-hidden, has elem_id so JS can READ current state
1425
+ # and embed it in the trigger value (avoids having this component in
1426
+ # both inputs AND outputs of the same .change() handler, which causes
1427
+ # Gradio 5 SSR "Too many arguments" validation errors).
1428
  seg_states.append(gr.Textbox(
1429
  value="",
1430
+ elem_id=f"seg_state_{slot_id}",
1431
  elem_classes=["wf-hidden-input"],
1432
  label="",
1433
  show_label=False,
 
1551
 
1552
  function fireRegen(slot_id, idx) {
1553
  const el = document.getElementById('regen_trigger_' + slot_id);
1554
+ if (!el) { console.warn('[fireRegen] regen_trigger element not found:', slot_id); return; }
1555
  const input = el.querySelector('input, textarea');
1556
+ if (!input) { console.warn('[fireRegen] no input inside regen_trigger:', slot_id); return; }
1557
+
1558
+ // Read current seg state JSON from the state textbox so we can embed it
1559
+ // in the trigger value. This avoids having seg_state in BOTH inputs AND
1560
+ // outputs of the .change() handler, which causes Gradio 5 SSR to reject
1561
+ // the call with "Too many arguments provided for the endpoint".
1562
+ const stEl = document.getElementById('seg_state_' + slot_id);
1563
+ const stInput = stEl ? stEl.querySelector('input, textarea') : null;
1564
+ const stateJson = stInput ? stInput.value : '';
1565
+ if (!stateJson) {
1566
+ console.warn('[fireRegen] seg_state is empty for slot', slot_id, 'β€” skipping regen');
1567
+ return;
1568
+ }
1569
 
1570
  // Use native setter to bypass React's controlled-input tracking.
1571
  // Clear to '' first so a repeat click on the same segment still fires .change().
 
1577
  input.dispatchEvent(new Event('input', {bubbles: true}));
1578
  input.dispatchEvent(new Event('change', {bubbles: true}));
1579
  }
1580
+ // Encode: "slot_id|seg_idx|{stateJSON}"
1581
+ const triggerVal = slot_id + '|' + idx + '|' + stateJson;
1582
  setNative('');
1583
  setTimeout(function() {
1584
+ setNative(triggerVal);
1585
+ console.log('[fireRegen] fired trigger for', slot_id, 'seg', idx);
1586
  }, 50);
1587
 
1588
  const lbl = document.getElementById('wf_seglabel_' + slot_id);
 
1685
  for _i, _rtrig in enumerate(taro_slot_rtrigs):
1686
  _slot_id = f"taro_{_i}"
1687
  def _make_taro_regen(_si, _sid):
1688
+ def _do(trigger_val, video, seed, cfg, steps, mode, cf_dur, cf_db):
1689
+ print(f"[regen TARO] trigger_val_len={len(trigger_val) if trigger_val else 0} video={video!r}")
1690
+ if not trigger_val:
1691
+ print(f"[regen TARO] early-exit: trigger_val empty")
1692
  return gr.update(), gr.update(), gr.update(value="")
1693
+ # Trigger format: "slot_id|seg_idx|{stateJSON}"
1694
+ parts = trigger_val.split("|", 2)
1695
+ if len(parts) != 3 or parts[0] != _sid:
1696
+ print(f"[regen TARO] early-exit: parts[0]={parts[0]!r} expected={_sid!r}")
1697
  return gr.update(), gr.update(), gr.update(value="")
1698
+ seg_idx = int(parts[1])
1699
+ state_json = parts[2]
1700
+ print(f"[regen TARO] slot={_sid} seg_idx={seg_idx} state_json_len={len(state_json)}")
1701
  lock = _get_slot_lock(_sid)
1702
  with lock:
1703
  print(f"[regen TARO] slot={_sid} seg_idx={seg_idx} β€” lock acquired, showing spinner")
 
1722
  _rtrig.change(
1723
  fn=_make_taro_regen(_i, _slot_id),
1724
  inputs=[_rtrig, taro_video, taro_seed, taro_cfg, taro_steps,
1725
+ taro_mode, taro_cf_dur, taro_cf_db],
1726
  outputs=[taro_slot_vids[_i], taro_slot_waves[_i], taro_slot_states[_i]],
1727
  )
1728
 
 
1777
  for _i, _rtrig in enumerate(mma_slot_rtrigs):
1778
  _slot_id = f"mma_{_i}"
1779
  def _make_mma_regen(_si, _sid):
1780
+ def _do(trigger_val, video, prompt, neg, seed, cfg, steps, cf_dur, cf_db):
1781
+ print(f"[regen MMA] trigger_val_len={len(trigger_val) if trigger_val else 0} video={video!r}")
1782
+ if not trigger_val:
1783
+ print(f"[regen MMA] early-exit: trigger_val empty")
1784
  return gr.update(), gr.update(), gr.update(value="")
1785
+ # Trigger format: "slot_id|seg_idx|{stateJSON}"
1786
+ parts = trigger_val.split("|", 2)
1787
+ if len(parts) != 3 or parts[0] != _sid:
1788
+ print(f"[regen MMA] early-exit: parts[0]={parts[0]!r} expected={_sid!r}")
1789
  return gr.update(), gr.update(), gr.update(value="")
1790
+ seg_idx = int(parts[1])
1791
+ state_json = parts[2]
1792
+ print(f"[regen MMA] slot={_sid} seg_idx={seg_idx} state_json_len={len(state_json)}")
1793
  lock = _get_slot_lock(_sid)
1794
  with lock:
1795
  print(f"[regen MMA] slot={_sid} seg_idx={seg_idx} β€” lock acquired, showing spinner")
 
1814
  _rtrig.change(
1815
  fn=_make_mma_regen(_i, _slot_id),
1816
  inputs=[_rtrig, mma_video, mma_prompt, mma_neg, mma_seed,
1817
+ mma_cfg, mma_steps, mma_cf_dur, mma_cf_db],
1818
  outputs=[mma_slot_vids[_i], mma_slot_waves[_i], mma_slot_states[_i]],
1819
  )
1820
 
 
1870
  for _i, _rtrig in enumerate(hf_slot_rtrigs):
1871
  _slot_id = f"hf_{_i}"
1872
  def _make_hf_regen(_si, _sid):
1873
+ def _do(trigger_val, video, prompt, neg, seed, guidance, steps, size, cf_dur, cf_db):
1874
+ print(f"[regen HF] trigger_val_len={len(trigger_val) if trigger_val else 0} video={video!r}")
1875
+ if not trigger_val:
1876
+ print(f"[regen HF] early-exit: trigger_val empty")
1877
  return gr.update(), gr.update(), gr.update(value="")
1878
+ # Trigger format: "slot_id|seg_idx|{stateJSON}"
1879
+ parts = trigger_val.split("|", 2)
1880
+ if len(parts) != 3 or parts[0] != _sid:
1881
+ print(f"[regen HF] early-exit: parts[0]={parts[0]!r} expected={_sid!r}")
1882
  return gr.update(), gr.update(), gr.update(value="")
1883
+ seg_idx = int(parts[1])
1884
+ state_json = parts[2]
1885
+ print(f"[regen HF] slot={_sid} seg_idx={seg_idx} state_json_len={len(state_json)}")
1886
  lock = _get_slot_lock(_sid)
1887
  with lock:
1888
  print(f"[regen HF] slot={_sid} seg_idx={seg_idx} β€” lock acquired, showing spinner")
 
1907
  _rtrig.change(
1908
  fn=_make_hf_regen(_i, _slot_id),
1909
  inputs=[_rtrig, hf_video, hf_prompt, hf_neg, hf_seed,
1910
+ hf_guidance, hf_steps, hf_size, hf_cf_dur, hf_cf_db],
1911
  outputs=[hf_slot_vids[_i], hf_slot_waves[_i], hf_slot_states[_i]],
1912
  )
1913