prompts = [
"Time-lapse of clouds moving over mountain peaks, dramatic lighting",
"Ocean waves crashing on rocks, slow motion, cinematic",
"Northern lights dancing in the night sky, vibrant colors",
"Forest in autumn with leaves falling, peaceful atmosphere"
]
prompts = [
"A golden retriever running through a field of flowers",
"A butterfly emerging from its cocoon, macro shot",
"Samurai warrior drawing sword, dramatic lighting",
"Robot walking through futuristic city streets"
]
prompts = [
"Colorful paint swirling in water, abstract art",
"Geometric shapes transforming and morphing, neon colors",
"Ink drops spreading in milk, macro photography"
]
import os
import torch
from diffusers import WanPipeline
from diffusers.utils import export_to_video
pipe = WanPipeline.from_pretrained("alibaba-pai/Wan2.1-T2V-1.3B", torch_dtype=torch.float16)
pipe.to("cuda")
pipe.enable_model_cpu_offload()
prompts = [
"A rocket launching into space",
"Fish swimming in coral reef",
"Rain falling on a city street at night"
]
output_dir = "./videos"
os.makedirs(output_dir, exist_ok=True)
for i, prompt in enumerate(prompts):
print(f"Generating {i+1}/{len(prompts)}: {prompt[:40]}...")
output = pipe(
prompt=prompt,
num_frames=49,
num_inference_steps=50
)
export_to_video(output.frames[0], f"{output_dir}/video_{i:03d}.mp4", fps=16)
torch.cuda.empty_cache()
import gradio as gr
import torch
from diffusers import WanPipeline
from diffusers.utils import export_to_video
import tempfile
pipe = WanPipeline.from_pretrained("alibaba-pai/Wan2.1-T2V-1.3B", torch_dtype=torch.float16)
pipe.to("cuda")
pipe.enable_model_cpu_offload()
def generate_video(prompt, negative_prompt, frames, steps, guidance, seed):
generator = torch.Generator("cuda").manual_seed(seed) if seed > 0 else None
output = pipe(
prompt=prompt,
negative_prompt=negative_prompt,
num_frames=frames,
num_inference_steps=steps,
guidance_scale=guidance,
generator=generator
)
with tempfile.NamedTemporaryFile(suffix=".mp4", delete=False) as f:
export_to_video(output.frames[0], f.name, fps=16)
return f.name
demo = gr.Interface(
fn=generate_video,
inputs=[
gr.Textbox(label="Prompt", lines=2),
gr.Textbox(label="Negative Prompt", value="blurry, low quality"),
gr.Slider(17, 81, value=49, step=8, label="Frames"),
gr.Slider(20, 100, value=50, step=5, label="Steps"),
gr.Slider(3, 12, value=7, step=0.5, label="Guidance"),
gr.Number(value=-1, label="Seed")
],
outputs=gr.Video(label="Generated Video"),
title="Wan2.1 - Text to Video Generation",
description="Generate videos from text prompts. Running on CLORE.AI."
)
demo.launch(server_name="0.0.0.0", server_port=7860)
# Enable all optimizations
pipe.enable_model_cpu_offload()
pipe.enable_vae_tiling()
pipe.enable_vae_slicing()
# For very low VRAM
pipe.enable_sequential_cpu_offload()
# Clear cache between generations
torch.cuda.empty_cache()
# Use smaller model
pipe = WanPipeline.from_pretrained("alibaba-pai/Wan2.1-T2V-1.3B")
# Enable all optimizations
pipe.enable_model_cpu_offload()
pipe.enable_vae_tiling()
# Reduce frames
output = pipe(prompt, num_frames=17)
# Reduce resolution
output = pipe(prompt, height=480, width=854)