File size: 943 Bytes
9857823
 
7425484
9857823
 
7425484
 
 
9857823
7425484
9857823
 
 
 
7425484
9857823
 
 
7425484
 
 
9857823
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
import streamlit as st
import torch
from diffusers import WanPipeline
from diffusers.utils import export_to_video

# Load the Wan2.1 text-to-video pipeline (1.3B version) with half-precision weights
st.write("Loading model... (first run may take a few minutes)")

model_id = "Wan-AI/Wan2.1-T2V-1.3B-Diffusers"
pipe = WanPipeline.from_pretrained(model_id, torch_dtype=torch.float16)

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"):
        result = pipe(prompt=prompt, height=480, width=832, num_frames=frames, num_inference_steps=20)
        video_frames = result.frames  # List of PIL images
        export_to_video(video_frames, "output.mp4", fps=8)

    st.video("output.mp4")