Spaces:
Running on Zero
Running on Zero
Commit Β·
95fa2df
1
Parent(s): 8375700
Add regen debug logging + remove console.log noise
Browse files- Add [regen TARO/MMA/HF] print statements at every step of regen:
trigger received, early-exit reason, lock acquired, inference start/done, errors
- Remove all console.log/warn/error from waveform iframe JS
- Add per-slot threading.Lock to prevent concurrent regen race conditions
- Add regen loading indicator (_build_regen_pending_html)
- Replace gr.State with hidden gr.Textbox (JSON) to fix Gradio 5 SSR
'Too many arguments' in endpoint validation
Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
app.py
CHANGED
|
@@ -1243,7 +1243,6 @@ def _build_waveform_html(audio_path: str, segments: list, slot_id: str,
|
|
| 1243 |
const dpr = window.devicePixelRatio || 1;
|
| 1244 |
const W = wrap.getBoundingClientRect().width || window.innerWidth || 600;
|
| 1245 |
const H = 80;
|
| 1246 |
-
console.log('[wf iframe {slot_id}] drawWaveform W='+W+' H='+H);
|
| 1247 |
cv.width = W * dpr; cv.height = H * dpr;
|
| 1248 |
const ctx = cv.getContext('2d');
|
| 1249 |
ctx.scale(dpr, dpr);
|
|
@@ -1340,34 +1339,27 @@ def _build_waveform_html(audio_path: str, segments: list, slot_id: str,
|
|
| 1340 |
|
| 1341 |
// ββ Decode audio βββββββββββββββββββββββββββββββββββββββββββββββββββ
|
| 1342 |
const b64str = '{b64}';
|
| 1343 |
-
console.log('[wf iframe {slot_id}] b64 len='+b64str.length);
|
| 1344 |
const bin = atob(b64str);
|
| 1345 |
const buf = new Uint8Array(bin.length);
|
| 1346 |
for (let i=0; i<bin.length; i++) buf[i]=bin.charCodeAt(i);
|
| 1347 |
-
console.log('[wf iframe {slot_id}] raw bytes='+buf.byteLength);
|
| 1348 |
|
| 1349 |
const AudioCtx = window.AudioContext || window.webkitAudioContext;
|
| 1350 |
-
if (
|
| 1351 |
-
console.warn('[wf iframe {slot_id}] No AudioContext');
|
| 1352 |
-
}} else {{
|
| 1353 |
const tmpCtx = new AudioCtx({{sampleRate:44100}});
|
| 1354 |
-
console.log('[wf iframe {slot_id}] calling decodeAudioData');
|
| 1355 |
try {{
|
| 1356 |
tmpCtx.decodeAudioData(buf.buffer.slice(0),
|
| 1357 |
function(ab) {{
|
| 1358 |
-
console.log('[wf iframe {slot_id}] decoded OK duration='+ab.duration+'s');
|
| 1359 |
try {{ tmpCtx.close(); }} catch(e) {{}}
|
| 1360 |
function tryDraw() {{
|
| 1361 |
const W = wrap.getBoundingClientRect().width || window.innerWidth;
|
| 1362 |
-
console.log('[wf iframe {slot_id}] tryDraw W='+W);
|
| 1363 |
if (W > 0) {{ drawWaveform(ab.getChannelData(0), ab.duration); }}
|
| 1364 |
else {{ setTimeout(tryDraw, 100); }}
|
| 1365 |
}}
|
| 1366 |
tryDraw();
|
| 1367 |
}},
|
| 1368 |
-
function(err) {{
|
| 1369 |
);
|
| 1370 |
-
}} catch(e) {{
|
| 1371 |
}}
|
| 1372 |
}})();
|
| 1373 |
</script>
|
|
@@ -1539,9 +1531,9 @@ _GLOBAL_JS = """
|
|
| 1539 |
function fireRegen(slot_id, idx) {
|
| 1540 |
const hidden_id = 'regen_trigger_' + slot_id;
|
| 1541 |
const el = document.getElementById(hidden_id);
|
| 1542 |
-
if (!el)
|
| 1543 |
const input = el.querySelector('input, textarea');
|
| 1544 |
-
if (!input)
|
| 1545 |
const desc = Object.getOwnPropertyDescriptor(HTMLInputElement.prototype, 'value')
|
| 1546 |
|| Object.getOwnPropertyDescriptor(HTMLTextAreaElement.prototype, 'value');
|
| 1547 |
if (desc && desc.set) desc.set.call(input, slot_id + '|' + idx);
|
|
@@ -1649,26 +1641,35 @@ with gr.Blocks(title="Generate Audio for Video", css=_SLOT_CSS, js=_GLOBAL_JS) a
|
|
| 1649 |
_slot_id = f"taro_{_i}"
|
| 1650 |
def _make_taro_regen(_si, _sid):
|
| 1651 |
def _do(trigger_val, video, seed, cfg, steps, mode, cf_dur, cf_db, state_json):
|
|
|
|
| 1652 |
if not trigger_val or not state_json:
|
|
|
|
| 1653 |
return gr.update(), gr.update(), gr.update(value=""), gr.update()
|
| 1654 |
parts = trigger_val.split("|")
|
| 1655 |
if len(parts) != 2 or parts[0] != _sid:
|
|
|
|
| 1656 |
return gr.update(), gr.update(), gr.update(value=""), gr.update()
|
| 1657 |
seg_idx = int(parts[1])
|
| 1658 |
-
|
| 1659 |
-
# don't read stale state (second regen waits for first to finish).
|
| 1660 |
lock = _get_slot_lock(_sid)
|
| 1661 |
with lock:
|
|
|
|
| 1662 |
state = json.loads(state_json)
|
| 1663 |
pending_html = _build_regen_pending_html(
|
| 1664 |
state["segments"], seg_idx, _sid,
|
| 1665 |
f"regen_trigger_{_sid}"
|
| 1666 |
)
|
| 1667 |
yield gr.update(), gr.update(value=pending_html), gr.update(value=state_json), gr.update()
|
| 1668 |
-
|
| 1669 |
-
|
| 1670 |
-
|
| 1671 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1672 |
yield gr.update(value=vid), gr.update(value=html), gr.update(value=new_meta_json), gr.update(value="")
|
| 1673 |
return _do
|
| 1674 |
_rtrig.change(
|
|
@@ -1731,24 +1732,35 @@ with gr.Blocks(title="Generate Audio for Video", css=_SLOT_CSS, js=_GLOBAL_JS) a
|
|
| 1731 |
_slot_id = f"mma_{_i}"
|
| 1732 |
def _make_mma_regen(_si, _sid):
|
| 1733 |
def _do(trigger_val, video, prompt, neg, seed, cfg, steps, cf_dur, cf_db, state_json):
|
|
|
|
| 1734 |
if not trigger_val or not state_json:
|
|
|
|
| 1735 |
return gr.update(), gr.update(), gr.update(value=""), gr.update()
|
| 1736 |
parts = trigger_val.split("|")
|
| 1737 |
if len(parts) != 2 or parts[0] != _sid:
|
|
|
|
| 1738 |
return gr.update(), gr.update(), gr.update(value=""), gr.update()
|
| 1739 |
seg_idx = int(parts[1])
|
|
|
|
| 1740 |
lock = _get_slot_lock(_sid)
|
| 1741 |
with lock:
|
|
|
|
| 1742 |
state = json.loads(state_json)
|
| 1743 |
pending_html = _build_regen_pending_html(
|
| 1744 |
state["segments"], seg_idx, _sid,
|
| 1745 |
f"regen_trigger_{_sid}"
|
| 1746 |
)
|
| 1747 |
yield gr.update(), gr.update(value=pending_html), gr.update(value=state_json), gr.update()
|
| 1748 |
-
|
| 1749 |
-
|
| 1750 |
-
|
| 1751 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1752 |
yield gr.update(value=vid), gr.update(value=html), gr.update(value=new_meta_json), gr.update(value="")
|
| 1753 |
return _do
|
| 1754 |
_rtrig.change(
|
|
@@ -1812,24 +1824,35 @@ with gr.Blocks(title="Generate Audio for Video", css=_SLOT_CSS, js=_GLOBAL_JS) a
|
|
| 1812 |
_slot_id = f"hf_{_i}"
|
| 1813 |
def _make_hf_regen(_si, _sid):
|
| 1814 |
def _do(trigger_val, video, prompt, neg, seed, guidance, steps, size, cf_dur, cf_db, state_json):
|
|
|
|
| 1815 |
if not trigger_val or not state_json:
|
|
|
|
| 1816 |
return gr.update(), gr.update(), gr.update(value=""), gr.update()
|
| 1817 |
parts = trigger_val.split("|")
|
| 1818 |
if len(parts) != 2 or parts[0] != _sid:
|
|
|
|
| 1819 |
return gr.update(), gr.update(), gr.update(value=""), gr.update()
|
| 1820 |
seg_idx = int(parts[1])
|
|
|
|
| 1821 |
lock = _get_slot_lock(_sid)
|
| 1822 |
with lock:
|
|
|
|
| 1823 |
state = json.loads(state_json)
|
| 1824 |
pending_html = _build_regen_pending_html(
|
| 1825 |
state["segments"], seg_idx, _sid,
|
| 1826 |
f"regen_trigger_{_sid}"
|
| 1827 |
)
|
| 1828 |
yield gr.update(), gr.update(value=pending_html), gr.update(value=state_json), gr.update()
|
| 1829 |
-
|
| 1830 |
-
|
| 1831 |
-
|
| 1832 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1833 |
yield gr.update(value=vid), gr.update(value=html), gr.update(value=new_meta_json), gr.update(value="")
|
| 1834 |
return _do
|
| 1835 |
_rtrig.change(
|
|
|
|
| 1243 |
const dpr = window.devicePixelRatio || 1;
|
| 1244 |
const W = wrap.getBoundingClientRect().width || window.innerWidth || 600;
|
| 1245 |
const H = 80;
|
|
|
|
| 1246 |
cv.width = W * dpr; cv.height = H * dpr;
|
| 1247 |
const ctx = cv.getContext('2d');
|
| 1248 |
ctx.scale(dpr, dpr);
|
|
|
|
| 1339 |
|
| 1340 |
// ββ Decode audio βββββββββββββββββββββββββββββββββββββββββββββββββββ
|
| 1341 |
const b64str = '{b64}';
|
|
|
|
| 1342 |
const bin = atob(b64str);
|
| 1343 |
const buf = new Uint8Array(bin.length);
|
| 1344 |
for (let i=0; i<bin.length; i++) buf[i]=bin.charCodeAt(i);
|
|
|
|
| 1345 |
|
| 1346 |
const AudioCtx = window.AudioContext || window.webkitAudioContext;
|
| 1347 |
+
if (AudioCtx) {{
|
|
|
|
|
|
|
| 1348 |
const tmpCtx = new AudioCtx({{sampleRate:44100}});
|
|
|
|
| 1349 |
try {{
|
| 1350 |
tmpCtx.decodeAudioData(buf.buffer.slice(0),
|
| 1351 |
function(ab) {{
|
|
|
|
| 1352 |
try {{ tmpCtx.close(); }} catch(e) {{}}
|
| 1353 |
function tryDraw() {{
|
| 1354 |
const W = wrap.getBoundingClientRect().width || window.innerWidth;
|
|
|
|
| 1355 |
if (W > 0) {{ drawWaveform(ab.getChannelData(0), ab.duration); }}
|
| 1356 |
else {{ setTimeout(tryDraw, 100); }}
|
| 1357 |
}}
|
| 1358 |
tryDraw();
|
| 1359 |
}},
|
| 1360 |
+
function(err) {{}}
|
| 1361 |
);
|
| 1362 |
+
}} catch(e) {{}}
|
| 1363 |
}}
|
| 1364 |
}})();
|
| 1365 |
</script>
|
|
|
|
| 1531 |
function fireRegen(slot_id, idx) {
|
| 1532 |
const hidden_id = 'regen_trigger_' + slot_id;
|
| 1533 |
const el = document.getElementById(hidden_id);
|
| 1534 |
+
if (!el) return;
|
| 1535 |
const input = el.querySelector('input, textarea');
|
| 1536 |
+
if (!input) return;
|
| 1537 |
const desc = Object.getOwnPropertyDescriptor(HTMLInputElement.prototype, 'value')
|
| 1538 |
|| Object.getOwnPropertyDescriptor(HTMLTextAreaElement.prototype, 'value');
|
| 1539 |
if (desc && desc.set) desc.set.call(input, slot_id + '|' + idx);
|
|
|
|
| 1641 |
_slot_id = f"taro_{_i}"
|
| 1642 |
def _make_taro_regen(_si, _sid):
|
| 1643 |
def _do(trigger_val, video, seed, cfg, steps, mode, cf_dur, cf_db, state_json):
|
| 1644 |
+
print(f"[regen TARO] trigger_val={trigger_val!r} state_json_len={len(state_json) if state_json else 0} video={video!r}")
|
| 1645 |
if not trigger_val or not state_json:
|
| 1646 |
+
print(f"[regen TARO] early-exit: trigger_val empty={not trigger_val} state empty={not state_json}")
|
| 1647 |
return gr.update(), gr.update(), gr.update(value=""), gr.update()
|
| 1648 |
parts = trigger_val.split("|")
|
| 1649 |
if len(parts) != 2 or parts[0] != _sid:
|
| 1650 |
+
print(f"[regen TARO] early-exit: parts={parts} expected slot={_sid}")
|
| 1651 |
return gr.update(), gr.update(), gr.update(value=""), gr.update()
|
| 1652 |
seg_idx = int(parts[1])
|
| 1653 |
+
print(f"[regen TARO] slot={_sid} seg_idx={seg_idx} β acquiring lock")
|
|
|
|
| 1654 |
lock = _get_slot_lock(_sid)
|
| 1655 |
with lock:
|
| 1656 |
+
print(f"[regen TARO] slot={_sid} seg_idx={seg_idx} β lock acquired, showing spinner")
|
| 1657 |
state = json.loads(state_json)
|
| 1658 |
pending_html = _build_regen_pending_html(
|
| 1659 |
state["segments"], seg_idx, _sid,
|
| 1660 |
f"regen_trigger_{_sid}"
|
| 1661 |
)
|
| 1662 |
yield gr.update(), gr.update(value=pending_html), gr.update(value=state_json), gr.update()
|
| 1663 |
+
print(f"[regen TARO] slot={_sid} seg_idx={seg_idx} β calling regen_taro_segment")
|
| 1664 |
+
try:
|
| 1665 |
+
vid, aud, new_meta_json, html = regen_taro_segment(
|
| 1666 |
+
video, seg_idx, state_json,
|
| 1667 |
+
seed, cfg, steps, mode, cf_dur, cf_db, _sid,
|
| 1668 |
+
)
|
| 1669 |
+
print(f"[regen TARO] slot={_sid} seg_idx={seg_idx} β done, vid={vid!r}")
|
| 1670 |
+
except Exception as _e:
|
| 1671 |
+
print(f"[regen TARO] slot={_sid} seg_idx={seg_idx} β ERROR: {_e}")
|
| 1672 |
+
raise
|
| 1673 |
yield gr.update(value=vid), gr.update(value=html), gr.update(value=new_meta_json), gr.update(value="")
|
| 1674 |
return _do
|
| 1675 |
_rtrig.change(
|
|
|
|
| 1732 |
_slot_id = f"mma_{_i}"
|
| 1733 |
def _make_mma_regen(_si, _sid):
|
| 1734 |
def _do(trigger_val, video, prompt, neg, seed, cfg, steps, cf_dur, cf_db, state_json):
|
| 1735 |
+
print(f"[regen MMA] trigger_val={trigger_val!r} state_json_len={len(state_json) if state_json else 0} video={video!r}")
|
| 1736 |
if not trigger_val or not state_json:
|
| 1737 |
+
print(f"[regen MMA] early-exit: trigger_val empty={not trigger_val} state empty={not state_json}")
|
| 1738 |
return gr.update(), gr.update(), gr.update(value=""), gr.update()
|
| 1739 |
parts = trigger_val.split("|")
|
| 1740 |
if len(parts) != 2 or parts[0] != _sid:
|
| 1741 |
+
print(f"[regen MMA] early-exit: parts={parts} expected slot={_sid}")
|
| 1742 |
return gr.update(), gr.update(), gr.update(value=""), gr.update()
|
| 1743 |
seg_idx = int(parts[1])
|
| 1744 |
+
print(f"[regen MMA] slot={_sid} seg_idx={seg_idx} β acquiring lock")
|
| 1745 |
lock = _get_slot_lock(_sid)
|
| 1746 |
with lock:
|
| 1747 |
+
print(f"[regen MMA] slot={_sid} seg_idx={seg_idx} β lock acquired, showing spinner")
|
| 1748 |
state = json.loads(state_json)
|
| 1749 |
pending_html = _build_regen_pending_html(
|
| 1750 |
state["segments"], seg_idx, _sid,
|
| 1751 |
f"regen_trigger_{_sid}"
|
| 1752 |
)
|
| 1753 |
yield gr.update(), gr.update(value=pending_html), gr.update(value=state_json), gr.update()
|
| 1754 |
+
print(f"[regen MMA] slot={_sid} seg_idx={seg_idx} β calling regen_mmaudio_segment")
|
| 1755 |
+
try:
|
| 1756 |
+
vid, aud, new_meta_json, html = regen_mmaudio_segment(
|
| 1757 |
+
video, seg_idx, state_json,
|
| 1758 |
+
prompt, neg, seed, cfg, steps, cf_dur, cf_db, _sid,
|
| 1759 |
+
)
|
| 1760 |
+
print(f"[regen MMA] slot={_sid} seg_idx={seg_idx} β done, vid={vid!r}")
|
| 1761 |
+
except Exception as _e:
|
| 1762 |
+
print(f"[regen MMA] slot={_sid} seg_idx={seg_idx} β ERROR: {_e}")
|
| 1763 |
+
raise
|
| 1764 |
yield gr.update(value=vid), gr.update(value=html), gr.update(value=new_meta_json), gr.update(value="")
|
| 1765 |
return _do
|
| 1766 |
_rtrig.change(
|
|
|
|
| 1824 |
_slot_id = f"hf_{_i}"
|
| 1825 |
def _make_hf_regen(_si, _sid):
|
| 1826 |
def _do(trigger_val, video, prompt, neg, seed, guidance, steps, size, cf_dur, cf_db, state_json):
|
| 1827 |
+
print(f"[regen HF] trigger_val={trigger_val!r} state_json_len={len(state_json) if state_json else 0} video={video!r}")
|
| 1828 |
if not trigger_val or not state_json:
|
| 1829 |
+
print(f"[regen HF] early-exit: trigger_val empty={not trigger_val} state empty={not state_json}")
|
| 1830 |
return gr.update(), gr.update(), gr.update(value=""), gr.update()
|
| 1831 |
parts = trigger_val.split("|")
|
| 1832 |
if len(parts) != 2 or parts[0] != _sid:
|
| 1833 |
+
print(f"[regen HF] early-exit: parts={parts} expected slot={_sid}")
|
| 1834 |
return gr.update(), gr.update(), gr.update(value=""), gr.update()
|
| 1835 |
seg_idx = int(parts[1])
|
| 1836 |
+
print(f"[regen HF] slot={_sid} seg_idx={seg_idx} β acquiring lock")
|
| 1837 |
lock = _get_slot_lock(_sid)
|
| 1838 |
with lock:
|
| 1839 |
+
print(f"[regen HF] slot={_sid} seg_idx={seg_idx} β lock acquired, showing spinner")
|
| 1840 |
state = json.loads(state_json)
|
| 1841 |
pending_html = _build_regen_pending_html(
|
| 1842 |
state["segments"], seg_idx, _sid,
|
| 1843 |
f"regen_trigger_{_sid}"
|
| 1844 |
)
|
| 1845 |
yield gr.update(), gr.update(value=pending_html), gr.update(value=state_json), gr.update()
|
| 1846 |
+
print(f"[regen HF] slot={_sid} seg_idx={seg_idx} β calling regen_hunyuan_segment")
|
| 1847 |
+
try:
|
| 1848 |
+
vid, aud, new_meta_json, html = regen_hunyuan_segment(
|
| 1849 |
+
video, seg_idx, state_json,
|
| 1850 |
+
prompt, neg, seed, guidance, steps, size, cf_dur, cf_db, _sid,
|
| 1851 |
+
)
|
| 1852 |
+
print(f"[regen HF] slot={_sid} seg_idx={seg_idx} β done, vid={vid!r}")
|
| 1853 |
+
except Exception as _e:
|
| 1854 |
+
print(f"[regen HF] slot={_sid} seg_idx={seg_idx} β ERROR: {_e}")
|
| 1855 |
+
raise
|
| 1856 |
yield gr.update(value=vid), gr.update(value=html), gr.update(value=new_meta_json), gr.update(value="")
|
| 1857 |
return _do
|
| 1858 |
_rtrig.change(
|