Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
@@ -2,18 +2,7 @@ import gradio as gr
|
|
2 |
import cv2
|
3 |
import numpy as np
|
4 |
|
5 |
-
#
|
6 |
-
def convert_to_grayscale(image):
|
7 |
-
gray_image = cv2.cvtColor(image, cv2.COLOR_BGR2GRAY)
|
8 |
-
return gray_image
|
9 |
-
|
10 |
-
def convert_and_save(image):
|
11 |
-
gray_image = convert_to_grayscale(image)
|
12 |
-
output_path = "output.jpg"
|
13 |
-
cv2.imwrite(output_path, gray_image)
|
14 |
-
return gray_image, output_path
|
15 |
-
|
16 |
-
# ๋ก๊ทธ์ธ ๊ฒ์ฆ ํจ์
|
17 |
def verify_credentials(username, password):
|
18 |
if username == "kim" and password == "1234":
|
19 |
return True, "์ฑ๊ณต์ ์ผ๋ก ๋ก๊ทธ์ธ๋์์ต๋๋ค."
|
@@ -25,17 +14,31 @@ def login(username, password):
|
|
25 |
success, message = verify_credentials(username, password)
|
26 |
if success:
|
27 |
# ๋ก๊ทธ์ธ ์ฑ๊ณต ์ ๋ก๊ทธ์ธ ์น์
์จ๊ธฐ๊ณ ๋ฉ์ธ ์ฑ ํ์
|
28 |
-
return gr.update(visible=False), gr.update(visible=True), gr.update(value=message
|
29 |
else:
|
30 |
-
# ๋ก๊ทธ์ธ ์คํจ ์ ๋ฉ์์ง ํ์
|
31 |
-
return gr.update(visible=True), gr.update(visible=False), gr.update(value=message
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
32 |
|
33 |
-
# Gradio
|
34 |
with gr.Blocks() as demo:
|
35 |
# ๋ก๊ทธ์ธ ์น์
|
36 |
-
with gr.Row(
|
37 |
with gr.Column():
|
38 |
-
gr.Markdown("
|
39 |
username = gr.Textbox(label="์์ด๋")
|
40 |
password = gr.Textbox(label="๋น๋ฐ๋ฒํธ", type="password")
|
41 |
login_button = gr.Button("๋ก๊ทธ์ธ")
|
@@ -43,25 +46,12 @@ with gr.Blocks() as demo:
|
|
43 |
|
44 |
# ๋ฉ์ธ ์ ํ๋ฆฌ์ผ์ด์
์น์
(์ด๊ธฐ์๋ ์จ๊น)
|
45 |
with gr.Row(visible=False) as main_app:
|
46 |
-
with gr.
|
47 |
-
|
48 |
-
|
49 |
-
|
50 |
-
|
51 |
-
|
52 |
-
convert_button = gr.Button("๋ณํ ๋ฐ ์ ์ฅ")
|
53 |
-
|
54 |
-
# ์ค๋ฅธ์ชฝ: ์ถ๋ ฅ ํญ๋ชฉ
|
55 |
-
with gr.Column(scale=1):
|
56 |
-
output_image = gr.Image(label="ํ๋ฐฑ ์ด๋ฏธ์ง")
|
57 |
-
download_file = gr.File(label="๋ค์ด๋ก๋ JPG ํ์ผ")
|
58 |
-
|
59 |
-
# ๋ณํ ๋ฒํผ ํด๋ฆญ ์ ํจ์ ์ฐ๊ฒฐ
|
60 |
-
convert_button.click(
|
61 |
-
convert_and_save,
|
62 |
-
inputs=image_input,
|
63 |
-
outputs=[output_image, download_file]
|
64 |
-
)
|
65 |
|
66 |
# ๋ก๊ทธ์ธ ๋ฒํผ ์ด๋ฒคํธ ์ฐ๊ฒฐ
|
67 |
login_button.click(
|
@@ -69,6 +59,13 @@ with gr.Blocks() as demo:
|
|
69 |
inputs=[username, password],
|
70 |
outputs=[login_row, main_app, login_message]
|
71 |
)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
72 |
|
73 |
if __name__ == "__main__":
|
74 |
demo.launch()
|
|
|
2 |
import cv2
|
3 |
import numpy as np
|
4 |
|
5 |
+
# ์์ด๋/๋น๋ฐ๋ฒํธ ๊ฒ์ฆ ํจ์
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
6 |
def verify_credentials(username, password):
|
7 |
if username == "kim" and password == "1234":
|
8 |
return True, "์ฑ๊ณต์ ์ผ๋ก ๋ก๊ทธ์ธ๋์์ต๋๋ค."
|
|
|
14 |
success, message = verify_credentials(username, password)
|
15 |
if success:
|
16 |
# ๋ก๊ทธ์ธ ์ฑ๊ณต ์ ๋ก๊ทธ์ธ ์น์
์จ๊ธฐ๊ณ ๋ฉ์ธ ์ฑ ํ์
|
17 |
+
return gr.update(visible=False), gr.update(visible=True), gr.update(value=message)
|
18 |
else:
|
19 |
+
# ๋ก๊ทธ์ธ ์คํจ ์ ์ค๋ฅ ๋ฉ์์ง ํ์
|
20 |
+
return gr.update(visible=True), gr.update(visible=False), gr.update(value=message)
|
21 |
+
|
22 |
+
# ์ด๋ฏธ์ง ํ๋ฐฑ ๋ณํ ํจ์
|
23 |
+
def convert_to_grayscale(image):
|
24 |
+
# ์ด๋ฏธ์ง๋ฅผ ํ๋ฐฑ์ผ๋ก ๋ณํ
|
25 |
+
gray_image = cv2.cvtColor(image, cv2.COLOR_BGR2GRAY)
|
26 |
+
return gray_image
|
27 |
+
|
28 |
+
# ์ด๋ฏธ์ง ๋ณํ ๋ฐ ์ ์ฅ ํจ์
|
29 |
+
def convert_and_save(image):
|
30 |
+
# ์ด๋ฏธ์ง๋ฅผ ํ๋ฐฑ์ผ๋ก ๋ณํํ๊ณ , ๋ค์ด๋ก๋ ๊ฐ๋ฅํ JPG ํ์ผ๋ก ์ ์ฅ
|
31 |
+
gray_image = convert_to_grayscale(image)
|
32 |
+
output_path = "output.jpg"
|
33 |
+
cv2.imwrite(output_path, gray_image)
|
34 |
+
return gray_image, output_path
|
35 |
|
36 |
+
# Gradio ์ธํฐํ์ด์ค ์ ์
|
37 |
with gr.Blocks() as demo:
|
38 |
# ๋ก๊ทธ์ธ ์น์
|
39 |
+
with gr.Row() as login_row:
|
40 |
with gr.Column():
|
41 |
+
gr.Markdown("## ๋ก๊ทธ์ธ")
|
42 |
username = gr.Textbox(label="์์ด๋")
|
43 |
password = gr.Textbox(label="๋น๋ฐ๋ฒํธ", type="password")
|
44 |
login_button = gr.Button("๋ก๊ทธ์ธ")
|
|
|
46 |
|
47 |
# ๋ฉ์ธ ์ ํ๋ฆฌ์ผ์ด์
์น์
(์ด๊ธฐ์๋ ์จ๊น)
|
48 |
with gr.Row(visible=False) as main_app:
|
49 |
+
with gr.Column():
|
50 |
+
image_input = gr.Image(type="numpy", label="์ด๋ฏธ์ง ์
๋ก๋")
|
51 |
+
convert_button = gr.Button("ํ๋ฐฑ ๋ณํ")
|
52 |
+
with gr.Column():
|
53 |
+
grayscale_image = gr.Image(label="ํ๋ฐฑ ์ด๋ฏธ์ง")
|
54 |
+
download_file = gr.File(label="๋ณํ๋ ์ด๋ฏธ์ง ๋ค์ด๋ก๋")
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
55 |
|
56 |
# ๋ก๊ทธ์ธ ๋ฒํผ ์ด๋ฒคํธ ์ฐ๊ฒฐ
|
57 |
login_button.click(
|
|
|
59 |
inputs=[username, password],
|
60 |
outputs=[login_row, main_app, login_message]
|
61 |
)
|
62 |
+
|
63 |
+
# ์ด๋ฏธ์ง ๋ณํ ๋ฒํผ ์ด๋ฒคํธ ์ฐ๊ฒฐ
|
64 |
+
convert_button.click(
|
65 |
+
convert_and_save,
|
66 |
+
inputs=image_input,
|
67 |
+
outputs=[grayscale_image, download_file]
|
68 |
+
)
|
69 |
|
70 |
if __name__ == "__main__":
|
71 |
demo.launch()
|