testingwan / app.py
ManuelHuman's picture
Update app.py
d33c9ef verified
raw
history blame
910 Bytes
import streamlit as st
import torch
from diffusers import StableVideoDiffusionPipeline
from diffusers.utils import export_to_video
# Load the video generation pipeline
st.write("Loading model... (first run may take a few minutes)")
model_id = "stabilityai/stable-video-diffusion-img2vid"
pipe = StableVideoDiffusionPipeline.from_pretrained(model_id, torch_dtype=torch.float16)
st.title("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, 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")