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