File size: 910 Bytes
9857823
 
d33c9ef
9857823
 
d33c9ef
7425484
 
d33c9ef
 
9857823
d33c9ef
9857823
 
7425484
9857823
 
d33c9ef
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 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")