Spaces:
Runtime error
Runtime error
File size: 1,438 Bytes
f9f55eb a7dd379 c0ed664 9d611d0 a7dd379 7f3748b ce62711 7f3748b ce62711 7f3748b c57854a 7f3748b a7dd379 7f3748b c57854a 7f3748b c57854a ce62711 47816f4 a7dd379 c57854a 47816f4 c57854a 47816f4 a7dd379 6940020 a7dd379 82cfe63 a7dd379 | 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 | import gradio as gr
from PIL import Image
import numpy as np
import cv2
import os
def image_to_video(image):
# PIL ์ด๋ฏธ์ง๋ฅผ NumPy ๋ฐฐ์ด๋ก ๋ณํํ๊ณ , RGB ํ์์ผ๋ก ๋ณํ
image_array = np.array(image.convert('RGB'))
# OpenCV๋ BGR ํ์์ ์ฌ์ฉํ๋ฏ๋ก RGB์์ BGR๋ก ์์ ์ฑ๋์ ์ฌ์ ๋ ฌ
image_array = cv2.cvtColor(image_array, cv2.COLOR_RGB2BGR)
output_path = 'output_video.mp4'
if not os.path.exists('output'):
os.makedirs('output')
output_path = os.path.join('output', output_path)
height, width, layers = image_array.shape
size = (width, height)
fourcc = cv2.VideoWriter_fourcc(*'mp4v')
video = cv2.VideoWriter(output_path, fourcc, 30, size)
if not video.isOpened():
print("๋น๋์ค ์์ฑ์๊ฐ ํ์ผ์ ์ด์ง ๋ชปํ์ต๋๋ค.")
return None
for _ in range(150): # ์ด 150 ํ๋ ์ ์์ฑ
video.write(image_array)
video.release()
return output_path
def setup_interface():
with gr.Blocks() as demo:
gr.Markdown("### ์ด๋ฏธ์ง๋ฅผ ์
๋ก๋ํ๋ฉด 5์ด์ง๋ฆฌ ๋น๋์ค๋ฅผ ์์ฑํฉ๋๋ค.")
with gr.Row():
image_input = gr.Image(type="pil")
video_output = gr.Video(label="์์ฑ๋ ๋น๋์ค")
image_input.change(image_to_video, inputs=image_input, outputs=video_output)
return demo
demo = setup_interface()
demo.launch()
|