BoxOfColors commited on
Commit
8ddbfd1
·
1 Parent(s): 0378fbe

fix: add video download link to waveform panel so it always reflects latest regen

Browse files

Gradio's built-in gr.Video download button is tied to Svelte state and stays
pointing at the originally generated file even after regen. Added a dedicated
Video download link inside _build_waveform_html (served via /gradio_api/file=)
alongside the existing audio download link. Since the waveform HTML is rebuilt
with the fresh video_path on every regen, this link always downloads the most
recent muxed video. Renamed the existing download button label to Audio for
clarity.

Files changed (1) hide show
  1. app.py +10 -4
app.py CHANGED
@@ -841,7 +841,8 @@ def _splice_and_save(new_wav, seg_idx, meta, slot_id):
841
  state_json_new = json.dumps(_serialised_meta)
842
 
843
  waveform_html = _build_waveform_html(audio_path, segments, slot_id, "",
844
- state_json=state_json_new)
 
845
  return video_path, audio_path, updated_meta, waveform_html
846
 
847
 
@@ -1168,7 +1169,7 @@ def _build_regen_pending_html(segments: list, regen_seg_idx: int, slot_id: str,
1168
 
1169
  def _build_waveform_html(audio_path: str, segments: list, slot_id: str,
1170
  hidden_input_id: str, state_json: str = "",
1171
- fn_index: int = -1) -> str:
1172
  """Return a self-contained HTML block with a Canvas waveform (display only),
1173
  segment boundary markers, and a download link.
1174
 
@@ -1417,7 +1418,11 @@ def _build_waveform_html(audio_path: str, segments: list, slot_id: str,
1417
  <a href="{data_uri}" download="audio_{slot_id}.wav"
1418
  style="margin-left:auto;background:#333;color:#eee;border:1px solid #555;
1419
  border-radius:4px;padding:3px 10px;font-size:12px;text-decoration:none;">
1420
- &#8595; Download</a>
 
 
 
 
1421
  </div>
1422
  <div id="wf_seglabel_{slot_id}"
1423
  style="color:#aaa;font-size:11px;margin-top:4px;min-height:16px;"></div>
@@ -1471,7 +1476,8 @@ def _unpack_outputs(flat: list, n: int, tab_prefix: str) -> list:
1471
  slot_id = f"{tab_prefix}_{i}"
1472
  state_json = json.dumps(meta)
1473
  html = _build_waveform_html(aud_path, meta["segments"], slot_id,
1474
- "", state_json=state_json)
 
1475
  wave_updates.append(gr.update(value=html))
1476
  else:
1477
  wave_updates.append(gr.update(
 
841
  state_json_new = json.dumps(_serialised_meta)
842
 
843
  waveform_html = _build_waveform_html(audio_path, segments, slot_id, "",
844
+ state_json=state_json_new,
845
+ video_path=video_path)
846
  return video_path, audio_path, updated_meta, waveform_html
847
 
848
 
 
1169
 
1170
  def _build_waveform_html(audio_path: str, segments: list, slot_id: str,
1171
  hidden_input_id: str, state_json: str = "",
1172
+ fn_index: int = -1, video_path: str = "") -> str:
1173
  """Return a self-contained HTML block with a Canvas waveform (display only),
1174
  segment boundary markers, and a download link.
1175
 
 
1418
  <a href="{data_uri}" download="audio_{slot_id}.wav"
1419
  style="margin-left:auto;background:#333;color:#eee;border:1px solid #555;
1420
  border-radius:4px;padding:3px 10px;font-size:12px;text-decoration:none;">
1421
+ &#8595; Audio</a>{f'''
1422
+ <a href="/gradio_api/file={video_path}" download="video_{slot_id}.mp4"
1423
+ style="background:#333;color:#eee;border:1px solid #555;
1424
+ border-radius:4px;padding:3px 10px;font-size:12px;text-decoration:none;">
1425
+ &#8595; Video</a>''' if video_path else ''}
1426
  </div>
1427
  <div id="wf_seglabel_{slot_id}"
1428
  style="color:#aaa;font-size:11px;margin-top:4px;min-height:16px;"></div>
 
1476
  slot_id = f"{tab_prefix}_{i}"
1477
  state_json = json.dumps(meta)
1478
  html = _build_waveform_html(aud_path, meta["segments"], slot_id,
1479
+ "", state_json=state_json,
1480
+ video_path=meta.get("video_path", ""))
1481
  wave_updates.append(gr.update(value=html))
1482
  else:
1483
  wave_updates.append(gr.update(