File size: 3,109 Bytes
ec0dbf0 b99b09d ec0dbf0 b99b09d 0bee58f b99b09d ec0dbf0 b99b09d ec0dbf0 b99b09d ec0dbf0 b99b09d ec0dbf0 58f5984 b99b09d 58f5984 0bee58f ec0dbf0 b99b09d ee7d7d6 ec0dbf0 ee7d7d6 b99b09d 58f5984 b99b09d 58f5984 0bee58f 841fb88 ee7d7d6 ec0dbf0 ee7d7d6 0bee58f ec0dbf0 |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 |
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()
|