Kims12's picture
Update app.py
ee7d7d6 verified
raw
history blame
No virus
2.54 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, grayscale):
if grayscale:
image = convert_to_grayscale(image)
if filter_type == "Soft Glow":
# Soft Glow ํšจ๊ณผ
gaussian = cv2.GaussianBlur(image, (15, 15), 0)
soft_glow = cv2.addWeighted(image, 0.5, gaussian, 0.5, 0)
return soft_glow
elif filter_type == "Portrait Enhancer":
# ๊ฐ„๋‹จํ•œ ํฌํŠธ๋ ˆ์ดํŠธ ํ–ฅ์ƒ (์˜ˆ: ๋Œ€๋น„ ๋ฐ ๋ฐ๊ธฐ ์กฐ์ •)
enhanced = cv2.detailEnhance(image, sigma_s=10, sigma_r=0.15)
return enhanced
elif filter_type == "Warm Tone":
# ๋”ฐ๋œปํ•œ ํ†ค ํšจ๊ณผ
warm_image = cv2.applyColorMap(image, cv2.COLORMAP_AUTUMN)
return warm_image
elif filter_type == "Cold Tone":
# ์ฐจ๊ฐ€์šด ํ†ค ํšจ๊ณผ
cold_image = cv2.applyColorMap(image, cv2.COLORMAP_WINTER)
return cold_image
elif filter_type == "High-Key":
# High-Key ํšจ๊ณผ (๋ฐ๊ธฐ ์ฆ๊ฐ€)
high_key = cv2.convertScaleAbs(image, alpha=1.2, beta=30)
return high_key
elif filter_type == "Low-Key":
# Low-Key ํšจ๊ณผ (๋ฐ๊ธฐ ๊ฐ์†Œ)
low_key = cv2.convertScaleAbs(image, alpha=0.7, beta=-30)
return low_key
elif filter_type == "Haze":
# Haze ํšจ๊ณผ
haze = cv2.addWeighted(image, 0.7, np.full(image.shape, 255, dtype=np.uint8), 0.3, 0)
return haze
else:
# ํ•„ํ„ฐ๋ฅผ ์ ์šฉํ•˜์ง€ ์•Š์Œ
return image
def convert_and_save(image, filter_type, grayscale):
# ์„ ํƒํ•œ ํ•„ํ„ฐ์™€ ํ‘๋ฐฑ ๋ณ€ํ™˜ ์—ฌ๋ถ€๋ฅผ ์ด๋ฏธ์ง€์— ์ ์šฉ
filtered_image = apply_filter(image, filter_type, grayscale)
# ์ด๋ฏธ์ง€๋ฅผ ์ €์žฅ
output_path = "output.jpg"
cv2.imwrite(output_path, filtered_image)
return filtered_image, output_path
# Gradio ์ธํ„ฐํŽ˜์ด์Šค ์ •์˜
iface = gr.Interface(
fn=convert_and_save,
inputs=[
"image",
gr.Radio(["None", "Soft Glow", "Portrait Enhancer", "Warm Tone", "Cold Tone", "High-Key", "Low-Key", "Haze"], label="ํ•„ํ„ฐ ์„ ํƒ"),
gr.Checkbox(label="ํ‘๋ฐฑ ๋ณ€ํ™˜")
],
outputs=["image", "file"],
title="์ด๋ฏธ์ง€ ํ•„ํ„ฐ ๋ฐ ํ‘๋ฐฑ ๋ณ€ํ™˜๊ธฐ",
description="์ด๋ฏธ์ง€๋ฅผ ์—…๋กœ๋“œํ•˜๊ณ  ํ•„ํ„ฐ์™€ ํ‘๋ฐฑ ๋ณ€ํ™˜ ์—ฌ๋ถ€๋ฅผ ์„ ํƒํ•˜๋ฉด, ๋ณ€ํ™˜๋œ ์ด๋ฏธ์ง€๋ฅผ JPG ํŒŒ์ผ๋กœ ๋‹ค์šด๋กœ๋“œํ•  ์ˆ˜ ์žˆ์Šต๋‹ˆ๋‹ค."
)
iface.launch()