Spaces:
Runtime error
Runtime error
Download app.py from RustyPan90/aivideo: direct link, hf CLI and curl.
- Browser
- Download file 1.28 kB
-
https://huggingface.co/spaces/RustyPan90/aivideo/resolve/main/app.py
- Command line
-
hf download hf://spaces/RustyPan90/aivideo/app.py
-
curl -L -o app.py https://huggingface.co/spaces/RustyPan90/aivideo/resolve/main/app.py
1.28 kB
| import gradio as gr | |
| import torch | |
| from diffusers import StableVideoDiffusionPipeline | |
| from diffusers.utils import export_to_video | |
| from PIL import Image | |
| # Load the model on CPU | |
| pipe = StableVideoDiffusionPipeline.from_pretrained( | |
| "stabilityai/stable-video-diffusion-img2vid-xt", | |
| torch_dtype=torch.float32 # Use float32 for CPU compatibility | |
| ) | |
| # Removed pipe.enable_model_cpu_offload() as it requires a GPU accelerator | |
| def generate_video(image_file): | |
| # Process the uploaded image | |
| image = Image.open(image_file.name).convert("RGB") | |
| image = image.resize((1024, 576)) | |
| # Generate the frames | |
| # Note: On CPU, this process will take significantly longer | |
| frames = pipe(image, decode_chunk_size=8, generator=torch.manual_seed(42)).frames[0] | |
| # Save frames as a video | |
| video_path = "output.mp4" | |
| export_to_video(frames, video_path, fps=7) | |
| return video_path | |
| # UI Layout | |
| with gr.Blocks() as demo: | |
| gr.Markdown("# Rustyemini AI - Video Studio") | |
| with gr.Row(): | |
| input_image = gr.Image(label="Upload an Image to animate", type="file") | |
| output_video = gr.Video(label="Generated Video") | |
| btn = gr.Button("Generate Video") | |
| btn.click(fn=generate_video, inputs=input_image, outputs=output_video) | |
| demo.launch() |