Spaces:
Running
Running
import gradio as gr | |
from moviepy.editor import ImageSequenceClip | |
import tempfile | |
import os | |
def images_to_video(image_files): | |
# μμ λλ ν°λ¦¬ μμ± | |
temp_dir = tempfile.mkdtemp() | |
# μ΄λ―Έμ§ νμΌμ μμ λλ ν°λ¦¬λ‘ μ μ₯ | |
image_paths = [] | |
for i, image_file in enumerate(image_files): | |
image_path = os.path.join(temp_dir, f"image_{i}.png") | |
with open(image_path, "wb") as f: | |
f.write(image_file) | |
image_paths.append(image_path) | |
# μ΄λ―Έμ§ μνμ€λ‘λΆν° λΉλμ€ ν΄λ¦½ μμ± (κ° μ΄λ―Έμ§μ μ§μ μκ°μ 2μ΄) | |
clip = ImageSequenceClip(image_paths, fps=0.5) # fps=0.5 => κ° μ΄λ―Έμ§λ 2μ΄ λμ 보μ | |
# λΉλμ€ νμΌ μ μ₯ | |
output_video_path = os.path.join(temp_dir, "output.mp4") | |
clip.write_videofile(output_video_path, fps=24) # 24fpsλ‘ μΆλ ₯ λΉλμ€ μ μ₯ | |
# μμ±λ λΉλμ€ νμΌ κ²½λ‘ λ°ν | |
return output_video_path | |
# Gradio μΈν°νμ΄μ€ μ μ | |
with gr.Blocks() as demo: | |
with gr.Row(): | |
file_input = gr.File(label="Upload images") | |
video_output = gr.Video(label="Output video") | |
file_input.change(images_to_video, inputs=file_input, outputs=video_output) | |
demo.launch() | |