ManuelHuman commited on
Commit
9857823
·
verified ·
1 Parent(s): dd5573c

Create app.py

Browse files
Files changed (1) hide show
  1. app.py +23 -0
app.py ADDED
@@ -0,0 +1,23 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import streamlit as st
2
+ import torch
3
+ from diffusers import AutoencoderKLWan, WanPipeline
4
+ from diffusers.utils import export_to_video
5
+
6
+ # Load the Wan2.1 text-to-video pipeline (1.3B version) with half precision weights
7
+ model_id = "Wan-AI/Wan2.1-T2V-1.3B-Diffusers"
8
+ st.write("Downloading and loading model... (first run may take a few minutes)")
9
+ vae = AutoencoderKLWan.from_pretrained(model_id, subfolder="vae", torch_dtype=torch.float16)
10
+ pipe = WanPipeline.from_pretrained(model_id, vae=vae, torch_dtype=torch.float16)
11
+ # (By default, the pipeline is on CPU since no .to("cuda") is called)
12
+
13
+ st.title("Wan2.1 Text-to-Video Generator")
14
+ prompt = st.text_input("Enter a text prompt for the video:")
15
+ frames = st.slider("Number of frames (video length)", min_value=8, max_value=81, value=24)
16
+ if st.button("Generate Video") and prompt:
17
+ with st.spinner("Generating video... this may take a while on CPU"):
18
+ # Run the pipeline to generate video frames
19
+ result = pipe(prompt=prompt, height=480, width=832, num_frames=frames, num_inference_steps=20)
20
+ video_frames = result.frames # list of PIL images
21
+ # Save frames as video file
22
+ export_to_video(video_frames, "output.mp4", fps=8) # using a lower FPS for a short video
23
+ st.video("output.mp4")