Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
@@ -1,32 +1,29 @@
|
|
1 |
import gradio as gr
|
2 |
-
import cv2
|
3 |
-
import numpy as np
|
4 |
from PIL import Image
|
5 |
from gradio_imageslider import ImageSlider
|
6 |
|
7 |
def convert_to_grayscale(image):
|
8 |
-
|
9 |
-
|
10 |
-
|
11 |
-
|
12 |
-
|
|
|
13 |
|
14 |
def convert_and_save(image):
|
15 |
-
|
16 |
-
|
|
|
|
|
|
|
|
|
17 |
|
18 |
-
# ์ด๋ฏธ์ง๋ฅผ ํ๋ฐฑ์ผ๋ก ๋ณํ
|
19 |
-
gray_image = convert_to_grayscale(image)
|
20 |
-
gray_image_pil = Image.fromarray(cv2.cvtColor(gray_image, cv2.COLOR_BGR2RGB))
|
21 |
-
|
22 |
-
# ์ถ๋ ฅ ํ์ผ ๊ฒฝ๋ก ์ค์
|
23 |
-
output_path = "output.jpg"
|
24 |
# ํ๋ฐฑ ์ด๋ฏธ์ง ์ ์ฅ
|
25 |
-
|
26 |
-
|
27 |
|
28 |
-
# ์ฌ๋ผ์ด๋์ ์ฌ์ฉํ ๋ ์ด๋ฏธ์ง ๋ฐํ
|
29 |
-
return
|
30 |
|
31 |
# Gradio ์ธํฐํ์ด์ค ์ ์
|
32 |
with gr.Blocks() as demo:
|
@@ -34,7 +31,7 @@ with gr.Blocks() as demo:
|
|
34 |
gr.Markdown("์ด๋ฏธ์ง๋ฅผ ์
๋ก๋ํ๋ฉด ํ๋ฐฑ์ผ๋ก ๋ณํํ๊ณ , ๋ณ๊ฒฝ ์ ํ๋ฅผ ์ฌ๋ผ์ด๋ ํํ๋ก ๋น๊ตํ ์ ์์ต๋๋ค.")
|
35 |
|
36 |
with gr.Row():
|
37 |
-
image_input = gr.Image(label="์ด๋ฏธ์ง ์
๋ก๋", type="
|
38 |
file_output = gr.File(label="๋ค์ด๋ก๋ ๊ฐ๋ฅํ JPG ํ์ผ")
|
39 |
|
40 |
with gr.Row():
|
|
|
1 |
import gradio as gr
|
|
|
|
|
2 |
from PIL import Image
|
3 |
from gradio_imageslider import ImageSlider
|
4 |
|
5 |
def convert_to_grayscale(image):
|
6 |
+
"""
|
7 |
+
์ด๋ฏธ์ง๋ฅผ ํ๋ฐฑ์ผ๋ก ๋ณํํ๊ณ ๋ค์ RGB ํ์์ผ๋ก ๋ณํํ์ฌ 3์ฑ๋ ์ด๋ฏธ์ง๋ฅผ ๋ฐํํฉ๋๋ค.
|
8 |
+
"""
|
9 |
+
gray_image = image.convert("L") # ํ๋ฐฑ์ผ๋ก ๋ณํ
|
10 |
+
gray_image = gray_image.convert("RGB") # ๋ค์ RGB๋ก ๋ณํ
|
11 |
+
return gray_image
|
12 |
|
13 |
def convert_and_save(image):
|
14 |
+
"""
|
15 |
+
์
๋ก๋๋ ์ด๋ฏธ์ง๋ฅผ ํ๋ฐฑ์ผ๋ก ๋ณํํ๊ณ , ์๋ณธ๊ณผ ๋ณํ๋ ์ด๋ฏธ์ง๋ฅผ ์ฌ๋ผ์ด๋ ํํ๋ก ๋ฐํํ๋ฉฐ,
|
16 |
+
๋ณํ๋ ์ด๋ฏธ์ง๋ฅผ JPG ํ์ผ๋ก ์ ์ฅํฉ๋๋ค.
|
17 |
+
"""
|
18 |
+
original_image = image # ์๋ณธ ์ด๋ฏธ์ง (PIL ํ์)
|
19 |
+
gray_image = convert_to_grayscale(image) # ํ๋ฐฑ ์ด๋ฏธ์ง (PIL ํ์)
|
20 |
|
|
|
|
|
|
|
|
|
|
|
|
|
21 |
# ํ๋ฐฑ ์ด๋ฏธ์ง ์ ์ฅ
|
22 |
+
output_path = "output.jpg"
|
23 |
+
gray_image.save(output_path, "JPEG")
|
24 |
|
25 |
+
# ์ฌ๋ผ์ด๋์ ์ฌ์ฉํ ๋ ์ด๋ฏธ์ง ๋ฆฌ์คํธ๋ก ๋ฐํ
|
26 |
+
return [original_image, gray_image], output_path
|
27 |
|
28 |
# Gradio ์ธํฐํ์ด์ค ์ ์
|
29 |
with gr.Blocks() as demo:
|
|
|
31 |
gr.Markdown("์ด๋ฏธ์ง๋ฅผ ์
๋ก๋ํ๋ฉด ํ๋ฐฑ์ผ๋ก ๋ณํํ๊ณ , ๋ณ๊ฒฝ ์ ํ๋ฅผ ์ฌ๋ผ์ด๋ ํํ๋ก ๋น๊ตํ ์ ์์ต๋๋ค.")
|
32 |
|
33 |
with gr.Row():
|
34 |
+
image_input = gr.Image(label="์ด๋ฏธ์ง ์
๋ก๋", type="pil")
|
35 |
file_output = gr.File(label="๋ค์ด๋ก๋ ๊ฐ๋ฅํ JPG ํ์ผ")
|
36 |
|
37 |
with gr.Row():
|