Spaces:
Running
Running
Create app.py
Browse files
app.py
ADDED
@@ -0,0 +1,31 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
import gradio as gr
|
2 |
+
import torch
|
3 |
+
from diffusers import StableVideoDiffusionPipeline
|
4 |
+
from PIL import Image
|
5 |
+
import requests
|
6 |
+
from io import BytesIO
|
7 |
+
import tempfile
|
8 |
+
|
9 |
+
# Load pipeline
|
10 |
+
pipe = StableVideoDiffusionPipeline.from_pretrained(
|
11 |
+
"stabilityai/stable-video-diffusion-img2vid-xt-1-1",
|
12 |
+
torch_dtype=torch.float16,
|
13 |
+
variant="fp16"
|
14 |
+
).to("cuda")
|
15 |
+
|
16 |
+
pipe.enable_model_cpu_offload()
|
17 |
+
|
18 |
+
def generate_video(image_url):
|
19 |
+
image = Image.open(BytesIO(requests.get(image_url).content)).resize((1024, 576))
|
20 |
+
result = pipe(image, decode_chunk_size=8, generator=torch.manual_seed(42)).frames[0]
|
21 |
+
temp = tempfile.NamedTemporaryFile(suffix=".mp4", delete=False)
|
22 |
+
result.save(temp.name, fps=7)
|
23 |
+
return temp.name
|
24 |
+
|
25 |
+
demo = gr.Interface(
|
26 |
+
fn=generate_video,
|
27 |
+
inputs=gr.Text(label="Image URL"),
|
28 |
+
outputs=gr.Video()
|
29 |
+
)
|
30 |
+
|
31 |
+
demo.launch()
|