Spaces:
Running
on
Zero
Running
on
Zero
Update app.py
Browse files
app.py
CHANGED
@@ -1,28 +1,43 @@
|
|
1 |
-
import gradio as gr
|
2 |
-
from transformers import pipeline
|
3 |
import torch
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
4 |
|
5 |
-
#
|
6 |
-
|
7 |
-
|
8 |
|
9 |
-
|
10 |
-
# Generate the video from the image and prompt
|
11 |
-
video = pipe(prompt, image, num_inference_steps=50, guidance_scale=7.5)
|
12 |
-
return video
|
13 |
|
14 |
# Create the Gradio interface
|
15 |
iface = gr.Interface(
|
16 |
fn=generate_video,
|
17 |
inputs=[
|
18 |
-
gr.Image(type="pil", label="
|
19 |
-
gr.
|
|
|
20 |
],
|
21 |
outputs=gr.Video(label="Generated Video"),
|
22 |
-
title="Stable Video Diffusion
|
23 |
-
description="Generate a video from an image using
|
24 |
)
|
25 |
|
26 |
# Launch the interface
|
27 |
-
|
28 |
-
iface.launch()
|
|
|
|
|
|
|
1 |
import torch
|
2 |
+
from PIL import Image
|
3 |
+
import imageio
|
4 |
+
from diffusers import StableVideoDiffusionPipeline
|
5 |
+
import gradio as gr
|
6 |
+
|
7 |
+
# Load the pipeline
|
8 |
+
pipe = StableVideoDiffusionPipeline.from_pretrained(
|
9 |
+
"stabilityai/stable-video-diffusion-img2vid-xt", torch_dtype=torch.float16, variant="fp16"
|
10 |
+
)
|
11 |
+
pipe.enable_model_cpu_offload()
|
12 |
+
|
13 |
+
def generate_video(image, seed=42, fps=7):
|
14 |
+
# Resize the image
|
15 |
+
image = image.resize((1024, 576))
|
16 |
+
|
17 |
+
# Set the generator seed
|
18 |
+
generator = torch.manual_seed(seed)
|
19 |
+
|
20 |
+
# Generate the frames
|
21 |
+
frames = pipe(image, decode_chunk_size=8, generator=generator).frames[0]
|
22 |
|
23 |
+
# Export the frames to a video
|
24 |
+
output_path = "generated.mp4"
|
25 |
+
imageio.mimwrite(output_path, frames, fps=fps)
|
26 |
|
27 |
+
return output_path
|
|
|
|
|
|
|
28 |
|
29 |
# Create the Gradio interface
|
30 |
iface = gr.Interface(
|
31 |
fn=generate_video,
|
32 |
inputs=[
|
33 |
+
gr.Image(type="pil", label="Upload Image"),
|
34 |
+
gr.Number(label="Seed", value=42),
|
35 |
+
gr.Number(label="FPS", value=7)
|
36 |
],
|
37 |
outputs=gr.Video(label="Generated Video"),
|
38 |
+
title="Stable Video Diffusion",
|
39 |
+
description="Generate a video from an uploaded image using Stable Video Diffusion."
|
40 |
)
|
41 |
|
42 |
# Launch the interface
|
43 |
+
iface.launch()
|
|