Spaces:
Runtime error
Runtime error
Download app.py from sillyguy21/ai-video-maker: direct link, hf CLI and curl.
- Browser
- Download file 2.2 kB
-
https://huggingface.co/spaces/sillyguy21/ai-video-maker/resolve/main/app.py
- Command line
-
hf download hf://spaces/sillyguy21/ai-video-maker/app.py
-
curl -L -o app.py https://huggingface.co/spaces/sillyguy21/ai-video-maker/resolve/main/app.py
2.2 kB
| import os | |
| import tempfile | |
| import gradio as gr | |
| import spaces | |
| import torch | |
| from diffusers import CogVideoXPipeline | |
| from diffusers.utils import export_to_video | |
| # Actual pretrained video-generation model | |
| MODEL_ID = "zai-org/CogVideoX-2b" | |
| print("Loading Wendas AI video model...") | |
| pipe = CogVideoXPipeline.from_pretrained( | |
| MODEL_ID, | |
| torch_dtype=torch.float16 | |
| ) | |
| # ZeroGPU requires the model to be placed on CUDA at startup. | |
| pipe.to("cuda") | |
| # Memory optimizations | |
| pipe.vae.enable_slicing() | |
| pipe.vae.enable_tiling() | |
| print("Wendas AI is ready!") | |
| def generate_video(prompt, seed): | |
| if not prompt or not prompt.strip(): | |
| raise gr.Error("Please enter a video description.") | |
| try: | |
| generator = torch.Generator( | |
| device="cuda" | |
| ).manual_seed(int(seed)) | |
| with torch.inference_mode(): | |
| result = pipe( | |
| prompt=prompt, | |
| num_frames=49, | |
| height=480, | |
| width=720, | |
| num_inference_steps=30, | |
| guidance_scale=6, | |
| generator=generator | |
| ) | |
| video_frames = result.frames[0] | |
| output_path = os.path.join( | |
| tempfile.gettempdir(), | |
| "wendas_generated_video.mp4" | |
| ) | |
| export_to_video( | |
| video_frames, | |
| output_path, | |
| fps=8 | |
| ) | |
| return output_path | |
| except Exception as error: | |
| raise gr.Error(f"Video generation failed: {error}") | |
| with gr.Blocks(title="Wendas AI") as demo: | |
| gr.Markdown("# Wendas AI") | |
| gr.Markdown( | |
| "### Real AI Text-to-Video Generation\n" | |
| "Powered by CogVideoX-2B" | |
| ) | |
| prompt = gr.Textbox( | |
| label="Video prompt", | |
| placeholder="A white cat eating pizza...", | |
| lines=3 | |
| ) | |
| seed = gr.Number( | |
| label="Random seed", | |
| value=42, | |
| precision=0 | |
| ) | |
| generate = gr.Button( | |
| "Generate Video", | |
| variant="primary" | |
| ) | |
| output = gr.Video( | |
| label="Generated video" | |
| ) | |
| generate.click( | |
| fn=generate_video, | |
| inputs=[prompt, seed], | |
| outputs=output | |
| ) | |
| demo.launch() | |