mrcuddle commited on
Commit
e8c645c
·
verified ·
1 Parent(s): 8ed9a30

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +5 -6
app.py CHANGED
@@ -3,7 +3,8 @@ from diffusers import StableVideoDiffusionPipeline, EulerDiscreteScheduler
3
  import torch
4
  from PIL import Image
5
  import tempfile
6
- import spaces
 
7
  # Load the Stable Video Diffusion model
8
  model_id = "stabilityai/stable-video-diffusion-img2vid-xt"
9
  try:
@@ -13,7 +14,6 @@ try:
13
  except Exception as e:
14
  raise RuntimeError(f"Failed to load the model: {e}")
15
 
16
- @spaces.GPU(duration=300)
17
  def generate_video(image, num_frames=25, height=576, width=1024):
18
  try:
19
  # Convert the image to a format suitable for the pipeline
@@ -23,8 +23,8 @@ def generate_video(image, num_frames=25, height=576, width=1024):
23
  # Save the video frames to a temporary file
24
  with tempfile.NamedTemporaryFile(delete=False, suffix=".mp4") as temp_video:
25
  video_path = temp_video.name
26
- # Assuming video_frames is a list of PIL images
27
- video_frames[0].save(video_path, save_all=True, append_images=video_frames[1:], duration=100, loop=0)
28
  return video_path
29
  except Exception as e:
30
  raise RuntimeError(f"Failed to generate the video: {e}")
@@ -50,5 +50,4 @@ with gr.Blocks() as demo:
50
 
51
  # Launch the interface
52
  if __name__ == "__main__":
53
- demo.launch()
54
-
 
3
  import torch
4
  from PIL import Image
5
  import tempfile
6
+ import imageio
7
+
8
  # Load the Stable Video Diffusion model
9
  model_id = "stabilityai/stable-video-diffusion-img2vid-xt"
10
  try:
 
14
  except Exception as e:
15
  raise RuntimeError(f"Failed to load the model: {e}")
16
 
 
17
  def generate_video(image, num_frames=25, height=576, width=1024):
18
  try:
19
  # Convert the image to a format suitable for the pipeline
 
23
  # Save the video frames to a temporary file
24
  with tempfile.NamedTemporaryFile(delete=False, suffix=".mp4") as temp_video:
25
  video_path = temp_video.name
26
+ # Save the frames as a video using imageio
27
+ imageio.mimsave(video_path, video_frames, fps=30)
28
  return video_path
29
  except Exception as e:
30
  raise RuntimeError(f"Failed to generate the video: {e}")
 
50
 
51
  # Launch the interface
52
  if __name__ == "__main__":
53
+ demo.launch()