File size: 1,122 Bytes
9ef21f1
9e806af
 
9ef21f1
9e806af
9ef21f1
 
9e806af
9ef21f1
9e806af
fe80cd3
9e806af
 
 
 
 
 
f81fa21
9e806af
f81fa21
9e806af
f81fa21
fe80cd3
9e806af
 
 
f81fa21
fe80cd3
9e806af
fe80cd3
 
f81fa21
fe80cd3
f81fa21
fe80cd3
 
9e806af
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
import streamlit as st
from diffusers import DiffusionPipeline
import torch
from moviepy.editor import *
import numpy as np
import tempfile, os

st.title("🚀 Text-to-Video (Zeroscope)")

@st.cache_resource
def load_model():
    pipe = DiffusionPipeline.from_pretrained(
        "cerspense/zeroscope_v2_576w", 
        torch_dtype=torch.float16
    )
    pipe.enable_cpu_offload()
    return pipe

pipe = load_model()

prompt = st.text_area("Enter prompt (short & descriptive):", max_chars=50)

if st.button("Generate Video"):
    if prompt:
        with st.spinner("Generating... (this may take ~2-3 mins)"):
            video_frames = pipe(prompt, num_frames=10, height=320, width=576).frames

            video_filename = tempfile.mktemp(".mp4")
            clips = [ImageClip(np.array(frame)).set_duration(0.3) for frame in video_frames]
            final_clip = concatenate_videoclips(clips, method="compose")
            final_clip.write_videofile(video_filename, fps=5)

            st.video(video_filename)

            os.remove(video_filename)
    else:
        st.warning("Enter a prompt to generate a video.")