Update app.py
Browse files
app.py
CHANGED
|
@@ -1,52 +1,73 @@
|
|
| 1 |
import gradio as gr
|
| 2 |
-
|
| 3 |
-
import
|
|
|
|
| 4 |
|
| 5 |
-
|
| 6 |
-
|
| 7 |
-
|
| 8 |
-
|
| 9 |
-
|
| 10 |
-
|
| 11 |
-
|
| 12 |
-
|
| 13 |
-
|
| 14 |
-
|
| 15 |
-
|
| 16 |
-
|
| 17 |
-
|
| 18 |
-
|
| 19 |
-
|
| 20 |
-
|
| 21 |
-
|
| 22 |
-
|
| 23 |
-
|
| 24 |
-
|
| 25 |
-
|
| 26 |
-
|
| 27 |
-
|
| 28 |
-
|
| 29 |
-
|
| 30 |
-
|
| 31 |
-
|
| 32 |
-
|
| 33 |
-
|
| 34 |
|
| 35 |
-
#
|
| 36 |
-
|
| 37 |
-
|
| 38 |
-
|
| 39 |
-
|
| 40 |
-
gr.Radio(["Color", "Grayscale"], label="๋ชจ๋ ์ ํ", value="Color"),
|
| 41 |
-
gr.Slider(0.5, 2.0, step=0.1, label="๋ฐ๊ธฐ ์กฐ์ ", value=1.0),
|
| 42 |
-
gr.Slider(0.5, 2.0, step=0.1, label="ํค ์กฐ์ ", value=1.0),
|
| 43 |
-
gr.Slider(0.1, 1.0, step=0.1, label="ํํฐ ๊ฐ๋", value=1.0),
|
| 44 |
-
gr.Radio(["JPG", "PNG", "PDF"], label="์ถ๋ ฅ ํฌ๋งท", value="JPG"),
|
| 45 |
-
],
|
| 46 |
-
outputs=gr.File(label="๋ค์ด๋ก๋"),
|
| 47 |
-
title="ํ
์คํธ๋ฅผ ์ด๋ฏธ์ง๋ก ๋ณํ",
|
| 48 |
-
description="ํ
์คํธ๋ฅผ ์
๋ ฅํ๊ณ ์ํ๋ ์ค์ ์ ํตํด ์ด๋ฏธ์ง๋ฅผ ์์ฑํฉ๋๋ค."
|
| 49 |
-
)
|
| 50 |
|
| 51 |
-
|
| 52 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
import gradio as gr
|
| 2 |
+
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)
|
| 15 |
+
enhanced = cv2.merge((l, a, b))
|
| 16 |
+
return cv2.cvtColor(enhanced, cv2.COLOR_LAB2RGB)
|
| 17 |
+
elif filter_type == "Warm Tone":
|
| 18 |
+
warm_filter = np.array([1, 1, 1, 0, 0, 1], dtype=np.float32).reshape(2, 3)
|
| 19 |
+
return cv2.transform(image, warm_filter)
|
| 20 |
+
elif filter_type == "Cold Tone":
|
| 21 |
+
cold_filter = np.array([1, 0, 0, 0, 1, 1], dtype=np.float32).reshape(2, 3)
|
| 22 |
+
return cv2.transform(image, cold_filter)
|
| 23 |
+
elif filter_type == "High-Key":
|
| 24 |
+
return cv2.convertScaleAbs(image, alpha=1 + intensity / 100, beta=intensity)
|
| 25 |
+
elif filter_type == "Low-Key":
|
| 26 |
+
return cv2.convertScaleAbs(image, alpha=1 - intensity / 100, beta=-intensity)
|
| 27 |
+
elif filter_type == "Haze":
|
| 28 |
+
haze = cv2.GaussianBlur(image, (21, 21), 0)
|
| 29 |
+
return cv2.addWeighted(image, 1.0, haze, intensity / 100, 0)
|
| 30 |
+
elif filter_type == "Monochrome":
|
| 31 |
+
gray = cv2.cvtColor(image, cv2.COLOR_RGB2GRAY)
|
| 32 |
+
return cv2.cvtColor(gray, cv2.COLOR_GRAY2RGB)
|
| 33 |
+
else:
|
| 34 |
+
return image
|
| 35 |
|
| 36 |
+
# ํํฐ ์ ์ฉ ์ ํ ๋น๊ต๋ฅผ ์ํ ํจ์
|
| 37 |
+
def process_image(image, filter_type, intensity):
|
| 38 |
+
original = image
|
| 39 |
+
filtered = apply_filter(image, filter_type, intensity)
|
| 40 |
+
return original, filtered
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 41 |
|
| 42 |
+
# Gradio ์ธํฐํ์ด์ค ๊ตฌ์ฑ
|
| 43 |
+
with gr.Blocks() as demo:
|
| 44 |
+
gr.Markdown("### ๋ค์ํ ์ฌ์ง ํํฐ ์ ์ฉ")
|
| 45 |
+
with gr.Row():
|
| 46 |
+
image_input = gr.Image(label="์
๋ก๋ ์ด๋ฏธ์ง", type="pil")
|
| 47 |
+
filter_type = gr.Dropdown(
|
| 48 |
+
label="ํํฐ ์ ํ",
|
| 49 |
+
choices=[
|
| 50 |
+
"Soft Glow", "Portrait Enhancer", "Warm Tone",
|
| 51 |
+
"Cold Tone", "High-Key", "Low-Key", "Haze", "Monochrome"
|
| 52 |
+
],
|
| 53 |
+
value="Soft Glow"
|
| 54 |
+
)
|
| 55 |
+
intensity = gr.Slider(label="ํํฐ ๊ฐ๋", minimum=0, maximum=100, value=50)
|
| 56 |
+
with gr.Row():
|
| 57 |
+
original_image = gr.Image(label="์๋ณธ ์ด๋ฏธ์ง")
|
| 58 |
+
filtered_image = gr.Image(label="ํํฐ ์ ์ฉ ์ด๋ฏธ์ง")
|
| 59 |
+
with gr.Row():
|
| 60 |
+
download_format = gr.Dropdown(
|
| 61 |
+
label="๋ค์ด๋ก๋ ํ์",
|
| 62 |
+
choices=["JPG", "PNG", "PDF"],
|
| 63 |
+
value="JPG"
|
| 64 |
+
)
|
| 65 |
+
download_button = gr.Button("๋ค์ด๋ก๋")
|
| 66 |
+
compare_slider = gr.Slider(label="๋ณ๊ฒฝ ์ ํ ๋น๊ต", minimum=0, maximum=1, value=0.5)
|
| 67 |
+
gr.Button("ํํฐ ์ ์ฉ").click(
|
| 68 |
+
process_image,
|
| 69 |
+
inputs=[image_input, filter_type, intensity],
|
| 70 |
+
outputs=[original_image, filtered_image]
|
| 71 |
+
)
|
| 72 |
+
|
| 73 |
+
demo.launch()
|