Spaces:
Runtime error
Runtime error
import gradio as gr | |
import torch | |
from diffusers import AnimateDiffPipeline, DDIMScheduler | |
from PIL import Image | |
import tempfile | |
import imageio | |
# Use a public AnimateDiff-compatible model (Realistic Vision base) | |
model_id = "SG161222/Realistic_Vision_V6.0_B1_noVAE" | |
pipe = AnimateDiffPipeline.from_pretrained(model_id, torch_dtype=torch.float16) | |
pipe.scheduler = DDIMScheduler.from_config(pipe.scheduler.config) | |
pipe = pipe.to("cuda" if torch.cuda.is_available() else "cpu") | |
def generate_video(image, prompt): | |
image = image.convert("RGB").resize((512, 512)) | |
result = pipe(prompt=prompt, image=image, num_frames=16, guidance_scale=7.5) | |
frames = result.frames | |
video_path = tempfile.NamedTemporaryFile(suffix=".mp4", delete=False).name | |
imageio.mimsave(video_path, frames, fps=8) | |
return video_path | |
gr.Interface( | |
fn=generate_video, | |
inputs=[ | |
gr.Image(type="pil", label="Upload Image"), | |
gr.Textbox(label="Describe Motion (Prompt)") | |
], | |
outputs=gr.Video(label="Generated Video"), | |
title="π Image + Prompt to Animation", | |
description="Upload a still image and describe how you want it animated!" | |
).launch() | |