ManuelHuman commited on
Commit
23a791e
·
verified ·
1 Parent(s): ffdde5a

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +14 -8
app.py CHANGED
@@ -1,22 +1,28 @@
1
  import streamlit as st
2
  import torch
3
- from diffusers import StableVideoDiffusionPipeline
4
- from diffusers.utils import export_to_video
5
 
6
- # Load the video generation pipeline
7
  st.write("Loading model... (first run may take a few minutes)")
8
 
9
- model_id = "stabilityai/stable-video-diffusion-img2vid"
10
- pipe = StableVideoDiffusionPipeline.from_pretrained(model_id, torch_dtype=torch.float16)
 
11
 
12
  st.title("Text-to-Video Generator")
13
  prompt = st.text_input("Enter a text prompt for the video:")
14
- frames = st.slider("Number of frames (video length)", min_value=8, max_value=81, value=24)
 
15
 
16
  if st.button("Generate Video") and prompt:
17
  with st.spinner("Generating video... this may take a while on CPU"):
18
  result = pipe(prompt=prompt, num_frames=frames, num_inference_steps=20)
19
  video_frames = result.frames # List of PIL images
20
- export_to_video(video_frames, "output.mp4", fps=8)
21
 
22
- st.video("output.mp4")
 
 
 
 
 
 
1
  import streamlit as st
2
  import torch
3
+ from diffusers import DiffusionPipeline
4
+ import tempfile
5
 
6
+ # Load the text-to-video model
7
  st.write("Loading model... (first run may take a few minutes)")
8
 
9
+ model_id = "damo-vilab/text-to-video-ms-1.7b"
10
+ pipe = DiffusionPipeline.from_pretrained(model_id, torch_dtype=torch.float16)
11
+ pipe.to("cpu") # Stay on CPU since we don’t have a GPU
12
 
13
  st.title("Text-to-Video Generator")
14
  prompt = st.text_input("Enter a text prompt for the video:")
15
+
16
+ frames = st.slider("Number of frames (video length)", min_value=8, max_value=24, value=16)
17
 
18
  if st.button("Generate Video") and prompt:
19
  with st.spinner("Generating video... this may take a while on CPU"):
20
  result = pipe(prompt=prompt, num_frames=frames, num_inference_steps=20)
21
  video_frames = result.frames # List of PIL images
 
22
 
23
+ # Save frames as video file
24
+ with tempfile.NamedTemporaryFile(delete=False, suffix=".mp4") as temp_file:
25
+ video_path = temp_file.name
26
+ result.export_to_video(video_path, fps=8)
27
+
28
+ st.video(video_path)