BoxOfColors commited on
Commit
1ccc3d0
·
1 Parent(s): 1bc8988

Debug: log vidUpdate structure, handle all Gradio 5 video output shapes

Browse files
Files changed (1) hide show
  1. app.py +44 -12
app.py CHANGED
@@ -1648,31 +1648,63 @@ _GLOBAL_JS = """
1648
  // data[0] = video update, data[1] = waveform HTML update
1649
  var vidUpdate = out.data[0];
1650
  var waveUpdate = out.data[1];
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1651
  // Apply video: update the <video> src inside the slot_vid element
1652
- if (vidUpdate && vidUpdate.value) {
1653
  var vidEl = document.getElementById('slot_vid_' + slot_id);
1654
  if (vidEl) {
1655
  var video = vidEl.querySelector('video');
1656
  if (video) {
1657
- var newSrc = vidUpdate.value.url || vidUpdate.value;
1658
- if (typeof newSrc === 'string') {
1659
- video.src = newSrc;
1660
- video.load();
1661
- }
 
 
1662
  }
 
 
1663
  }
1664
  }
 
1665
  // Apply waveform HTML: update innerHTML of the slot_wave element
1666
- if (waveUpdate && waveUpdate.value) {
 
 
 
 
 
 
 
 
1667
  var waveEl = document.getElementById('slot_wave_' + slot_id);
1668
  if (waveEl) {
1669
  // Find the inner content div (Gradio wraps HTML component)
1670
  var inner = waveEl.querySelector('.prose') || waveEl.querySelector('div');
1671
- if (inner) inner.innerHTML = waveUpdate.value;
1672
- else waveEl.innerHTML = waveUpdate.value;
1673
- // Also update the data-state on the new wf_container
1674
- var newContainer = waveEl.querySelector('#wf_container_' + slot_id);
1675
- // data-state is already embedded in the returned HTML
1676
  }
1677
  }
1678
  }
 
1648
  // data[0] = video update, data[1] = waveform HTML update
1649
  var vidUpdate = out.data[0];
1650
  var waveUpdate = out.data[1];
1651
+ console.log('[_listenAndApply] vidUpdate raw:', JSON.stringify(vidUpdate));
1652
+ console.log('[_listenAndApply] waveUpdate type:', typeof waveUpdate,
1653
+ waveUpdate && typeof waveUpdate === 'object' ? Object.keys(waveUpdate) : waveUpdate && String(waveUpdate).slice(0,80));
1654
+
1655
+ // Extract video URL — Gradio 5 gr.Video outputs as {video:{url:"...",...},subtitles:null}
1656
+ // or sometimes wrapped in {value:{video:{url:"..."}}}
1657
+ var newSrc = null;
1658
+ if (vidUpdate) {
1659
+ if (vidUpdate.video && vidUpdate.video.url) {
1660
+ newSrc = vidUpdate.video.url; // Gradio 5 direct
1661
+ } else if (vidUpdate.value && vidUpdate.value.video && vidUpdate.value.video.url) {
1662
+ newSrc = vidUpdate.value.video.url; // wrapped
1663
+ } else if (vidUpdate.value && vidUpdate.value.url) {
1664
+ newSrc = vidUpdate.value.url; // older style
1665
+ } else if (typeof vidUpdate.value === 'string') {
1666
+ newSrc = vidUpdate.value; // plain string
1667
+ } else if (vidUpdate.url) {
1668
+ newSrc = vidUpdate.url; // flat
1669
+ }
1670
+ }
1671
+ console.log('[_listenAndApply] resolved video src:', newSrc);
1672
+
1673
  // Apply video: update the <video> src inside the slot_vid element
1674
+ if (newSrc) {
1675
  var vidEl = document.getElementById('slot_vid_' + slot_id);
1676
  if (vidEl) {
1677
  var video = vidEl.querySelector('video');
1678
  if (video) {
1679
+ // Gradio 5 uses Svelte — set src attribute AND property to force reload
1680
+ video.setAttribute('src', newSrc);
1681
+ video.src = newSrc;
1682
+ video.load();
1683
+ console.log('[_listenAndApply] set video src on', 'slot_vid_' + slot_id);
1684
+ } else {
1685
+ console.warn('[_listenAndApply] no <video> element found inside', 'slot_vid_' + slot_id);
1686
  }
1687
+ } else {
1688
+ console.warn('[_listenAndApply] no element with id slot_vid_' + slot_id);
1689
  }
1690
  }
1691
+
1692
  // Apply waveform HTML: update innerHTML of the slot_wave element
1693
+ var waveHtml = null;
1694
+ if (waveUpdate) {
1695
+ if (typeof waveUpdate === 'string') {
1696
+ waveHtml = waveUpdate;
1697
+ } else if (waveUpdate.value && typeof waveUpdate.value === 'string') {
1698
+ waveHtml = waveUpdate.value;
1699
+ }
1700
+ }
1701
+ if (waveHtml) {
1702
  var waveEl = document.getElementById('slot_wave_' + slot_id);
1703
  if (waveEl) {
1704
  // Find the inner content div (Gradio wraps HTML component)
1705
  var inner = waveEl.querySelector('.prose') || waveEl.querySelector('div');
1706
+ if (inner) inner.innerHTML = waveHtml;
1707
+ else waveEl.innerHTML = waveHtml;
 
 
 
1708
  }
1709
  }
1710
  }