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

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +18 -16
app.py CHANGED
@@ -2,16 +2,11 @@ import gradio as gr
2
  import cv2
3
  import numpy as np
4
 
5
- def convert_to_grayscale(image):
6
- # ์ด๋ฏธ์ง€๋ฅผ ํ‘๋ฐฑ์œผ๋กœ ๋ณ€ํ™˜
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)
17
  soft_glow = cv2.addWeighted(image, 0.5, gaussian, 0.5, 0)
@@ -44,9 +39,14 @@ def apply_filter(image, filter_type, grayscale):
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)
@@ -57,12 +57,14 @@ 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()
 
2
  import cv2
3
  import numpy as np
4
 
5
+ def apply_filter(image, filter_type):
6
+ if filter_type == "Grayscale":
7
+ # ํ‘๋ฐฑ ๋ณ€ํ™˜
8
+ return convert_to_grayscale(image)
9
+ elif filter_type == "Soft Glow":
 
 
 
 
 
10
  # Soft Glow ํšจ๊ณผ
11
  gaussian = cv2.GaussianBlur(image, (15, 15), 0)
12
  soft_glow = cv2.addWeighted(image, 0.5, gaussian, 0.5, 0)
 
39
  # ํ•„ํ„ฐ๋ฅผ ์ ์šฉํ•˜์ง€ ์•Š์Œ
40
  return image
41
 
42
+ def convert_to_grayscale(image):
43
+ # ์ด๋ฏธ์ง€๋ฅผ ํ‘๋ฐฑ์œผ๋กœ ๋ณ€ํ™˜
44
+ gray_image = cv2.cvtColor(image, cv2.COLOR_BGR2GRAY)
45
+ return gray_image
46
+
47
+ def convert_and_save(image, filter_type):
48
+ # ์„ ํƒํ•œ ํ•„ํ„ฐ๋ฅผ ์ด๋ฏธ์ง€์— ์ ์šฉ
49
+ filtered_image = apply_filter(image, filter_type)
50
  # ์ด๋ฏธ์ง€๋ฅผ ์ €์žฅ
51
  output_path = "output.jpg"
52
  cv2.imwrite(output_path, filtered_image)
 
57
  fn=convert_and_save,
58
  inputs=[
59
  "image",
60
+ gr.Radio(
61
+ ["None", "Grayscale", "Soft Glow", "Portrait Enhancer", "Warm Tone", "Cold Tone", "High-Key", "Low-Key", "Haze"],
62
+ label="ํ•„ํ„ฐ ์„ ํƒ"
63
+ )
64
  ],
65
  outputs=["image", "file"],
66
  title="์ด๋ฏธ์ง€ ํ•„ํ„ฐ ๋ฐ ํ‘๋ฐฑ ๋ณ€ํ™˜๊ธฐ",
67
+ description="์ด๋ฏธ์ง€๋ฅผ ์—…๋กœ๋“œํ•˜๊ณ  ํ•„ํ„ฐ(๋˜๋Š” ํ‘๋ฐฑ ๋ณ€ํ™˜)๋ฅผ ์„ ํƒํ•˜๋ฉด, ๋ณ€ํ™˜๋œ ์ด๋ฏธ์ง€๋ฅผ JPG ํŒŒ์ผ๋กœ ๋‹ค์šด๋กœ๋“œํ•  ์ˆ˜ ์žˆ์Šต๋‹ˆ๋‹ค."
68
  )
69
 
70
  iface.launch()