Spaces:
Runtime error
Runtime error
Create app.py
Browse files
app.py
ADDED
@@ -0,0 +1,32 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
import gradio as gr
|
2 |
+
import torch
|
3 |
+
from diffusers import AnimateDiffPipeline, DDIMScheduler
|
4 |
+
from PIL import Image
|
5 |
+
import tempfile
|
6 |
+
import imageio
|
7 |
+
|
8 |
+
# Use a public AnimateDiff-compatible model (Realistic Vision base)
|
9 |
+
model_id = "SG161222/Realistic_Vision_V6.0_B1_noVAE"
|
10 |
+
pipe = AnimateDiffPipeline.from_pretrained(model_id, torch_dtype=torch.float16)
|
11 |
+
pipe.scheduler = DDIMScheduler.from_config(pipe.scheduler.config)
|
12 |
+
pipe = pipe.to("cuda" if torch.cuda.is_available() else "cpu")
|
13 |
+
|
14 |
+
def generate_video(image, prompt):
|
15 |
+
image = image.convert("RGB").resize((512, 512))
|
16 |
+
result = pipe(prompt=prompt, image=image, num_frames=16, guidance_scale=7.5)
|
17 |
+
frames = result.frames
|
18 |
+
|
19 |
+
video_path = tempfile.NamedTemporaryFile(suffix=".mp4", delete=False).name
|
20 |
+
imageio.mimsave(video_path, frames, fps=8)
|
21 |
+
return video_path
|
22 |
+
|
23 |
+
gr.Interface(
|
24 |
+
fn=generate_video,
|
25 |
+
inputs=[
|
26 |
+
gr.Image(type="pil", label="Upload Image"),
|
27 |
+
gr.Textbox(label="Describe Motion (Prompt)")
|
28 |
+
],
|
29 |
+
outputs=gr.Video(label="Generated Video"),
|
30 |
+
title="🌀 Image + Prompt to Animation",
|
31 |
+
description="Upload a still image and describe how you want it animated!"
|
32 |
+
).launch()
|