Create app.py
Browse files
app.py
ADDED
@@ -0,0 +1,58 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
import gradio as gr
|
2 |
+
import cv2
|
3 |
+
import numpy as np
|
4 |
+
|
5 |
+
def apply_filter(image, filter_type):
|
6 |
+
if filter_type == "Soft Glow":
|
7 |
+
# Soft Glow ํจ๊ณผ
|
8 |
+
gaussian = cv2.GaussianBlur(image, (15, 15), 0)
|
9 |
+
soft_glow = cv2.addWeighted(image, 0.5, gaussian, 0.5, 0)
|
10 |
+
return soft_glow
|
11 |
+
elif filter_type == "Portrait Enhancer":
|
12 |
+
# ๊ฐ๋จํ ํฌํธ๋ ์ดํธ ํฅ์ (์: ๋๋น ๋ฐ ๋ฐ๊ธฐ ์กฐ์ )
|
13 |
+
enhanced = cv2.detailEnhance(image, sigma_s=10, sigma_r=0.15)
|
14 |
+
return enhanced
|
15 |
+
elif filter_type == "Warm Tone":
|
16 |
+
# ๋ฐ๋ปํ ํค ํจ๊ณผ
|
17 |
+
warm_image = cv2.applyColorMap(image, cv2.COLORMAP_AUTUMN)
|
18 |
+
return warm_image
|
19 |
+
elif filter_type == "Cold Tone":
|
20 |
+
# ์ฐจ๊ฐ์ด ํค ํจ๊ณผ
|
21 |
+
cold_image = cv2.applyColorMap(image, cv2.COLORMAP_WINTER)
|
22 |
+
return cold_image
|
23 |
+
elif filter_type == "High-Key":
|
24 |
+
# High-Key ํจ๊ณผ (๋ฐ๊ธฐ ์ฆ๊ฐ)
|
25 |
+
high_key = cv2.convertScaleAbs(image, alpha=1.2, beta=30)
|
26 |
+
return high_key
|
27 |
+
elif filter_type == "Low-Key":
|
28 |
+
# Low-Key ํจ๊ณผ (๋ฐ๊ธฐ ๊ฐ์)
|
29 |
+
low_key = cv2.convertScaleAbs(image, alpha=0.7, beta=-30)
|
30 |
+
return low_key
|
31 |
+
elif filter_type == "Haze":
|
32 |
+
# Haze ํจ๊ณผ
|
33 |
+
haze = cv2.addWeighted(image, 0.7, np.full(image.shape, 255, dtype=np.uint8), 0.3, 0)
|
34 |
+
return haze
|
35 |
+
else:
|
36 |
+
# ํํฐ๋ฅผ ์ ์ฉํ์ง ์์
|
37 |
+
return image
|
38 |
+
|
39 |
+
def convert_and_save(image, filter_type):
|
40 |
+
# ์ ํํ ํํฐ๋ฅผ ์ด๋ฏธ์ง์ ์ ์ฉ
|
41 |
+
filtered_image = apply_filter(image, filter_type)
|
42 |
+
# ์ด๋ฏธ์ง๋ฅผ ํ๋ฐฑ์ผ๋ก ๋ณํ
|
43 |
+
gray_image = convert_to_grayscale(filtered_image)
|
44 |
+
# ์ด๋ฏธ์ง๋ฅผ ์ ์ฅ
|
45 |
+
output_path = "output.jpg"
|
46 |
+
cv2.imwrite(output_path, gray_image)
|
47 |
+
return gray_image, output_path
|
48 |
+
|
49 |
+
# Gradio ์ธํฐํ์ด์ค ์ ์
|
50 |
+
iface = gr.Interface(
|
51 |
+
fn=convert_and_save,
|
52 |
+
inputs=["image", gr.Radio(["Soft Glow", "Portrait Enhancer", "Warm Tone", "Cold Tone", "High-Key", "Low-Key", "Haze"], label="ํํฐ ์ ํ")],
|
53 |
+
outputs=["image", "file"],
|
54 |
+
title="์ด๋ฏธ์ง ํ๋ฐฑ ๋ณํ๊ธฐ",
|
55 |
+
description="์ด๋ฏธ์ง๋ฅผ ์
๋ก๋ํ๊ณ ํํฐ๋ฅผ ์ ํํ๋ฉด, ํ๋ฐฑ์ผ๋ก ๋ณํํ๊ณ JPG ํ์ผ๋ก ๋ค์ด๋ก๋ํ ์ ์์ต๋๋ค."
|
56 |
+
)
|
57 |
+
|
58 |
+
iface.launch()
|