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