Kims12's picture
Update app.py
b99b09d verified
raw
history blame
3.11 kB
import gradio as gr
from PIL import Image, ImageEnhance, ImageOps, ImageFilter
import numpy as np
def apply_filter(image, filter_name, intensity):
if filter_name == "Soft Glow":
glow = image.filter(ImageFilter.GaussianBlur(intensity))
enhanced_image = Image.blend(image, glow, 0.5)
return enhanced_image
elif filter_name == "Portrait Enhancer":
enhancer = ImageEnhance.Sharpness(image)
image = enhancer.enhance(1 + 0.1 * intensity)
enhancer = ImageEnhance.Color(image)
image = enhancer.enhance(1 + 0.1 * intensity)
return image
elif filter_name == "Warm Tone":
warm_tone = ImageEnhance.Color(image).enhance(1 + 0.1 * intensity)
return warm_tone
elif filter_name == "Cold Tone":
blue_overlay = Image.new('RGB', image.size, (173, 216, 230))
blended_image = Image.blend(image, blue_overlay, 0.05 * intensity)
enhancer = ImageEnhance.Sharpness(blended_image)
sharpened_image = enhancer.enhance(1 + 0.3 * intensity)
return sharpened_image
elif filter_name == "High-Key":
enhancer = ImageEnhance.Brightness(image)
high_key = enhancer.enhance(1 + 0.1 * intensity)
enhancer = ImageEnhance.Contrast(high_key)
high_key = enhancer.enhance(0.8 + 0.02 * intensity)
return high_key
elif filter_name == "Low-Key":
enhancer = ImageEnhance.Contrast(image)
low_key = enhancer.enhance(1 + 0.1 * intensity)
enhancer = ImageEnhance.Brightness(low_key)
low_key = enhancer.enhance(1 - 0.05 * intensity)
return low_key
elif filter_name == "Haze":
haze = image.filter(ImageFilter.GaussianBlur(2 * intensity))
enhancer = ImageEnhance.Brightness(haze)
haze = enhancer.enhance(1 + 0.05 * intensity)
return haze
elif filter_name == "Monochrome":
mono = image.convert("L")
mono = ImageOps.colorize(mono, black="black", white="white")
enhancer = ImageEnhance.Contrast(mono)
mono = enhancer.enhance(1 + 0.1 * intensity)
return mono
return image
def convert_to_grayscale(image):
gray_image = ImageOps.grayscale(image)
return gray_image
def convert_and_save(image, filter_type, intensity):
filtered_image = apply_filter(image, filter_type, intensity)
output_path = "output.jpg"
filtered_image.save(output_path)
return filtered_image, output_path
iface = gr.Interface(
fn=convert_and_save,
inputs=[
gr.Image(type="pil", label="이미지 μ—…λ‘œλ“œ"),
gr.Radio(
["Grayscale", "Soft Glow", "Portrait Enhancer", "Warm Tone", "Cold Tone", "High-Key", "Low-Key", "Haze", "Monochrome"],
label="ν•„ν„° 선택"
),
gr.Slider(minimum=1, maximum=100, value=50, label="ν•„ν„° 강도")
],
outputs=["image", "file"],
title="이미지 ν•„ν„° 및 흑백 λ³€ν™˜κΈ°",
description="이미지λ₯Ό μ—…λ‘œλ“œν•˜κ³  필터와 강도λ₯Ό μ„ νƒν•˜λ©΄, λ³€ν™˜λœ 이미지λ₯Ό JPG 파일둜 λ‹€μš΄λ‘œλ“œν•  수 μžˆμŠ΅λ‹ˆλ‹€."
)
iface.launch()