Update app.py
Browse files
app.py
CHANGED
|
@@ -3,19 +3,6 @@ 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)
|
| 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,64 +70,4 @@ with gr.Blocks() as demo:
|
|
| 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()
|
|
|
|
| 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 |
outputs=[original_image, filtered_image]
|
| 71 |
)
|
| 72 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 73 |
demo.launch()
|