import streamlit as st import torch from diffusers import AutoencoderKLWan, WanPipeline from diffusers.utils import export_to_video # Load the Wan2.1 text-to-video pipeline (1.3B version) with half precision weights model_id = "Wan-AI/Wan2.1-T2V-1.3B-Diffusers" st.write("Downloading and loading model... (first run may take a few minutes)") vae = AutoencoderKLWan.from_pretrained(model_id, subfolder="vae", torch_dtype=torch.float16) pipe = WanPipeline.from_pretrained(model_id, vae=vae, torch_dtype=torch.float16) # (By default, the pipeline is on CPU since no .to("cuda") is called) st.title("Wan2.1 Text-to-Video Generator") prompt = st.text_input("Enter a text prompt for the video:") frames = st.slider("Number of frames (video length)", min_value=8, max_value=81, value=24) if st.button("Generate Video") and prompt: with st.spinner("Generating video... this may take a while on CPU"): # Run the pipeline to generate video frames result = pipe(prompt=prompt, height=480, width=832, num_frames=frames, num_inference_steps=20) video_frames = result.frames # list of PIL images # Save frames as video file export_to_video(video_frames, "output.mp4", fps=8) # using a lower FPS for a short video st.video("output.mp4")