Spaces:
Running
on
Zero
Running
on
Zero
Create app.py
Browse files
app.py
ADDED
@@ -0,0 +1,38 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
import gradio as gr
|
2 |
+
from diffusers import StableVideoDiffusionPipeline
|
3 |
+
import torch
|
4 |
+
from PIL import Image
|
5 |
+
|
6 |
+
# Load the model and pipeline
|
7 |
+
model_id = "stabilityai/stable-video-diffusion-img2vid-xt"
|
8 |
+
pipe = StableVideoDiffusionPipeline.from_pretrained(model_id, torch_dtype=torch.float16)
|
9 |
+
pipe = pipe.to("cuda")
|
10 |
+
|
11 |
+
def generate_video(image, prompt):
|
12 |
+
# Convert the image to a format suitable for the model
|
13 |
+
image = Image.fromarray(image)
|
14 |
+
|
15 |
+
# Generate the video from the image and prompt
|
16 |
+
video = pipe(prompt, image, num_inference_steps=50, guidance_scale=7.5).frames
|
17 |
+
|
18 |
+
# Convert the video frames to a format suitable for Gradio
|
19 |
+
video_path = "output_video.mp4"
|
20 |
+
video[0].save(video_path, save_all=True, append_images=video[1:], duration=100, loop=0)
|
21 |
+
|
22 |
+
return video_path
|
23 |
+
|
24 |
+
# Create the Gradio interface
|
25 |
+
iface = gr.Interface(
|
26 |
+
fn=generate_video,
|
27 |
+
inputs=[
|
28 |
+
gr.Image(type="pil", label="Input Image"),
|
29 |
+
gr.Textbox(lines=2, placeholder="Enter a prompt...", label="Prompt")
|
30 |
+
],
|
31 |
+
outputs=gr.Video(label="Generated Video"),
|
32 |
+
title="Stable Video Diffusion img2vid-xt",
|
33 |
+
description="Generate a video from an image using the stabilityai/stable-video-diffusion-img2vid-xt model."
|
34 |
+
)
|
35 |
+
|
36 |
+
# Launch the interface
|
37 |
+
if __name__ == "__main__":
|
38 |
+
iface.launch()
|