SEO / app.py
Sangwon78's picture
Update app.py
9bb5cf1 verified
Raw History Blame Contribute Delete
2.39 kB
import gradio as gr
import cv2
import numpy as np
def convert_to_grayscale(image):
# ์ด๋ฏธ์ง€๋ฅผ ํ‘๋ฐฑ์œผ๋กœ ๋ณ€ํ™˜
gray_image = cv2.cvtColor(image, cv2.COLOR_BGR2GRAY)
return gray_image
def apply_filter(image, filter_type):
if filter_type == "Soft Glow":
# ๋ถ€๋“œ๋Ÿฌ์šด ๋น› ํšจ๊ณผ
blurred = cv2.GaussianBlur(image, (15, 15), 0)
soft_glow = cv2.addWeighted(image, 0.5, blurred, 0.5, 0)
return soft_glow
elif filter_type == "Portrait Enhancer":
# ์ดˆ์ƒํ™” ๊ฐ•ํ™” ํšจ๊ณผ
kernel = np.array([[0, -1, 0], [-1, 5,-1], [0, -1, 0]])
enhanced = cv2.filter2D(image, -1, kernel)
return enhanced
elif filter_type == "Warm Tone":
# ๋”ฐ๋œปํ•œ ํ†ค ํšจ๊ณผ
warm = cv2.applyColorMap(image, cv2.COLORMAP_AUTUMN)
return warm
elif filter_type == "Cold Tone":
# ์ฐจ๊ฐ€์šด ํ†ค ํšจ๊ณผ
cold = cv2.applyColorMap(image, cv2.COLORMAP_WINTER)
return cold
elif filter_type == "High-Key":
# ํ•˜์ดํ‚ค ํšจ๊ณผ
high_key = cv2.convertScaleAbs(image, alpha=1.2, beta=50)
return high_key
elif filter_type == "Low-Key":
# ๋กœ์šฐํ‚ค ํšจ๊ณผ
low_key = cv2.convertScaleAbs(image, alpha=0.8, beta=-30)
return low_key
elif filter_type == "Haze":
# ํ—ค์ด์ฆˆ ํšจ๊ณผ
haze = cv2.addWeighted(image, 0.8, np.full(image.shape, 255, dtype=np.uint8), 0.2, 0)
return haze
else:
# ํ•„ํ„ฐ๊ฐ€ ์„ ํƒ๋˜์ง€ ์•Š์•˜์„ ๊ฒฝ์šฐ ์›๋ณธ ๋ฐ˜ํ™˜
return image
def convert_and_save_with_filter(image, filter_type):
# ์„ ํƒํ•œ ํ•„ํ„ฐ ์ ์šฉ ๋ฐ ํ‘๋ฐฑ ๋ณ€ํ™˜
filtered_image = apply_filter(image, filter_type)
gray_image = convert_to_grayscale(filtered_image)
output_path = "output.jpg"
cv2.imwrite(output_path, gray_image)
return gray_image, output_path
# Gradio ์ธํ„ฐํŽ˜์ด์Šค ์ •์˜
iface = gr.Interface(
fn=convert_and_save_with_filter,
inputs=["image", gr.Radio(["Soft Glow", "Portrait Enhancer", "Warm Tone", "Cold Tone", "High-Key", "Low-Key", "Haze"], label="Select Filter")],
outputs=["image", "file"],
title="์ด๋ฏธ์ง€ ํ‘๋ฐฑ ๋ณ€ํ™˜๊ธฐ ๋ฐ ํ•„ํ„ฐ ์ ์šฉ",
description="์ด๋ฏธ์ง€๋ฅผ ์—…๋กœ๋“œํ•˜๊ณ  ํ•„ํ„ฐ๋ฅผ ์„ ํƒํ•˜๋ฉด ํ‘๋ฐฑ์œผ๋กœ ๋ณ€ํ™˜ํ•˜๊ณ  JPG ํŒŒ์ผ๋กœ ๋‹ค์šด๋กœ๋“œํ•  ์ˆ˜ ์žˆ์Šต๋‹ˆ๋‹ค."
)
if __name__ == "__main__":
iface.launch()