Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
@@ -1,47 +1,44 @@
|
|
1 |
-
import requests
|
2 |
import gradio as gr
|
3 |
-
import os
|
4 |
import imageio
|
5 |
import numpy as np
|
6 |
from PIL import Image
|
7 |
-
import requests
|
8 |
-
from io import BytesIO
|
9 |
-
import tempfile
|
10 |
|
11 |
-
|
12 |
-
|
13 |
-
|
|
|
|
|
|
|
14 |
|
15 |
-
def
|
16 |
-
|
17 |
-
|
18 |
-
|
19 |
-
|
20 |
-
|
21 |
-
|
22 |
-
|
23 |
-
for
|
24 |
-
|
25 |
-
|
26 |
-
|
27 |
-
images.append(img)
|
28 |
-
|
29 |
-
# ์ด๋ฏธ์ง๋ฅผ ์์์ผ๋ก ํฉ์น๊ธฐ
|
30 |
-
with tempfile.NamedTemporaryFile(delete=False, suffix='.mp4') as tmpfile:
|
31 |
-
with imageio.get_writer(tmpfile.name, fps=0.5) as video: # 2์ด ๊ฐ๊ฒฉ
|
32 |
-
for img in images:
|
33 |
-
video.append_data(np.array(img))
|
34 |
-
return tmpfile.name # ์์ ํ์ผ์ ๊ฒฝ๋ก ๋ฐํ
|
35 |
-
else:
|
36 |
-
return "๊ฒ์ ๊ฒฐ๊ณผ๊ฐ ์์ต๋๋ค."
|
37 |
|
38 |
-
|
39 |
-
|
40 |
-
|
41 |
-
|
42 |
-
|
43 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
44 |
)
|
45 |
|
46 |
-
|
47 |
-
|
|
|
|
|
1 |
import gradio as gr
|
|
|
2 |
import imageio
|
3 |
import numpy as np
|
4 |
from PIL import Image
|
|
|
|
|
|
|
5 |
|
6 |
+
def resize_image(image, target_width, target_height):
|
7 |
+
"""
|
8 |
+
์ด๋ฏธ์ง๋ฅผ ์ง์ ๋ ํฌ๊ธฐ๋ก ์กฐ์ ํฉ๋๋ค.
|
9 |
+
"""
|
10 |
+
image_pil = Image.fromarray(image).resize((target_width, target_height), Image.ANTIALIAS)
|
11 |
+
return np.array(image_pil)
|
12 |
|
13 |
+
def create_video(images):
|
14 |
+
"""
|
15 |
+
์ฃผ์ด์ง ์ด๋ฏธ์ง ๋ฆฌ์คํธ๋ก๋ถํฐ ๋น๋์ค๋ฅผ ์์ฑํฉ๋๋ค.
|
16 |
+
๋ชจ๋ ์ด๋ฏธ์ง๋ ๋น๋์ค์ ์ถ๊ฐ๋๊ธฐ ์ ์ ๋์ผํ ํฌ๊ธฐ๋ก ์กฐ์ ๋ฉ๋๋ค.
|
17 |
+
"""
|
18 |
+
target_width = 1920
|
19 |
+
target_height = 1080
|
20 |
+
with imageio.get_writer('output_video.mp4', fps=2) as video:
|
21 |
+
for img in images:
|
22 |
+
img_resized = resize_image(img, target_width, target_height)
|
23 |
+
video.append_data(img_resized)
|
24 |
+
return 'output_video.mp4'
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
25 |
|
26 |
+
def process_images(image_files):
|
27 |
+
"""
|
28 |
+
์
๋ก๋๋ ์ด๋ฏธ์ง ํ์ผ๋ค์ ์ฒ๋ฆฌํ์ฌ ๋น๋์ค๋ฅผ ์์ฑํฉ๋๋ค.
|
29 |
+
"""
|
30 |
+
images = [imageio.imread(image_file) for image_file in image_files]
|
31 |
+
video_file = create_video(images)
|
32 |
+
return video_file
|
33 |
+
|
34 |
+
# Gradio ์ธํฐํ์ด์ค ์ ์
|
35 |
+
iface = gr.Interface(
|
36 |
+
fn=process_images,
|
37 |
+
inputs=gr.inputs.Image(type="file", label="Upload Images", multiple=True),
|
38 |
+
outputs="file",
|
39 |
+
title="Image to Video Converter",
|
40 |
+
description="Upload multiple images to create a video."
|
41 |
)
|
42 |
|
43 |
+
# Gradio ์ฑ ์คํ
|
44 |
+
iface.launch()
|