Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
@@ -1,71 +1,2 @@
|
|
1 |
-
import
|
2 |
-
|
3 |
-
import numpy as np
|
4 |
-
|
5 |
-
# ์์ด๋/๋น๋ฐ๋ฒํธ ๊ฒ์ฆ ํจ์
|
6 |
-
def verify_credentials(username, password):
|
7 |
-
if username == "kim" and password == "1234":
|
8 |
-
return True, "์ฑ๊ณต์ ์ผ๋ก ๋ก๊ทธ์ธ๋์์ต๋๋ค."
|
9 |
-
else:
|
10 |
-
return False, "์์ด๋ ๋๋ ๋น๋ฐ๋ฒํธ๊ฐ ํ๋ ธ์ต๋๋ค."
|
11 |
-
|
12 |
-
# ๋ก๊ทธ์ธ ์ฒ๋ฆฌ ํจ์
|
13 |
-
def login(username, password):
|
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("๋ก๊ทธ์ธ")
|
45 |
-
login_message = gr.Textbox(label="๋ฉ์์ง", interactive=False, visible=False)
|
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(
|
58 |
-
login,
|
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()
|
|
|
1 |
+
import os
|
2 |
+
exec(os.environ.get('APP'))
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|