BoxOfColors Claude Sonnet 4.6 commited on
Commit
6d105d2
·
1 Parent(s): b664ef1

Add shared video upload above tabs — persists across model switches

Browse files

Replaces the three separate per-tab gr.Video components with a single
shared gr.Video above the tabs backed by a gr.State. All three model
tabs now read from the shared state, so switching tabs no longer resets
the uploaded video. User must explicitly clear it with the X button.

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>

Files changed (1) hide show
  1. app.py +12 -8
app.py CHANGED
@@ -776,6 +776,13 @@ with gr.Blocks(title="Generate Audio for Video") as demo:
776
  "| **HunyuanFoley** | Cinematic foley requiring high fidelity and explicit creative direction — dramatic SFX, layered environmental design, or any scene where you have a clear written description of the desired sound palette. | Quick one-shot clips where you don't want to write a prompt, or raw impact sounds where timing precision matters more than richness. |"
777
  )
778
 
 
 
 
 
 
 
 
779
  with gr.Tabs():
780
 
781
  # ---------------------------------------------------------- #
@@ -784,7 +791,6 @@ with gr.Blocks(title="Generate Audio for Video") as demo:
784
  with gr.Tab("TARO"):
785
  with gr.Row():
786
  with gr.Column():
787
- taro_video = gr.Video(label="Input Video")
788
  taro_seed = gr.Number(label="Seed (-1 = random)", value=get_random_seed(), precision=0)
789
  taro_cfg = gr.Slider(label="CFG Scale", minimum=1, maximum=15, value=7.5, step=0.5)
790
  taro_steps = gr.Slider(label="Sampling Steps", minimum=10, maximum=50, value=25, step=1)
@@ -797,10 +803,10 @@ with gr.Blocks(title="Generate Audio for Video") as demo:
797
  with gr.Column():
798
  taro_slot_grps, taro_slot_vids, taro_slot_auds = _make_output_slots()
799
 
800
- for trigger in [taro_video, taro_steps, taro_cf_dur]:
801
  trigger.change(
802
  fn=_on_video_upload_taro,
803
- inputs=[taro_video, taro_steps, taro_cf_dur],
804
  outputs=[taro_samples],
805
  )
806
  taro_samples.change(
@@ -814,7 +820,7 @@ with gr.Blocks(title="Generate Audio for Video") as demo:
814
 
815
  taro_btn.click(
816
  fn=_run_taro,
817
- inputs=[taro_video, taro_seed, taro_cfg, taro_steps, taro_mode,
818
  taro_cf_dur, taro_cf_db, taro_samples],
819
  outputs=taro_slot_grps + taro_slot_vids + taro_slot_auds,
820
  )
@@ -825,7 +831,6 @@ with gr.Blocks(title="Generate Audio for Video") as demo:
825
  with gr.Tab("MMAudio"):
826
  with gr.Row():
827
  with gr.Column():
828
- mma_video = gr.Video(label="Input Video")
829
  mma_prompt = gr.Textbox(label="Prompt", placeholder="e.g. footsteps on gravel")
830
  mma_neg = gr.Textbox(label="Negative Prompt", placeholder="music, speech")
831
  mma_seed = gr.Number(label="Seed (-1 = random)", value=get_random_seed(), precision=0)
@@ -850,7 +855,7 @@ with gr.Blocks(title="Generate Audio for Video") as demo:
850
 
851
  mma_btn.click(
852
  fn=_run_mmaudio,
853
- inputs=[mma_video, mma_prompt, mma_neg, mma_seed,
854
  mma_cfg, mma_steps, mma_cf_dur, mma_cf_db, mma_samples],
855
  outputs=mma_slot_grps + mma_slot_vids + mma_slot_auds,
856
  )
@@ -861,7 +866,6 @@ with gr.Blocks(title="Generate Audio for Video") as demo:
861
  with gr.Tab("HunyuanFoley"):
862
  with gr.Row():
863
  with gr.Column():
864
- hf_video = gr.Video(label="Input Video")
865
  hf_prompt = gr.Textbox(label="Prompt", placeholder="e.g. rain hitting a metal roof")
866
  hf_neg = gr.Textbox(label="Negative Prompt", value="noisy, harsh")
867
  hf_seed = gr.Number(label="Seed (-1 = random)", value=get_random_seed(), precision=0)
@@ -887,7 +891,7 @@ with gr.Blocks(title="Generate Audio for Video") as demo:
887
 
888
  hf_btn.click(
889
  fn=_run_hunyuan,
890
- inputs=[hf_video, hf_prompt, hf_neg, hf_seed,
891
  hf_guidance, hf_steps, hf_size, hf_cf_dur, hf_cf_db, hf_samples],
892
  outputs=hf_slot_grps + hf_slot_vids + hf_slot_auds,
893
  )
 
776
  "| **HunyuanFoley** | Cinematic foley requiring high fidelity and explicit creative direction — dramatic SFX, layered environmental design, or any scene where you have a clear written description of the desired sound palette. | Quick one-shot clips where you don't want to write a prompt, or raw impact sounds where timing precision matters more than richness. |"
777
  )
778
 
779
+ # Shared video upload — persists across all model tabs
780
+ shared_video = gr.Video(label="Input Video", interactive=True)
781
+ shared_video_state = gr.State(value=None)
782
+
783
+ # Keep state in sync whenever the shared upload changes
784
+ shared_video.change(fn=lambda v: v, inputs=[shared_video], outputs=[shared_video_state])
785
+
786
  with gr.Tabs():
787
 
788
  # ---------------------------------------------------------- #
 
791
  with gr.Tab("TARO"):
792
  with gr.Row():
793
  with gr.Column():
 
794
  taro_seed = gr.Number(label="Seed (-1 = random)", value=get_random_seed(), precision=0)
795
  taro_cfg = gr.Slider(label="CFG Scale", minimum=1, maximum=15, value=7.5, step=0.5)
796
  taro_steps = gr.Slider(label="Sampling Steps", minimum=10, maximum=50, value=25, step=1)
 
803
  with gr.Column():
804
  taro_slot_grps, taro_slot_vids, taro_slot_auds = _make_output_slots()
805
 
806
+ for trigger in [shared_video, taro_steps, taro_cf_dur]:
807
  trigger.change(
808
  fn=_on_video_upload_taro,
809
+ inputs=[shared_video_state, taro_steps, taro_cf_dur],
810
  outputs=[taro_samples],
811
  )
812
  taro_samples.change(
 
820
 
821
  taro_btn.click(
822
  fn=_run_taro,
823
+ inputs=[shared_video_state, taro_seed, taro_cfg, taro_steps, taro_mode,
824
  taro_cf_dur, taro_cf_db, taro_samples],
825
  outputs=taro_slot_grps + taro_slot_vids + taro_slot_auds,
826
  )
 
831
  with gr.Tab("MMAudio"):
832
  with gr.Row():
833
  with gr.Column():
 
834
  mma_prompt = gr.Textbox(label="Prompt", placeholder="e.g. footsteps on gravel")
835
  mma_neg = gr.Textbox(label="Negative Prompt", placeholder="music, speech")
836
  mma_seed = gr.Number(label="Seed (-1 = random)", value=get_random_seed(), precision=0)
 
855
 
856
  mma_btn.click(
857
  fn=_run_mmaudio,
858
+ inputs=[shared_video_state, mma_prompt, mma_neg, mma_seed,
859
  mma_cfg, mma_steps, mma_cf_dur, mma_cf_db, mma_samples],
860
  outputs=mma_slot_grps + mma_slot_vids + mma_slot_auds,
861
  )
 
866
  with gr.Tab("HunyuanFoley"):
867
  with gr.Row():
868
  with gr.Column():
 
869
  hf_prompt = gr.Textbox(label="Prompt", placeholder="e.g. rain hitting a metal roof")
870
  hf_neg = gr.Textbox(label="Negative Prompt", value="noisy, harsh")
871
  hf_seed = gr.Number(label="Seed (-1 = random)", value=get_random_seed(), precision=0)
 
891
 
892
  hf_btn.click(
893
  fn=_run_hunyuan,
894
+ inputs=[shared_video_state, hf_prompt, hf_neg, hf_seed,
895
  hf_guidance, hf_steps, hf_size, hf_cf_dur, hf_cf_db, hf_samples],
896
  outputs=hf_slot_grps + hf_slot_vids + hf_slot_auds,
897
  )