Update app.py
Browse files
app.py
CHANGED
|
@@ -0,0 +1,53 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import gradio as gr
|
| 2 |
+
import cv2
|
| 3 |
+
import numpy as np
|
| 4 |
+
|
| 5 |
+
def apply_filter(image, filter_type):
|
| 6 |
+
# ํํฐ์ ๋ฐ๋ผ ์ฒ๋ฆฌ
|
| 7 |
+
if filter_type == "Soft Glow":
|
| 8 |
+
image = cv2.GaussianBlur(image, (15, 15), 0)
|
| 9 |
+
image = cv2.addWeighted(image, 1.5, cv2.GaussianBlur(image, (5, 5), 0), -0.5, 0)
|
| 10 |
+
elif filter_type == "Portrait Enhancer":
|
| 11 |
+
lab = cv2.cvtColor(image, cv2.COLOR_BGR2LAB)
|
| 12 |
+
l, a, b = cv2.split(lab)
|
| 13 |
+
l = cv2.equalizeHist(l)
|
| 14 |
+
enhanced = cv2.merge((l, a, b))
|
| 15 |
+
image = cv2.cvtColor(enhanced, cv2.COLOR_LAB2BGR)
|
| 16 |
+
elif filter_type == "Warm Tone":
|
| 17 |
+
warm_filter = np.array([[[20, 10, 0]]], dtype=np.uint8)
|
| 18 |
+
image = cv2.add(image, warm_filter)
|
| 19 |
+
elif filter_type == "Cold Tone":
|
| 20 |
+
cold_filter = np.array([[[-10, 0, 20]]], dtype=np.uint8)
|
| 21 |
+
image = cv2.add(image, cold_filter)
|
| 22 |
+
elif filter_type == "High-Key":
|
| 23 |
+
image = cv2.addWeighted(image, 1.5, np.zeros_like(image, image.dtype), 0, 50)
|
| 24 |
+
elif filter_type == "Low-Key":
|
| 25 |
+
image = cv2.addWeighted(image, 0.8, np.zeros_like(image, image.dtype), 0, -50)
|
| 26 |
+
elif filter_type == "Haze":
|
| 27 |
+
haze_filter = cv2.GaussianBlur(image, (25, 25), 10)
|
| 28 |
+
image = cv2.addWeighted(image, 0.8, haze_filter, 0.2, 0)
|
| 29 |
+
return image
|
| 30 |
+
|
| 31 |
+
def convert_and_save(image, filter_type):
|
| 32 |
+
# ํํฐ ์ ์ฉ
|
| 33 |
+
filtered_image = apply_filter(image, filter_type)
|
| 34 |
+
# ์ด๋ฏธ์ง๋ฅผ ํ๋ฐฑ์ผ๋ก ๋ณํ
|
| 35 |
+
gray_image = cv2.cvtColor(filtered_image, cv2.COLOR_BGR2GRAY)
|
| 36 |
+
output_path = "output.jpg"
|
| 37 |
+
cv2.imwrite(output_path, gray_image)
|
| 38 |
+
return gray_image, output_path
|
| 39 |
+
|
| 40 |
+
# Gradio ์ธํฐํ์ด์ค ์ ์
|
| 41 |
+
iface = gr.Interface(
|
| 42 |
+
fn=convert_and_save,
|
| 43 |
+
inputs=[
|
| 44 |
+
gr.Image(label="์ด๋ฏธ์ง ์
๋ก๋"),
|
| 45 |
+
gr.Radio(["Soft Glow", "Portrait Enhancer", "Warm Tone", "Cold Tone", "High-Key", "Low-Key", "Haze"], label="ํํฐ ์ ํ")
|
| 46 |
+
],
|
| 47 |
+
outputs=["image", "file"],
|
| 48 |
+
title="์ด๋ฏธ์ง ํ๋ฐฑ ๋ณํ๊ธฐ",
|
| 49 |
+
description="์ด๋ฏธ์ง๋ฅผ ์
๋ก๋ํ๊ณ ํํฐ๋ฅผ ์ ํํ ํ ํ๋ฐฑ์ผ๋ก ๋ณํ๋ ์ด๋ฏธ์ง๋ฅผ ๋ค์ด๋ก๋ํ ์ ์์ต๋๋ค."
|
| 50 |
+
)
|
| 51 |
+
|
| 52 |
+
if __name__ == "__main__":
|
| 53 |
+
iface.launch()
|