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()