vitamom commited on
Commit
1006b7e
Β·
verified Β·
1 Parent(s): 83cb9be

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +9 -28
app.py CHANGED
@@ -1,6 +1,5 @@
1
  import gradio as gr
2
  import cv2
3
- import numpy as np
4
  import os
5
 
6
  def convert_to_grayscale(image):
@@ -16,32 +15,14 @@ def convert_and_save(image):
16
  return gray_image, output_path
17
 
18
  # μ˜ˆμ‹œ 이미지 경둜 μ„€μ •
19
- example_dir = "example_images"
20
- os.makedirs(example_dir, exist_ok=True) # μ˜ˆμ‹œ 이미지 디렉토리 생성
21
- example_image_paths = [
22
- os.path.join(example_dir, f"example_image{i}.png") for i in range(1, 4)
23
- ]
24
 
25
- # μ˜ˆμ‹œ 이미지 생성 ν•¨μˆ˜
26
- def create_example_image(file_path, text):
27
- # κΈ°λ³Έ 흰색 이미지에 ν…μŠ€νŠΈ μΆ”κ°€
28
- image = np.ones((256, 256, 3), dtype=np.uint8) * 255 # 흰색 λ°°κ²½
29
- cv2.putText(
30
- image,
31
- text,
32
- (50, 130),
33
- cv2.FONT_HERSHEY_SIMPLEX,
34
- 1,
35
- (0, 0, 0),
36
- 2,
37
- cv2.LINE_AA
38
- )
39
- cv2.imwrite(file_path, image)
40
-
41
- # μ˜ˆμ‹œ 이미지가 없을 경우 생성
42
- for i, file_path in enumerate(example_image_paths, start=1):
43
- if not os.path.exists(file_path):
44
- create_example_image(file_path, f"Example {i}")
45
 
46
  # Gradio μΈν„°νŽ˜μ΄μŠ€ μ •μ˜
47
  iface = gr.Interface(
@@ -49,8 +30,8 @@ iface = gr.Interface(
49
  inputs="image",
50
  outputs=["image", "file"],
51
  title="이미지 흑백 λ³€ν™˜κΈ°",
52
- description="이미지λ₯Ό μ—…λ‘œλ“œν•˜λ©΄ ν‘λ°±μœΌλ‘œ λ³€ν™˜ν•˜κ³ , PNG 파일둜 λ‹€μš΄λ‘œλ“œν•  수 μžˆμŠ΅λ‹ˆλ‹€.",
53
- examples=example_image_paths # μ˜ˆμ‹œ 이미지 3개 제곡
54
  )
55
 
56
  if __name__ == "__main__":
 
1
  import gradio as gr
2
  import cv2
 
3
  import os
4
 
5
  def convert_to_grayscale(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(
 
30
  inputs="image",
31
  outputs=["image", "file"],
32
  title="이미지 흑백 λ³€ν™˜κΈ°",
33
+ description="μ•„λž˜ μ˜ˆμ‹œ νŒŒμΌμ„ ν΄λ¦­ν•˜κ±°λ‚˜ 직접 이미지λ₯Ό μ—…λ‘œλ“œν•˜μ„Έμš”.",
34
+ examples=example_paths # μ—…λ‘œλ“œλœ νŒŒμΌμ„ μ˜ˆμ‹œλ‘œ μ‚¬μš©
35
  )
36
 
37
  if __name__ == "__main__":