xi0v Fabrice-TIERCELIN commited on
Commit
1cf330c
β€’
1 Parent(s): d3e5f59

Autoplay the generated video and add a download button (#19)

Browse files

- Autoplay the generated video and add a download button (a452b5852a3919f3f735c9f3dc2271f15b1aa280)


Co-authored-by: Fabrice TIERCELIN <Fabrice-TIERCELIN@users.noreply.huggingface.co>

Files changed (1) hide show
  1. app.py +8 -7
app.py CHANGED
@@ -55,7 +55,7 @@ def sample(
55
  frames = fps14Pipe(image, decode_chunk_size=decoding_t, generator=generator, motion_bucket_id=motion_bucket_id, noise_aug_strength=noise_aug_strength, num_frames=25).frames[0]
56
  export_to_video(frames, video_path, fps=fps_id)
57
 
58
- return video_path, gr.update(label="Generated frames in *." + frame_format + " format", format = frame_format, value = frames), seed
59
 
60
  def resize_image(image, output_size=(1024, 576)):
61
  # Calculate aspect ratios
@@ -105,18 +105,19 @@ with gr.Blocks() as demo:
105
  noise_aug_strength = gr.Slider(label="Noise strength", info="The noise to add", value=0.1, minimum=0, maximum=1, step=0.1)
106
  decoding_t = gr.Slider(label="Decoding", info="Number of frames decoded at a time; this eats more VRAM; reduce if necessary", value=3, minimum=1, maximum=5, step=1)
107
  frame_format = gr.Radio([["*.png", "png"], ["*.webp", "webp"], ["*.jpeg", "jpeg"], ["*.gif", "gif"], ["*.bmp", "bmp"]], label="Image format for result", info="File extention", value="webp", interactive=True)
108
- version = gr.Radio([["Auto", "auto"], ["SVD (trained on 14 f/s)", "svd"], ["SVD-XT (trained on 25 f/s)", "svdxt"]], label="Model", info="Trained model", value="auto", interactive=True)
109
  seed = gr.Slider(label="Seed", value=42, randomize=True, minimum=0, maximum=max_64_bit_int, step=1)
110
  randomize_seed = gr.Checkbox(label="Randomize seed", value=True)
111
 
112
- generate_btn = gr.Button(value="Animate", variant="primary")
113
 
114
  with gr.Column():
115
- video = gr.Video(label="Generated video")
116
- gallery = gr.Gallery(label="Generated frames")
 
117
 
118
  image.upload(fn=resize_image, inputs=image, outputs=image, queue=False)
119
- generate_btn.click(fn=sample, inputs=[image, seed, randomize_seed, motion_bucket_id, fps_id, noise_aug_strength, decoding_t, frame_format, version], outputs=[video, gallery, seed], api_name="video")
120
 
121
  gr.Examples(
122
  examples=[
@@ -125,7 +126,7 @@ with gr.Blocks() as demo:
125
  ["Examples/Town.jpeg", 42, True, 127, 25, 0.1, 3, "png", "auto"]
126
  ],
127
  inputs=[image, seed, randomize_seed, motion_bucket_id, fps_id, noise_aug_strength, decoding_t, frame_format, version],
128
- outputs=[video, gallery, seed],
129
  fn=sample,
130
  run_on_click=True,
131
  cache_examples=False,
 
55
  frames = fps14Pipe(image, decode_chunk_size=decoding_t, generator=generator, motion_bucket_id=motion_bucket_id, noise_aug_strength=noise_aug_strength, num_frames=25).frames[0]
56
  export_to_video(frames, video_path, fps=fps_id)
57
 
58
+ return video_path, gr.update(value=video_path, visible=True), gr.update(label="Generated frames in *." + frame_format + " format", format = frame_format, value = frames, visible=True), seed
59
 
60
  def resize_image(image, output_size=(1024, 576)):
61
  # Calculate aspect ratios
 
105
  noise_aug_strength = gr.Slider(label="Noise strength", info="The noise to add", value=0.1, minimum=0, maximum=1, step=0.1)
106
  decoding_t = gr.Slider(label="Decoding", info="Number of frames decoded at a time; this eats more VRAM; reduce if necessary", value=3, minimum=1, maximum=5, step=1)
107
  frame_format = gr.Radio([["*.png", "png"], ["*.webp", "webp"], ["*.jpeg", "jpeg"], ["*.gif", "gif"], ["*.bmp", "bmp"]], label="Image format for result", info="File extention", value="webp", interactive=True)
108
+ version = gr.Radio([["Auto", "auto"], ["πŸƒπŸ»β€β™€οΈ SVD (trained on 14 f/s)", "svd"], ["πŸƒπŸ»β€β™€οΈπŸ’¨ SVD-XT (trained on 25 f/s)", "svdxt"]], label="Model", info="Trained model", value="auto", interactive=True)
109
  seed = gr.Slider(label="Seed", value=42, randomize=True, minimum=0, maximum=max_64_bit_int, step=1)
110
  randomize_seed = gr.Checkbox(label="Randomize seed", value=True)
111
 
112
+ generate_btn = gr.Button(value="πŸš€ Animate", variant="primary")
113
 
114
  with gr.Column():
115
+ video = gr.Video(label="Generated video", autoplay=True)
116
+ download_button = gr.DownloadButton(label="πŸ’Ύ Download video", visible=False)
117
+ gallery = gr.Gallery(label="Generated frames", visible=False)
118
 
119
  image.upload(fn=resize_image, inputs=image, outputs=image, queue=False)
120
+ generate_btn.click(fn=sample, inputs=[image, seed, randomize_seed, motion_bucket_id, fps_id, noise_aug_strength, decoding_t, frame_format, version], outputs=[video, download_button, gallery, seed], api_name="video")
121
 
122
  gr.Examples(
123
  examples=[
 
126
  ["Examples/Town.jpeg", 42, True, 127, 25, 0.1, 3, "png", "auto"]
127
  ],
128
  inputs=[image, seed, randomize_seed, motion_bucket_id, fps_id, noise_aug_strength, decoding_t, frame_format, version],
129
+ outputs=[video, download_button, gallery, seed],
130
  fn=sample,
131
  run_on_click=True,
132
  cache_examples=False,