Kims12 commited on
Commit
1278413
ยท
verified ยท
1 Parent(s): 6fdc5d1

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +34 -37
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, visible=True)
29
  else:
30
- # ๋กœ๊ทธ์ธ ์‹คํŒจ ์‹œ ๋ฉ”์‹œ์ง€ ํ‘œ์‹œ
31
- return gr.update(visible=True), gr.update(visible=False), gr.update(value=message, visible=True)
 
 
 
 
 
 
 
 
 
 
 
 
 
 
32
 
33
- # Gradio UI ๊ตฌ์„ฑ
34
  with gr.Blocks() as demo:
35
  # ๋กœ๊ทธ์ธ ์„น์…˜
36
- with gr.Row(visible=True) as login_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.Row():
47
- # ์™ผ์ชฝ: ์ž…๋ ฅ ํ•ญ๋ชฉ
48
- with gr.Column(scale=1):
49
- gr.Markdown("### ์ด๋ฏธ์ง€ ํ‘๋ฐฑ ๋ณ€ํ™˜๊ธฐ")
50
- gr.Markdown("์ด๋ฏธ์ง€๋ฅผ ์—…๋กœ๋“œํ•˜๋ฉด ํ‘๋ฐฑ์œผ๋กœ ๋ณ€ํ™˜ํ•˜๊ณ , JPG ํŒŒ์ผ๋กœ ๋‹ค์šด๋กœ๋“œํ•  ์ˆ˜ ์žˆ์Šต๋‹ˆ๋‹ค.")
51
- image_input = gr.Image(type="numpy", label="์ด๋ฏธ์ง€ ์—…๋กœ๋“œ")
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()