itop01 / app.py
taeyeol's picture
Update app.py
a62776c verified
import gradio as gr
import cv2
import numpy as np
def apply_filter(image, filter_type):
# ํ•„ํ„ฐ์— ๋”ฐ๋ผ ์ฒ˜๋ฆฌ
if filter_type == "Soft Glow":
image = cv2.GaussianBlur(image, (15, 15), 0)
image = cv2.addWeighted(image, 1.5, cv2.GaussianBlur(image, (5, 5), 0), -0.5, 0)
elif filter_type == "Portrait Enhancer":
lab = cv2.cvtColor(image, cv2.COLOR_BGR2LAB)
l, a, b = cv2.split(lab)
l = cv2.equalizeHist(l)
enhanced = cv2.merge((l, a, b))
image = cv2.cvtColor(enhanced, cv2.COLOR_LAB2BGR)
elif filter_type == "Warm Tone":
warm_filter = np.array([[[20, 10, 0]]], dtype=np.uint8)
image = cv2.add(image, warm_filter)
elif filter_type == "Cold Tone":
cold_filter = np.array([[[-10, 0, 20]]], dtype=np.uint8)
image = cv2.add(image, cold_filter)
elif filter_type == "High-Key":
image = cv2.addWeighted(image, 1.5, np.zeros_like(image, image.dtype), 0, 50)
elif filter_type == "Low-Key":
image = cv2.addWeighted(image, 0.8, np.zeros_like(image, image.dtype), 0, -50)
elif filter_type == "Haze":
haze_filter = cv2.GaussianBlur(image, (25, 25), 10)
image = cv2.addWeighted(image, 0.8, haze_filter, 0.2, 0)
return image
def convert_and_save(image, filter_type):
# ํ•„ํ„ฐ ์ ์šฉ
filtered_image = apply_filter(image, filter_type)
# ์ด๋ฏธ์ง€๋ฅผ ํ‘๋ฐฑ์œผ๋กœ ๋ณ€ํ™˜
gray_image = cv2.cvtColor(filtered_image, cv2.COLOR_BGR2GRAY)
output_path = "output.jpg"
cv2.imwrite(output_path, gray_image)
return gray_image, output_path
# Gradio ์ธํ„ฐํŽ˜์ด์Šค ์ •์˜
iface = gr.Interface(
fn=convert_and_save,
inputs=[
gr.Image(label="์ด๋ฏธ์ง€ ์—…๋กœ๋“œ"),
gr.Radio(["Soft Glow", "Portrait Enhancer", "Warm Tone", "Cold Tone", "High-Key", "Low-Key", "Haze"], label="ํ•„ํ„ฐ ์„ ํƒ")
],
outputs=["image", "file"],
title="์ด๋ฏธ์ง€ ํ‘๋ฐฑ ๋ณ€ํ™˜๊ธฐ",
description="์ด๋ฏธ์ง€๋ฅผ ์—…๋กœ๋“œํ•˜๊ณ  ํ•„ํ„ฐ๋ฅผ ์„ ํƒํ•œ ํ›„ ํ‘๋ฐฑ์œผ๋กœ ๋ณ€ํ™˜๋œ ์ด๋ฏธ์ง€๋ฅผ ๋‹ค์šด๋กœ๋“œํ•  ์ˆ˜ ์žˆ์Šต๋‹ˆ๋‹ค."
)
if __name__ == "__main__":
iface.launch()