salomonsky commited on
Commit
b9c9676
·
verified ·
1 Parent(s): 8ae0bf1

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +18 -9
app.py CHANGED
@@ -51,12 +51,14 @@ def demo():
51
  with gr.Row():
52
  with gr.Column():
53
  image = gr.Image(label="Upload your image", type="pil")
 
 
54
  with gr.Accordion("Advanced options", open=False):
55
  seed = gr.Slider(label="Seed", value=42, randomize=True, minimum=0, maximum=max_64_bit_int, step=1)
56
  randomize_seed = gr.Checkbox(label="Randomize seed", value=True)
57
  motion_bucket_id = gr.Slider(label="Motion bucket id", info="Controls how much motion to add/remove from the image", value=127, minimum=1, maximum=255)
58
  fps_id = gr.Slider(label="Frames per second", info="The length of your video in seconds will be 25/fps", value=6, minimum=5, maximum=30)
59
- generate_btn = gr.Button(value="Animate", variant="primary")
60
  with gr.Column():
61
  video = gr.Video(label="Generated video")
62
  gallery = gr.Gallery(label="Generated frames")
@@ -64,10 +66,13 @@ def demo():
64
  progress = gr.Progress()
65
 
66
 
67
- def resize_and_animate(image, progress, seed, randomize_seed, motion_bucket_id, fps_id):
68
- image = resize_image(image)
69
- if image.mode == "RGBA":
70
- image = image.convert("RGB")
 
 
 
71
 
72
  if(randomize_seed):
73
  seed = random.randint(0, max_64_bit_int)
@@ -79,7 +84,7 @@ def demo():
79
 
80
  frames = []
81
  for i in range(25):
82
- frame = pipe(image, decode_chunk_size=3, generator=generator, motion_bucket_id=motion_bucket_id, noise_aug_strength=0.1, num_frames=1).frames[0]
83
  frames.extend(frame)
84
  progress.update((i+1)/25)
85
 
@@ -89,10 +94,14 @@ def demo():
89
  return video_path, frames, seed
90
 
91
 
92
- image.upload(fn=resize_image, inputs=image, outputs=image, queue=False)
 
 
 
 
93
  generate_btn.click(
94
- fn=resize_and_animate,
95
- inputs=[image, progress, seed, randomize_seed, motion_bucket_id, fps_id],
96
  outputs=[video, gallery, progress],
97
  )
98
 
 
51
  with gr.Row():
52
  with gr.Column():
53
  image = gr.Image(label="Upload your image", type="pil")
54
+ resize_btn = gr.Button("Resize image")
55
+ resized_image = gr.Image(label="Resized image")
56
  with gr.Accordion("Advanced options", open=False):
57
  seed = gr.Slider(label="Seed", value=42, randomize=True, minimum=0, maximum=max_64_bit_int, step=1)
58
  randomize_seed = gr.Checkbox(label="Randomize seed", value=True)
59
  motion_bucket_id = gr.Slider(label="Motion bucket id", info="Controls how much motion to add/remove from the image", value=127, minimum=1, maximum=255)
60
  fps_id = gr.Slider(label="Frames per second", info="The length of your video in seconds will be 25/fps", value=6, minimum=5, maximum=30)
61
+ generate_btn = gr.Button("Animate")
62
  with gr.Column():
63
  video = gr.Video(label="Generated video")
64
  gallery = gr.Gallery(label="Generated frames")
 
66
  progress = gr.Progress()
67
 
68
 
69
+ def resize(image):
70
+ return resize_image(image)
71
+
72
+
73
+ def animate(resized_image, progress, seed, randomize_seed, motion_bucket_id, fps_id):
74
+ if resized_image.mode == "RGBA":
75
+ resized_image = resized_image.convert("RGB")
76
 
77
  if(randomize_seed):
78
  seed = random.randint(0, max_64_bit_int)
 
84
 
85
  frames = []
86
  for i in range(25):
87
+ frame = pipe(resized_image, decode_chunk_size=3, generator=generator, motion_bucket_id=motion_bucket_id, noise_aug_strength=0.1, num_frames=1).frames[0]
88
  frames.extend(frame)
89
  progress.update((i+1)/25)
90
 
 
94
  return video_path, frames, seed
95
 
96
 
97
+ resize_btn.click(
98
+ fn=resize,
99
+ inputs=image,
100
+ outputs=resized_image,
101
+ )
102
  generate_btn.click(
103
+ fn=animate,
104
+ inputs=[resized_image, progress, seed, randomize_seed, motion_bucket_id, fps_id],
105
  outputs=[video, gallery, progress],
106
  )
107