Spaces:
Build error
Build error
| import torch | |
| from PIL import Image | |
| import imageio | |
| from diffusers import StableVideoDiffusionPipeline | |
| import gradio as gr | |
| # Load the pipeline | |
| pipe = StableVideoDiffusionPipeline.from_pretrained( | |
| "stabilityai/stable-video-diffusion-img2vid-xt", torch_dtype=torch.float16, variant="fp16" | |
| ) | |
| pipe.enable_model_cpu_offload() | |
| def generate_video(image, seed=42, fps=7): | |
| # Resize the image | |
| image = image.resize((1024, 576)) | |
| # Set the generator seed | |
| generator = torch.manual_seed(seed) | |
| # Generate the frames | |
| frames = pipe(image, decode_chunk_size=8, generator=generator).frames[0] | |
| # Export the frames to a video | |
| output_path = "generated.mp4" | |
| imageio.mimwrite(output_path, frames, fps=fps) | |
| return output_path | |
| # Create the Gradio interface | |
| iface = gr.Interface( | |
| fn=generate_video, | |
| inputs=[ | |
| gr.Image(type="pil", label="Upload Image"), | |
| gr.Number(label="Seed", value=42), | |
| gr.Number(label="FPS", value=7) | |
| ], | |
| outputs=gr.Video(label="Generated Video"), | |
| title="Stable Video Diffusion", | |
| description="Generate a video from an uploaded image using Stable Video Diffusion." | |
| ) | |
| # Launch the interface | |
| iface.launch() | |