Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
|
@@ -3,10 +3,25 @@ from diffusers import DiffusionPipeline, DPMSolverMultistepScheduler
|
|
| 3 |
from diffusers.utils import export_to_video
|
| 4 |
import streamlit as st
|
| 5 |
|
| 6 |
-
|
| 7 |
-
|
| 8 |
-
|
| 9 |
|
| 10 |
-
|
| 11 |
-
|
| 12 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 3 |
from diffusers.utils import export_to_video
|
| 4 |
import streamlit as st
|
| 5 |
|
| 6 |
+
# Title and User Input
|
| 7 |
+
st.title("Text-to-Video with Streamlit")
|
| 8 |
+
prompt = st.text_input("Enter your text prompt:", "Spiderman is surfing")
|
| 9 |
|
| 10 |
+
# Button to trigger generation
|
| 11 |
+
if st.button("Generate Video"):
|
| 12 |
+
|
| 13 |
+
# Ensure you have 'accelerate' version 0.17.0 or higher (see previous explanation)
|
| 14 |
+
import accelerate
|
| 15 |
+
if accelerate.__version__ < "0.17.0":
|
| 16 |
+
st.warning("Please upgrade 'accelerate' to version 0.17.0 or higher for CPU offloading.")
|
| 17 |
+
else:
|
| 18 |
+
with st.spinner("Generating video..."):
|
| 19 |
+
pipe = DiffusionPipeline.from_pretrained("damo-vilab/text-to-video-ms-1.7b", torch_dtype=torch.float16, variant="fp16")
|
| 20 |
+
pipe.scheduler = DPMSolverMultistepScheduler.from_config(pipe.scheduler.config)
|
| 21 |
+
pipe.enable_model_cpu_offload() # Assuming 'accelerate' is updated
|
| 22 |
+
|
| 23 |
+
video_frames = pipe(prompt, num_inference_steps=25).frames
|
| 24 |
+
video_path = export_to_video(video_frames)
|
| 25 |
+
|
| 26 |
+
# Display the video in the Streamlit app
|
| 27 |
+
st.video(video_path)
|