|
import gradio as gr |
|
from diffusers import DiffusionPipeline |
|
import torch |
|
from PIL import Image |
|
import spaces |
|
|
|
|
|
pipeline = DiffusionPipeline.from_pretrained("stabilityai/stable-video-diffusion-img2vid-xt-1-1") |
|
|
|
|
|
interface = gr.Interface( |
|
fn=lambda img: generate_video(img), |
|
inputs=gr.Image(type="pil"), |
|
outputs=gr.Video(), |
|
title="Stable Video Diffusion", |
|
description="Upload an image to generate a video", |
|
theme="soft" |
|
) |
|
|
|
|
|
def generate_video(img): |
|
|
|
img_tensor = torch.tensor(img).unsqueeze(0) / 255.0 |
|
|
|
|
|
output = pipeline(img_tensor) |
|
|
|
|
|
video_frames = output["video_frames"] |
|
|
|
|
|
video = [] |
|
for frame in video_frames: |
|
video.append(Image.fromarray(frame.detach().cpu().numpy())) |
|
|
|
|
|
return video |
|
|
|
|
|
interface.launch() |