Fix the space: Video component needs a path, not frames
Browse files
app.py
CHANGED
|
@@ -1,6 +1,8 @@
|
|
| 1 |
import gradio as gr
|
| 2 |
from diffusers import DiffusionPipeline
|
|
|
|
| 3 |
import torch
|
|
|
|
| 4 |
from PIL import Image
|
| 5 |
import spaces
|
| 6 |
|
|
@@ -26,11 +28,17 @@ def generate_video(image):
|
|
| 26 |
image: A PIL Image object representing the input image.
|
| 27 |
|
| 28 |
Returns:
|
| 29 |
-
|
| 30 |
"""
|
| 31 |
video_frames = pipeline(image=image, num_inference_steps=20).images
|
| 32 |
|
| 33 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 34 |
|
| 35 |
# Launch the Gradio app
|
| 36 |
interface.launch()
|
|
|
|
| 1 |
import gradio as gr
|
| 2 |
from diffusers import DiffusionPipeline
|
| 3 |
+
from diffusers.utils import export_to_video
|
| 4 |
import torch
|
| 5 |
+
import os
|
| 6 |
from PIL import Image
|
| 7 |
import spaces
|
| 8 |
|
|
|
|
| 28 |
image: A PIL Image object representing the input image.
|
| 29 |
|
| 30 |
Returns:
|
| 31 |
+
The path of a video file.
|
| 32 |
"""
|
| 33 |
video_frames = pipeline(image=image, num_inference_steps=20).images
|
| 34 |
|
| 35 |
+
# Frames to Video
|
| 36 |
+
os.makedirs("outputs", exist_ok=True)
|
| 37 |
+
base_count = len(glob(os.path.join("outputs", "*.mp4")))
|
| 38 |
+
video_path = os.path.join("outputs", f"{base_count:06d}.mp4")
|
| 39 |
+
export_to_video(video_frames, video_path, fps=6)
|
| 40 |
+
|
| 41 |
+
return video_path
|
| 42 |
|
| 43 |
# Launch the Gradio app
|
| 44 |
interface.launch()
|