Spaces:
Running
Running
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()
|