vitamom commited on
Commit
901c73f
ยท
verified ยท
1 Parent(s): 1006b7e

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +26 -9
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
- example_paths = [os.path.abspath(file) for file in example_files]
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
20
 
21
- # ์˜ˆ์‹œ ํŒŒ์ผ ์กด์žฌ ์—ฌ๋ถ€ ํ™•์ธ
22
- missing_files = [file for file in example_files if not os.path.exists(file)]
23
- if missing_files:
24
- print(f"๋‹ค์Œ ํŒŒ์ผ์ด ์‹คํ–‰ ๋””๋ ‰ํ† ๋ฆฌ์— ์—†์Šต๋‹ˆ๋‹ค: {', '.join(missing_files)}")
25
- raise FileNotFoundError("ํ•„์ˆ˜ ์˜ˆ์‹œ ํŒŒ์ผ์ด ์—†์Šต๋‹ˆ๋‹ค. ํ™•์ธ ํ›„ ๋‹ค์‹œ ์‹คํ–‰ํ•˜์„ธ์š”.")
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__":