Spaces:
Running
Running
Upload 2 files
Browse files- app.py +44 -0
- requirements.txt +6 -0
app.py
ADDED
|
@@ -0,0 +1,44 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import streamlit as st
|
| 2 |
+
import torch
|
| 3 |
+
from diffusers import DiffusionPipeline
|
| 4 |
+
import imageio
|
| 5 |
+
from io import BytesIO
|
| 6 |
+
from PIL import Image
|
| 7 |
+
|
| 8 |
+
# Title of the app
|
| 9 |
+
st.title("Text-to-Video Generator")
|
| 10 |
+
|
| 11 |
+
# Load the model (only once when the app starts)
|
| 12 |
+
@st.cache_resource
|
| 13 |
+
def load_model():
|
| 14 |
+
pipe = DiffusionPipeline.from_pretrained("cerspense/zeroscope_v2_576w", torch_dtype=torch.float16)
|
| 15 |
+
pipe.enable_model_cpu_offload()
|
| 16 |
+
pipe.unet.enable_forward_chunking(chunk_size=1, dim=1)
|
| 17 |
+
pipe.enable_vae_slicing()
|
| 18 |
+
return pipe
|
| 19 |
+
|
| 20 |
+
pipe = load_model()
|
| 21 |
+
|
| 22 |
+
# Text input for the prompt
|
| 23 |
+
prompt = st.text_input("Enter a text prompt for the video")
|
| 24 |
+
|
| 25 |
+
# If a prompt is entered, generate the video
|
| 26 |
+
if prompt:
|
| 27 |
+
st.write("Generating video... please wait.")
|
| 28 |
+
|
| 29 |
+
# Generate video frames
|
| 30 |
+
video_frames = pipe(prompt, num_frames=24).frames[0]
|
| 31 |
+
|
| 32 |
+
# Save video to in-memory buffer
|
| 33 |
+
video_buffer = BytesIO()
|
| 34 |
+
with imageio.get_writer(video_buffer, fps=10, format="mp4") as writer:
|
| 35 |
+
for frame in video_frames:
|
| 36 |
+
writer.append_data(frame)
|
| 37 |
+
|
| 38 |
+
video_buffer.seek(0)
|
| 39 |
+
|
| 40 |
+
# Display the video
|
| 41 |
+
st.video(video_buffer, format="video/mp4")
|
| 42 |
+
|
| 43 |
+
# Optional: Allow users to download the video
|
| 44 |
+
st.download_button(label="Download Video", data=video_buffer, file_name="generated_video.mp4", mime="video/mp4")
|
requirements.txt
ADDED
|
@@ -0,0 +1,6 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
streamlit
|
| 2 |
+
diffusers
|
| 3 |
+
transformers
|
| 4 |
+
accelerate
|
| 5 |
+
torch
|
| 6 |
+
imageio[ffmpeg]
|