Spaces:
Sleeping
Sleeping
import gradio as gr | |
import imageio | |
import numpy as np | |
from PIL import Image | |
def resize_image(image, target_width, target_height): | |
""" | |
์ด๋ฏธ์ง๋ฅผ ์ง์ ๋ ํฌ๊ธฐ๋ก ์กฐ์ ํฉ๋๋ค. | |
""" | |
image_pil = Image.fromarray(image).resize((target_width, target_height), Image.ANTIALIAS) | |
return np.array(image_pil) | |
def create_video(images): | |
""" | |
์ฃผ์ด์ง ์ด๋ฏธ์ง ๋ฆฌ์คํธ๋ก๋ถํฐ ๋น๋์ค๋ฅผ ์์ฑํฉ๋๋ค. | |
๋ชจ๋ ์ด๋ฏธ์ง๋ ๋น๋์ค์ ์ถ๊ฐ๋๊ธฐ ์ ์ ๋์ผํ ํฌ๊ธฐ๋ก ์กฐ์ ๋ฉ๋๋ค. | |
""" | |
target_width = 1920 | |
target_height = 1080 | |
with imageio.get_writer('output_video.mp4', fps=2) as video: | |
for img in images: | |
img_resized = resize_image(img, target_width, target_height) | |
video.append_data(img_resized) | |
return 'output_video.mp4' | |
def process_images(image_files): | |
""" | |
์ ๋ก๋๋ ์ด๋ฏธ์ง ํ์ผ๋ค์ ์ฒ๋ฆฌํ์ฌ ๋น๋์ค๋ฅผ ์์ฑํฉ๋๋ค. | |
""" | |
images = [imageio.v3.imread(image_file) for image_file in image_files] | |
video_file = create_video(images) | |
return video_file | |
# Gradio ์ธํฐํ์ด์ค ์ ์ | |
iface = gr.Interface( | |
fn=process_images, | |
inputs=gr.File(label="Upload Images", type="file", multiple_files=True), # ์์ ๋ ๋ถ๋ถ | |
outputs="file", | |
title="Image to Video Converter", | |
description="Upload multiple images to create a video." | |
) | |
# Gradio ์ฑ ์คํ | |
iface.launch() |