Kims12 commited on
Commit
7d57c88
ยท
verified ยท
1 Parent(s): 1278413

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +2 -71
app.py CHANGED
@@ -1,71 +1,2 @@
1
- import gradio as gr
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, "์„ฑ๊ณต์ ์œผ๋กœ ๋กœ๊ทธ์ธ๋˜์—ˆ์Šต๋‹ˆ๋‹ค."
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'))