Nikhil0987 commited on
Commit
b3d2770
1 Parent(s): 89020ae

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +21 -6
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
- pipe = DiffusionPipeline.from_pretrained("damo-vilab/text-to-video-ms-1.7b", torch_dtype=torch.float16, variant="fp16")
7
- pipe.scheduler = DPMSolverMultistepScheduler.from_config(pipe.scheduler.config)
8
- pipe.enable_model_cpu_offload()
9
 
10
- prompt = "Spiderman is surfing"
11
- video_frames = pipe(prompt, num_inference_steps=25).frames
12
- video_path = export_to_video(video_frames)
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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)