Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
@@ -1,6 +1,7 @@
|
|
1 |
import gradio as gr
|
2 |
import cv2
|
3 |
import numpy as np
|
|
|
4 |
|
5 |
def convert_to_grayscale(image):
|
6 |
# ์ด๋ฏธ์ง๋ฅผ ํ๋ฐฑ์ผ๋ก ๋ณํ
|
@@ -8,20 +9,32 @@ def convert_to_grayscale(image):
|
|
8 |
return gray_image
|
9 |
|
10 |
def convert_and_save(image):
|
11 |
-
# ์ด๋ฏธ์ง๋ฅผ ํ๋ฐฑ์ผ๋ก ๋ณํํ๊ณ , ๋ค์ด๋ก๋ ๊ฐ๋ฅํ
|
12 |
gray_image = convert_to_grayscale(image)
|
13 |
-
output_path = "output.
|
14 |
cv2.imwrite(output_path, gray_image)
|
15 |
return gray_image, output_path
|
16 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
17 |
# Gradio ์ธํฐํ์ด์ค ์ ์
|
18 |
iface = gr.Interface(
|
19 |
fn=convert_and_save,
|
20 |
inputs="image",
|
21 |
outputs=["image", "file"],
|
22 |
title="์ด๋ฏธ์ง ํ๋ฐฑ ๋ณํ๊ธฐ",
|
23 |
-
description="์ด๋ฏธ์ง๋ฅผ ์
๋ก๋ํ๋ฉด ํ๋ฐฑ์ผ๋ก ๋ณํํ๊ณ ,
|
|
|
24 |
)
|
25 |
|
26 |
if __name__ == "__main__":
|
27 |
-
iface.launch()
|
|
|
1 |
import gradio as gr
|
2 |
import cv2
|
3 |
import numpy as np
|
4 |
+
from PIL import Image
|
5 |
|
6 |
def convert_to_grayscale(image):
|
7 |
# ์ด๋ฏธ์ง๋ฅผ ํ๋ฐฑ์ผ๋ก ๋ณํ
|
|
|
9 |
return gray_image
|
10 |
|
11 |
def convert_and_save(image):
|
12 |
+
# ์ด๋ฏธ์ง๋ฅผ ํ๋ฐฑ์ผ๋ก ๋ณํํ๊ณ , ๋ค์ด๋ก๋ ๊ฐ๋ฅํ PNG ํ์ผ๋ก ์ ์ฅ
|
13 |
gray_image = convert_to_grayscale(image)
|
14 |
+
output_path = "output.png"
|
15 |
cv2.imwrite(output_path, gray_image)
|
16 |
return gray_image, output_path
|
17 |
|
18 |
+
def load_example_image():
|
19 |
+
# ์์ ์ด๋ฏธ์ง ์์ฑ
|
20 |
+
example_path = "example_image.png"
|
21 |
+
example_image = np.ones((256, 256, 3), dtype=np.uint8) * 255 # ํฐ์ ์ด๋ฏธ์ง
|
22 |
+
cv2.putText(example_image, "Example", (50, 150), cv2.FONT_HERSHEY_SIMPLEX, 1, (0, 0, 0), 2, cv2.LINE_AA)
|
23 |
+
cv2.imwrite(example_path, example_image)
|
24 |
+
return example_path
|
25 |
+
|
26 |
+
# ์์ ์ด๋ฏธ์ง ๊ฒฝ๋ก ์์ฑ
|
27 |
+
example_image_path = load_example_image()
|
28 |
+
|
29 |
# Gradio ์ธํฐํ์ด์ค ์ ์
|
30 |
iface = gr.Interface(
|
31 |
fn=convert_and_save,
|
32 |
inputs="image",
|
33 |
outputs=["image", "file"],
|
34 |
title="์ด๋ฏธ์ง ํ๋ฐฑ ๋ณํ๊ธฐ",
|
35 |
+
description="์ด๋ฏธ์ง๋ฅผ ์
๋ก๋ํ๋ฉด ํ๋ฐฑ์ผ๋ก ๋ณํํ๊ณ , PNG ํ์ผ๋ก ๋ค์ด๋ก๋ํ ์ ์์ต๋๋ค.",
|
36 |
+
examples=[example_image_path]
|
37 |
)
|
38 |
|
39 |
if __name__ == "__main__":
|
40 |
+
iface.launch()
|