Kims12 commited on
Commit
ee7d7d6
โ€ข
1 Parent(s): e3680c4

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +16 -11
app.py CHANGED
@@ -7,7 +7,10 @@ def convert_to_grayscale(image):
7
  gray_image = cv2.cvtColor(image, cv2.COLOR_BGR2GRAY)
8
  return gray_image
9
 
10
- def apply_filter(image, filter_type):
 
 
 
11
  if filter_type == "Soft Glow":
12
  # Soft Glow ํšจ๊ณผ
13
  gaussian = cv2.GaussianBlur(image, (15, 15), 0)
@@ -41,23 +44,25 @@ def apply_filter(image, filter_type):
41
  # ํ•„ํ„ฐ๋ฅผ ์ ์šฉํ•˜์ง€ ์•Š์Œ
42
  return image
43
 
44
- def convert_and_save(image, filter_type):
45
- # ์„ ํƒํ•œ ํ•„ํ„ฐ๋ฅผ ์ด๋ฏธ์ง€์— ์ ์šฉ
46
- filtered_image = apply_filter(image, filter_type)
47
- # ์ด๋ฏธ์ง€๋ฅผ ํ‘๋ฐฑ์œผ๋กœ ๋ณ€ํ™˜
48
- gray_image = convert_to_grayscale(filtered_image)
49
  # ์ด๋ฏธ์ง€๋ฅผ ์ €์žฅ
50
  output_path = "output.jpg"
51
- cv2.imwrite(output_path, gray_image)
52
- return gray_image, output_path
53
 
54
  # Gradio ์ธํ„ฐํŽ˜์ด์Šค ์ •์˜
55
  iface = gr.Interface(
56
  fn=convert_and_save,
57
- inputs=["image", gr.Radio(["Soft Glow", "Portrait Enhancer", "Warm Tone", "Cold Tone", "High-Key", "Low-Key", "Haze"], label="ํ•„ํ„ฐ ์„ ํƒ")],
 
 
 
 
58
  outputs=["image", "file"],
59
- title="์ด๋ฏธ์ง€ ํ‘๋ฐฑ ๋ณ€ํ™˜๊ธฐ",
60
- description="์ด๋ฏธ์ง€๋ฅผ ์—…๋กœ๋“œํ•˜๊ณ  ํ•„ํ„ฐ๋ฅผ ์„ ํƒํ•˜๋ฉด, ํ‘๋ฐฑ์œผ๋กœ ๋ณ€ํ™˜ํ•˜๊ณ  JPG ํŒŒ์ผ๋กœ ๋‹ค์šด๋กœ๋“œํ•  ์ˆ˜ ์žˆ์Šต๋‹ˆ๋‹ค."
61
  )
62
 
63
  iface.launch()
 
7
  gray_image = cv2.cvtColor(image, cv2.COLOR_BGR2GRAY)
8
  return gray_image
9
 
10
+ def apply_filter(image, filter_type, grayscale):
11
+ if grayscale:
12
+ image = convert_to_grayscale(image)
13
+
14
  if filter_type == "Soft Glow":
15
  # Soft Glow ํšจ๊ณผ
16
  gaussian = cv2.GaussianBlur(image, (15, 15), 0)
 
44
  # ํ•„ํ„ฐ๋ฅผ ์ ์šฉํ•˜์ง€ ์•Š์Œ
45
  return image
46
 
47
+ def convert_and_save(image, filter_type, grayscale):
48
+ # ์„ ํƒํ•œ ํ•„ํ„ฐ์™€ ํ‘๋ฐฑ ๋ณ€ํ™˜ ์—ฌ๋ถ€๋ฅผ ์ด๋ฏธ์ง€์— ์ ์šฉ
49
+ filtered_image = apply_filter(image, filter_type, grayscale)
 
 
50
  # ์ด๋ฏธ์ง€๋ฅผ ์ €์žฅ
51
  output_path = "output.jpg"
52
+ cv2.imwrite(output_path, filtered_image)
53
+ return filtered_image, output_path
54
 
55
  # Gradio ์ธํ„ฐํŽ˜์ด์Šค ์ •์˜
56
  iface = gr.Interface(
57
  fn=convert_and_save,
58
+ inputs=[
59
+ "image",
60
+ gr.Radio(["None", "Soft Glow", "Portrait Enhancer", "Warm Tone", "Cold Tone", "High-Key", "Low-Key", "Haze"], label="ํ•„ํ„ฐ ์„ ํƒ"),
61
+ gr.Checkbox(label="ํ‘๋ฐฑ ๋ณ€ํ™˜")
62
+ ],
63
  outputs=["image", "file"],
64
+ title="์ด๋ฏธ์ง€ ํ•„ํ„ฐ ๋ฐ ํ‘๋ฐฑ ๋ณ€ํ™˜๊ธฐ",
65
+ description="์ด๋ฏธ์ง€๋ฅผ ์—…๋กœ๋“œํ•˜๊ณ  ํ•„ํ„ฐ์™€ ํ‘๋ฐฑ ๋ณ€ํ™˜ ์—ฌ๋ถ€๋ฅผ ์„ ํƒํ•˜๋ฉด, ๋ณ€ํ™˜๋œ ์ด๋ฏธ์ง€๋ฅผ JPG ํŒŒ์ผ๋กœ ๋‹ค์šด๋กœ๋“œํ•  ์ˆ˜ ์žˆ์Šต๋‹ˆ๋‹ค."
66
  )
67
 
68
  iface.launch()