Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
@@ -1,5 +1,6 @@
|
|
1 |
import gradio as gr
|
2 |
import cv2
|
|
|
3 |
import os
|
4 |
|
5 |
def convert_to_grayscale(image):
|
@@ -14,24 +15,40 @@ def convert_and_save(image):
|
|
14 |
cv2.imwrite(output_path, gray_image)
|
15 |
return gray_image, output_path
|
16 |
|
17 |
-
# ์์ ์ด๋ฏธ์ง
|
18 |
-
example_files = ["1.png", "2.png", "3.png"]
|
19 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
20 |
|
21 |
-
# ์์
|
22 |
-
|
23 |
-
if
|
24 |
-
|
25 |
-
|
26 |
|
27 |
# Gradio ์ธํฐํ์ด์ค ์ ์
|
|
|
28 |
iface = gr.Interface(
|
29 |
fn=convert_and_save,
|
30 |
inputs="image",
|
31 |
outputs=["image", "file"],
|
32 |
title="์ด๋ฏธ์ง ํ๋ฐฑ ๋ณํ๊ธฐ",
|
33 |
description="์๋ ์์ ํ์ผ์ ํด๋ฆญํ๊ฑฐ๋ ์ง์ ์ด๋ฏธ์ง๋ฅผ ์
๋ก๋ํ์ธ์.",
|
34 |
-
examples=example_paths #
|
35 |
)
|
36 |
|
37 |
if __name__ == "__main__":
|
|
|
1 |
import gradio as gr
|
2 |
import cv2
|
3 |
+
import numpy as np
|
4 |
import os
|
5 |
|
6 |
def convert_to_grayscale(image):
|
|
|
15 |
cv2.imwrite(output_path, gray_image)
|
16 |
return gray_image, output_path
|
17 |
|
18 |
+
# ์์ ์ด๋ฏธ์ง ํ์ผ ์ด๋ฆ
|
19 |
+
example_files = ["1.png", "2.png", "3.png"]
|
20 |
+
|
21 |
+
# ๊ธฐ๋ณธ ์์ ์ด๋ฏธ์ง ์์ฑ ํจ์
|
22 |
+
def create_example_image(file_path, text):
|
23 |
+
# ๊ธฐ๋ณธ ํฐ์ ์ด๋ฏธ์ง์ ํ
์คํธ ์ถ๊ฐ
|
24 |
+
image = np.ones((256, 256, 3), dtype=np.uint8) * 255 # ํฐ์ ๋ฐฐ๊ฒฝ
|
25 |
+
cv2.putText(
|
26 |
+
image,
|
27 |
+
text,
|
28 |
+
(50, 130),
|
29 |
+
cv2.FONT_HERSHEY_SIMPLEX,
|
30 |
+
1,
|
31 |
+
(0, 0, 0),
|
32 |
+
2,
|
33 |
+
cv2.LINE_AA
|
34 |
+
)
|
35 |
+
cv2.imwrite(file_path, image)
|
36 |
|
37 |
+
# ์์ ์ด๋ฏธ์ง ์ค๋น
|
38 |
+
for i, file_name in enumerate(example_files, start=1):
|
39 |
+
if not os.path.exists(file_name):
|
40 |
+
print(f"{file_name} ํ์ผ์ด ์กด์ฌํ์ง ์์ต๋๋ค. ๊ธฐ๋ณธ ์ด๋ฏธ์ง๋ฅผ ์์ฑํฉ๋๋ค.")
|
41 |
+
create_example_image(file_name, f"Example {i}")
|
42 |
|
43 |
# Gradio ์ธํฐํ์ด์ค ์ ์
|
44 |
+
example_paths = [os.path.abspath(file) for file in example_files]
|
45 |
iface = gr.Interface(
|
46 |
fn=convert_and_save,
|
47 |
inputs="image",
|
48 |
outputs=["image", "file"],
|
49 |
title="์ด๋ฏธ์ง ํ๋ฐฑ ๋ณํ๊ธฐ",
|
50 |
description="์๋ ์์ ํ์ผ์ ํด๋ฆญํ๊ฑฐ๋ ์ง์ ์ด๋ฏธ์ง๋ฅผ ์
๋ก๋ํ์ธ์.",
|
51 |
+
examples=example_paths # ์์ ์ด๋ฏธ์ง ๊ฒฝ๋ก ์ ๋ฌ
|
52 |
)
|
53 |
|
54 |
if __name__ == "__main__":
|