Spaces:
Build error
Build error
Update app.py
Browse files
app.py
CHANGED
@@ -2,21 +2,31 @@ import gradio as gr
|
|
2 |
from diffusers import StableVideoDiffusionPipeline, EulerDiscreteScheduler
|
3 |
import torch
|
4 |
from PIL import Image
|
5 |
-
import
|
6 |
|
7 |
# Load the Stable Video Diffusion model
|
8 |
model_id = "stabilityai/stable-video-diffusion-img2vid-xt"
|
9 |
-
|
10 |
-
pipe
|
11 |
-
pipe.
|
|
|
|
|
|
|
12 |
|
13 |
-
|
14 |
-
|
15 |
-
|
16 |
-
|
17 |
-
|
18 |
-
|
19 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
20 |
|
21 |
# Create the Gradio interface
|
22 |
with gr.Blocks() as demo:
|
@@ -24,7 +34,6 @@ with gr.Blocks() as demo:
|
|
24 |
with gr.Row():
|
25 |
with gr.Column():
|
26 |
image_input = gr.Image(type="filepath", label="Upload Image")
|
27 |
-
prompt_input = gr.Textbox(lines=2, placeholder="Enter prompt...", label="Prompt")
|
28 |
num_frames_input = gr.Slider(1, 50, step=1, value=25, label="Number of Frames")
|
29 |
height_input = gr.Number(label="Resolution Height", value=576)
|
30 |
width_input = gr.Number(label="Resolution Width", value=1024)
|
@@ -34,10 +43,11 @@ with gr.Blocks() as demo:
|
|
34 |
|
35 |
run_button.click(
|
36 |
generate_video,
|
37 |
-
inputs=[image_input,
|
38 |
outputs=video_output
|
39 |
)
|
40 |
|
41 |
# Launch the interface
|
42 |
if __name__ == "__main__":
|
43 |
-
demo.launch()
|
|
|
|
2 |
from diffusers import StableVideoDiffusionPipeline, EulerDiscreteScheduler
|
3 |
import torch
|
4 |
from PIL import Image
|
5 |
+
import tempfile
|
6 |
|
7 |
# Load the Stable Video Diffusion model
|
8 |
model_id = "stabilityai/stable-video-diffusion-img2vid-xt"
|
9 |
+
try:
|
10 |
+
pipe = StableVideoDiffusionPipeline.from_pretrained(model_id, torch_dtype=torch.float16, revision="main")
|
11 |
+
pipe.scheduler = EulerDiscreteScheduler.from_config(pipe.scheduler.config)
|
12 |
+
pipe.to("cuda")
|
13 |
+
except Exception as e:
|
14 |
+
raise RuntimeError(f"Failed to load the model: {e}")
|
15 |
|
16 |
+
def generate_video(image, num_frames=25, height=576, width=1024):
|
17 |
+
try:
|
18 |
+
# Convert the image to a format suitable for the pipeline
|
19 |
+
image = Image.open(image)
|
20 |
+
# Generate the video
|
21 |
+
video_frames = pipe(image=image, num_frames=num_frames, height=height, width=width).frames
|
22 |
+
# Save the video frames to a temporary file
|
23 |
+
with tempfile.NamedTemporaryFile(delete=False, suffix=".mp4") as temp_video:
|
24 |
+
video_path = temp_video.name
|
25 |
+
# Assuming video_frames is a list of PIL images
|
26 |
+
video_frames[0].save(video_path, save_all=True, append_images=video_frames[1:], duration=100, loop=0)
|
27 |
+
return video_path
|
28 |
+
except Exception as e:
|
29 |
+
raise RuntimeError(f"Failed to generate the video: {e}")
|
30 |
|
31 |
# Create the Gradio interface
|
32 |
with gr.Blocks() as demo:
|
|
|
34 |
with gr.Row():
|
35 |
with gr.Column():
|
36 |
image_input = gr.Image(type="filepath", label="Upload Image")
|
|
|
37 |
num_frames_input = gr.Slider(1, 50, step=1, value=25, label="Number of Frames")
|
38 |
height_input = gr.Number(label="Resolution Height", value=576)
|
39 |
width_input = gr.Number(label="Resolution Width", value=1024)
|
|
|
43 |
|
44 |
run_button.click(
|
45 |
generate_video,
|
46 |
+
inputs=[image_input, num_frames_input, height_input, width_input],
|
47 |
outputs=video_output
|
48 |
)
|
49 |
|
50 |
# Launch the interface
|
51 |
if __name__ == "__main__":
|
52 |
+
demo.launch()
|
53 |
+
|