Sangwon78 commited on
Commit
079a06c
Β·
verified Β·
1 Parent(s): f9a00d2

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +73 -0
app.py CHANGED
@@ -3,6 +3,19 @@ import cv2
3
  import numpy as np
4
  from PIL import Image
5
 
 
 
 
 
 
 
 
 
 
 
 
 
 
6
  # ν•„ν„° ν•¨μˆ˜ μ •μ˜
7
  def apply_filter(image, filter_type, intensity):
8
  image = np.array(image)
@@ -70,4 +83,64 @@ with gr.Blocks() as demo:
70
  outputs=[original_image, filtered_image]
71
  )
72
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
73
  demo.launch()
 
3
  import numpy as np
4
  from PIL import Image
5
 
6
+ # ν•„ν„° ν•¨μˆ˜ μ •μ˜
7
+ def apply_filter(image, filter_type, intensity):
8
+ image = np.array(image)
9
+ if filter_type == "Soft Glow":
10
+ return cv2.addWeighted(image, 1.0, cv2.GaussianBlur(image, (15, 15), 0), intensity / 100, 0)
11
+ elif filter_type == "Portrait Enhancer":
12
+ lab = cv2.cvtColor(image, cv2.COLOR_RGB2LAB)
13
+ l, a, b = cv2.split(lab)
14
+ l = cv2.equalizeHist(l)import gradio as gr
15
+ import cv2
16
+ import numpy as np
17
+ from PIL import Image
18
+
19
  # ν•„ν„° ν•¨μˆ˜ μ •μ˜
20
  def apply_filter(image, filter_type, intensity):
21
  image = np.array(image)
 
83
  outputs=[original_image, filtered_image]
84
  )
85
 
86
+ demo.launch()
87
+
88
+ enhanced = cv2.merge((l, a, b))
89
+ return cv2.cvtColor(enhanced, cv2.COLOR_LAB2RGB)
90
+ elif filter_type == "Warm Tone":
91
+ warm_filter = np.array([1, 1, 1, 0, 0, 1], dtype=np.float32).reshape(2, 3)
92
+ return cv2.transform(image, warm_filter)
93
+ elif filter_type == "Cold Tone":
94
+ cold_filter = np.array([1, 0, 0, 0, 1, 1], dtype=np.float32).reshape(2, 3)
95
+ return cv2.transform(image, cold_filter)
96
+ elif filter_type == "High-Key":
97
+ return cv2.convertScaleAbs(image, alpha=1 + intensity / 100, beta=intensity)
98
+ elif filter_type == "Low-Key":
99
+ return cv2.convertScaleAbs(image, alpha=1 - intensity / 100, beta=-intensity)
100
+ elif filter_type == "Haze":
101
+ haze = cv2.GaussianBlur(image, (21, 21), 0)
102
+ return cv2.addWeighted(image, 1.0, haze, intensity / 100, 0)
103
+ elif filter_type == "Monochrome":
104
+ gray = cv2.cvtColor(image, cv2.COLOR_RGB2GRAY)
105
+ return cv2.cvtColor(gray, cv2.COLOR_GRAY2RGB)
106
+ else:
107
+ return image
108
+
109
+ # ν•„ν„° 적용 μ „ν›„ 비ꡐλ₯Ό μœ„ν•œ ν•¨μˆ˜
110
+ def process_image(image, filter_type, intensity):
111
+ original = image
112
+ filtered = apply_filter(image, filter_type, intensity)
113
+ return original, filtered
114
+
115
+ # Gradio μΈν„°νŽ˜μ΄μŠ€ ꡬ성
116
+ with gr.Blocks() as demo:
117
+ gr.Markdown("### λ‹€μ–‘ν•œ 사진 ν•„ν„° 적용")
118
+ with gr.Row():
119
+ image_input = gr.Image(label="μ—…λ‘œλ“œ 이미지", type="pil")
120
+ filter_type = gr.Dropdown(
121
+ label="ν•„ν„° 선택",
122
+ choices=[
123
+ "Soft Glow", "Portrait Enhancer", "Warm Tone",
124
+ "Cold Tone", "High-Key", "Low-Key", "Haze", "Monochrome"
125
+ ],
126
+ value="Soft Glow"
127
+ )
128
+ intensity = gr.Slider(label="ν•„ν„° 강도", minimum=0, maximum=100, value=50)
129
+ with gr.Row():
130
+ original_image = gr.Image(label="원본 이미지")
131
+ filtered_image = gr.Image(label="ν•„ν„° 적용 이미지")
132
+ with gr.Row():
133
+ download_format = gr.Dropdown(
134
+ label="λ‹€μš΄λ‘œλ“œ ν˜•μ‹",
135
+ choices=["JPG", "PNG", "PDF"],
136
+ value="JPG"
137
+ )
138
+ download_button = gr.Button("λ‹€μš΄λ‘œλ“œ")
139
+ compare_slider = gr.Slider(label="λ³€κ²½ μ „ν›„ 비ꡐ", minimum=0, maximum=1, value=0.5)
140
+ gr.Button("ν•„ν„° 적용").click(
141
+ process_image,
142
+ inputs=[image_input, filter_type, intensity],
143
+ outputs=[original_image, filtered_image]
144
+ )
145
+
146
  demo.launch()