vitamom commited on
Commit
b608e9a
ยท
verified ยท
1 Parent(s): ec17889

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +17 -4
app.py CHANGED
@@ -1,6 +1,7 @@
1
  import gradio as gr
2
  import cv2
3
  import numpy as np
 
4
 
5
  def convert_to_grayscale(image):
6
  # ์ด๋ฏธ์ง€๋ฅผ ํ‘๋ฐฑ์œผ๋กœ ๋ณ€ํ™˜
@@ -8,20 +9,32 @@ def convert_to_grayscale(image):
8
  return gray_image
9
 
10
  def convert_and_save(image):
11
- # ์ด๋ฏธ์ง€๋ฅผ ํ‘๋ฐฑ์œผ๋กœ ๋ณ€ํ™˜ํ•˜๊ณ , ๋‹ค์šด๋กœ๋“œ ๊ฐ€๋Šฅํ•œ JPG ํŒŒ์ผ๋กœ ์ €์žฅ
12
  gray_image = convert_to_grayscale(image)
13
- output_path = "output.jpg"
14
  cv2.imwrite(output_path, gray_image)
15
  return gray_image, output_path
16
 
 
 
 
 
 
 
 
 
 
 
 
17
  # Gradio ์ธํ„ฐํŽ˜์ด์Šค ์ •์˜
18
  iface = gr.Interface(
19
  fn=convert_and_save,
20
  inputs="image",
21
  outputs=["image", "file"],
22
  title="์ด๋ฏธ์ง€ ํ‘๋ฐฑ ๋ณ€ํ™˜๊ธฐ",
23
- description="์ด๋ฏธ์ง€๋ฅผ ์—…๋กœ๋“œํ•˜๋ฉด ํ‘๋ฐฑ์œผ๋กœ ๋ณ€ํ™˜ํ•˜๊ณ , JPG ํŒŒ์ผ๋กœ ๋‹ค์šด๋กœ๋“œํ•  ์ˆ˜ ์žˆ์Šต๋‹ˆ๋‹ค."
 
24
  )
25
 
26
  if __name__ == "__main__":
27
- iface.launch()
 
1
  import gradio as gr
2
  import cv2
3
  import numpy as np
4
+ from PIL import Image
5
 
6
  def convert_to_grayscale(image):
7
  # ์ด๋ฏธ์ง€๋ฅผ ํ‘๋ฐฑ์œผ๋กœ ๋ณ€ํ™˜
 
9
  return gray_image
10
 
11
  def convert_and_save(image):
12
+ # ์ด๋ฏธ์ง€๋ฅผ ํ‘๋ฐฑ์œผ๋กœ ๋ณ€ํ™˜ํ•˜๊ณ , ๋‹ค์šด๋กœ๋“œ ๊ฐ€๋Šฅํ•œ PNG ํŒŒ์ผ๋กœ ์ €์žฅ
13
  gray_image = convert_to_grayscale(image)
14
+ output_path = "output.png"
15
  cv2.imwrite(output_path, gray_image)
16
  return gray_image, output_path
17
 
18
+ def load_example_image():
19
+ # ์˜ˆ์‹œ ์ด๋ฏธ์ง€ ์ƒ์„ฑ
20
+ example_path = "example_image.png"
21
+ example_image = np.ones((256, 256, 3), dtype=np.uint8) * 255 # ํฐ์ƒ‰ ์ด๋ฏธ์ง€
22
+ cv2.putText(example_image, "Example", (50, 150), cv2.FONT_HERSHEY_SIMPLEX, 1, (0, 0, 0), 2, cv2.LINE_AA)
23
+ cv2.imwrite(example_path, example_image)
24
+ return example_path
25
+
26
+ # ์˜ˆ์‹œ ์ด๋ฏธ์ง€ ๊ฒฝ๋กœ ์ƒ์„ฑ
27
+ example_image_path = load_example_image()
28
+
29
  # Gradio ์ธํ„ฐํŽ˜์ด์Šค ์ •์˜
30
  iface = gr.Interface(
31
  fn=convert_and_save,
32
  inputs="image",
33
  outputs=["image", "file"],
34
  title="์ด๋ฏธ์ง€ ํ‘๋ฐฑ ๋ณ€ํ™˜๊ธฐ",
35
+ description="์ด๋ฏธ์ง€๋ฅผ ์—…๋กœ๋“œํ•˜๋ฉด ํ‘๋ฐฑ์œผ๋กœ ๋ณ€ํ™˜ํ•˜๊ณ , PNG ํŒŒ์ผ๋กœ ๋‹ค์šด๋กœ๋“œํ•  ์ˆ˜ ์žˆ์Šต๋‹ˆ๋‹ค.",
36
+ examples=[example_image_path]
37
  )
38
 
39
  if __name__ == "__main__":
40
+ iface.launch()