import gradio as gr from moviepy.editor import ImageSequenceClip import tempfile import os import shutil # 이 부분을 추가 def images_to_video(image_files): # 임시 디렉터리 생성 temp_dir = tempfile.mkdtemp() image_paths = [] for i, image_file in enumerate(image_files): # 업로드된 파일을 임시 파일로 저장 temp_file_path = os.path.join(temp_dir, f"image_{i}.png") with open(temp_file_path, "wb") as f: f.write(image_file.read()) # 바이트 데이터를 파일로 저장 image_paths.append(temp_file_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 return image_paths # 예시 반환값, 실제로는 생성된 비디오 파일 경로를 반환해야 함 # 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()