File size: 1,563 Bytes
0660b1b
5b0e95f
 
 
a0b6e16
 
b8bab42
5b0e95f
 
 
a0b6e16
5b0e95f
 
a0b6e16
 
 
3bdb854
 
a0b6e16
 
 
 
5b0e95f
 
5d3bf28
3bdb854
5d3bf28
5b0e95f
 
 
 
 
 
 
 
 
 
 
 
 
80d6daf
b706b1a
5b0e95f
 
 
 
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
import gradio as gr
from moviepy.editor import ImageSequenceClip
import tempfile
import os
import shutil  # ์ด ๋ถ€๋ถ„์„ ์ถ”๊ฐ€


def images_to_video(image_files):
    temp_dir = tempfile.mkdtemp()
    image_paths = []
    
    for i, image_file in enumerate(image_files):
        image_path = os.path.join(temp_dir, f"image_{i}.png")
        
        # ํŒŒ์ผ ๋‚ด์šฉ์„ ๋ฐ”์ดํŠธ๋กœ ์“ฐ๊ฑฐ๋‚˜ ์ด๋ฏธ ์กด์žฌํ•˜๋Š” ํŒŒ์ผ์„ ๋ณต์‚ฌ
        if isinstance(image_file, bytes):
            with open(image_path, "wb") as f:
                f.write(image_file)
        else:
            # shutil ๋ชจ๋“ˆ์˜ copy ํ•จ์ˆ˜ ์‚ฌ์šฉ
            shutil.copy(image_file, image_path)
        
        image_paths.append(image_path)
    
    # ์ด๋ฏธ์ง€ ์‹œํ€€์Šค๋กœ๋ถ€ํ„ฐ ๋น„๋””์˜ค ํด๋ฆฝ ์ƒ์„ฑ ๋ฐ ๊ธฐํƒ€ ๋กœ์ง...

  
    # ์ด๋ฏธ์ง€ ์‹œํ€€์Šค๋กœ๋ถ€ํ„ฐ ๋น„๋””์˜ค ํด๋ฆฝ ์ƒ์„ฑ (๊ฐ ์ด๋ฏธ์ง€์˜ ์ง€์† ์‹œ๊ฐ„์€ 2์ดˆ)
    clip = ImageSequenceClip(image_paths, fps=0.5)  # fps=0.5 => ๊ฐ ์ด๋ฏธ์ง€๋Š” 2์ดˆ ๋™์•ˆ ๋ณด์ž„
    
    # ๋น„๋””์˜ค ํŒŒ์ผ ์ €์žฅ
    output_video_path = os.path.join(temp_dir, "output.mp4")
    clip.write_videofile(output_video_path, fps=24)  # 24fps๋กœ ์ถœ๋ ฅ ๋น„๋””์˜ค ์ €์žฅ
    
    # ์ƒ์„ฑ๋œ ๋น„๋””์˜ค ํŒŒ์ผ ๊ฒฝ๋กœ ๋ฐ˜ํ™˜
    return output_video_path

# Gradio ์ธํ„ฐํŽ˜์ด์Šค ์ •์˜
with gr.Blocks() as demo:
    with gr.Row():
        file_input = gr.File(label="Upload images")
        
        video_output = gr.Video(label="Output video")
        file_input.change(images_to_video, inputs=file_input, outputs=video_output)

demo.launch()