xi0v Fabrice-TIERCELIN commited on
Commit
4bafb5e
β€’
1 Parent(s): cbd363e

Make the introduction understandable by large public (and change video formats) (#23)

Browse files

- Make the introduction understandable by large public (and change video formats) (cefb3322111530d555dba8d76990a865e9521b7a)


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

Files changed (1) hide show
  1. app.py +21 -8
app.py CHANGED
@@ -44,6 +44,12 @@ def animate(
44
 
45
  if randomize_seed:
46
  seed = random.randint(0, max_64_bit_int)
 
 
 
 
 
 
47
 
48
  frames = animate_on_gpu(
49
  image,
@@ -83,11 +89,11 @@ def animate_on_gpu(
83
  fps_id: int = 6,
84
  noise_aug_strength: float = 0.1,
85
  decoding_t: int = 3,
86
- version: str = "auto"
87
  ):
88
  generator = torch.manual_seed(seed)
89
-
90
- if version == "svdxt" or (14 < fps_id and version != "svd"):
91
  return fps25Pipe(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]
92
  else:
93
  return 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]
@@ -129,9 +135,16 @@ def resize_image(image, output_size=(1024, 576)):
129
  return cropped_image
130
 
131
  with gr.Blocks() as demo:
132
- gr.Markdown('''# Community demo for Stable Video Diffusion - Img2Vid - XT ([model](https://huggingface.co/stabilityai/stable-video-diffusion-img2vid-xt), [paper](https://stability.ai/research/stable-video-diffusion-scaling-latent-video-diffusion-models-to-large-datasets), [stability's ui waitlist](https://stability.ai/contact))
133
- #### Research release ([_non-commercial_](https://huggingface.co/stabilityai/stable-video-diffusion-img2vid-xt/blob/main/LICENSE)): generate `4s` vid from a single image at (`25 frames` at `6 fps`). this demo uses [🧨 diffusers for low VRAM and fast generation](https://huggingface.co/docs/diffusers/main/en/using-diffusers/svd).
134
- ''')
 
 
 
 
 
 
 
135
  with gr.Row():
136
  with gr.Column():
137
  image = gr.Image(label="Upload your image", type="pil")
@@ -140,8 +153,8 @@ with gr.Blocks() as demo:
140
  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)
141
  noise_aug_strength = gr.Slider(label="Noise strength", info="The noise to add", value=0.1, minimum=0, maximum=1, step=0.1)
142
  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)
143
- video_format = gr.Radio([["*.mp4", "mp4"], ["*.avi", "avi"]], label="Video format for result", info="File extention", value="mp4", interactive=True)
144
- frame_format = gr.Radio([["*.png", "png"], ["*.webp", "webp"], ["*.jpeg", "jpeg"], ["*.gif", "gif"], ["*.bmp", "bmp"]], label="Image format for frames", info="File extention", value="webp", interactive=True)
145
  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)
146
  seed = gr.Slider(label="Seed", value=42, randomize=True, minimum=0, maximum=max_64_bit_int, step=1)
147
  randomize_seed = gr.Checkbox(label="Randomize seed", value=True)
 
44
 
45
  if randomize_seed:
46
  seed = random.randint(0, max_64_bit_int)
47
+
48
+ if version == "auto"):
49
+ if 14 < fps_id:
50
+ version = "svdxt"
51
+ else:
52
+ version = "svd"
53
 
54
  frames = animate_on_gpu(
55
  image,
 
89
  fps_id: int = 6,
90
  noise_aug_strength: float = 0.1,
91
  decoding_t: int = 3,
92
+ version: str = "svdxt"
93
  ):
94
  generator = torch.manual_seed(seed)
95
+
96
+ if version == "svdxt":
97
  return fps25Pipe(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]
98
  else:
99
  return 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]
 
135
  return cropped_image
136
 
137
  with gr.Blocks() as demo:
138
+ gr.HTML("""
139
+ <h1><center>Image-to-Video</center></h1>
140
+ <big><center>Animate your images into 25 frames of 1024x576 pixels freely, without account, without watermark and download the video</center></big>
141
+ <br/>
142
+
143
+ <p>
144
+ This demo is based on <i>Stable Video Diffusion</i> artificial intelligence.
145
+ No prompt or camera control is handled here. To control motions, rather use <i><a href="https://huggingface.co/spaces/TencentARC/MotionCtrl_SVD">MotionCtrl SVD</a></i>.
146
+ </p>
147
+ """)
148
  with gr.Row():
149
  with gr.Column():
150
  image = gr.Image(label="Upload your image", type="pil")
 
153
  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)
154
  noise_aug_strength = gr.Slider(label="Noise strength", info="The noise to add", value=0.1, minimum=0, maximum=1, step=0.1)
155
  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)
156
+ video_format = gr.Radio([["*.mp4", "mp4"], ["*.ogg", "ogg"], ["*.webm", "webm"]], label="Video format for result", info="File extention", value="mp4", interactive=True)
157
+ frame_format = gr.Radio([["*.png", "png"], ["*.webp", "webp"], ["*.jpeg", "jpeg"], ["*.gif (unanimated)", "gif"], ["*.bmp", "bmp"]], label="Image format for frames", info="File extention", value="webp", interactive=True)
158
  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)
159
  seed = gr.Slider(label="Seed", value=42, randomize=True, minimum=0, maximum=max_64_bit_int, step=1)
160
  randomize_seed = gr.Checkbox(label="Randomize seed", value=True)