Update app.py
Browse files
app.py
CHANGED
|
@@ -1,33 +1,58 @@
|
|
| 1 |
import gradio as gr
|
| 2 |
-
from PIL import Image
|
| 3 |
|
| 4 |
-
|
| 5 |
-
|
| 6 |
-
|
| 7 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 8 |
|
| 9 |
# Gradio UI ๊ตฌ์ฑ
|
| 10 |
with gr.Blocks() as app:
|
| 11 |
-
gr.Markdown("#
|
| 12 |
|
| 13 |
with gr.Row():
|
| 14 |
-
|
| 15 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 16 |
|
| 17 |
-
|
| 18 |
-
|
|
|
|
| 19 |
|
| 20 |
-
|
| 21 |
-
fn=
|
| 22 |
-
inputs=input_image,
|
| 23 |
outputs=output_image
|
| 24 |
)
|
| 25 |
-
|
| 26 |
-
download_button.click(
|
| 27 |
-
fn=lambda img: img.save("converted_image.jpg", "JPEG") or "converted_image.jpg",
|
| 28 |
-
inputs=output_image,
|
| 29 |
-
outputs=gr.File(label="JPG ํ์ผ ๋ค์ด๋ก๋")
|
| 30 |
-
)
|
| 31 |
|
| 32 |
# ์คํ
|
| 33 |
if __name__ == "__main__":
|
|
|
|
| 1 |
import gradio as gr
|
| 2 |
+
from PIL import Image, ImageEnhance, ImageOps, ImageFilter
|
| 3 |
|
| 4 |
+
# ํํฐ ํจ๊ณผ ์ ์
|
| 5 |
+
def apply_filter(image, filter_name, intensity):
|
| 6 |
+
if filter_name == "Soft Glow":
|
| 7 |
+
return image.filter(ImageFilter.GaussianBlur(intensity))
|
| 8 |
+
elif filter_name == "Portrait Enhancer":
|
| 9 |
+
enhancer = ImageEnhance.Brightness(image)
|
| 10 |
+
return enhancer.enhance(1 + (intensity / 100))
|
| 11 |
+
elif filter_name == "Warm Tone":
|
| 12 |
+
red, green, blue = image.split()
|
| 13 |
+
red = red.point(lambda p: min(255, p + intensity))
|
| 14 |
+
return Image.merge("RGB", (red, green, blue))
|
| 15 |
+
elif filter_name == "Cold Tone":
|
| 16 |
+
red, green, blue = image.split()
|
| 17 |
+
blue = blue.point(lambda p: min(255, p + intensity))
|
| 18 |
+
return Image.merge("RGB", (red, green, blue))
|
| 19 |
+
elif filter_name == "High-Key":
|
| 20 |
+
enhancer = ImageEnhance.Brightness(image)
|
| 21 |
+
return enhancer.enhance(1.5 + (intensity / 200))
|
| 22 |
+
elif filter_name == "Low-Key":
|
| 23 |
+
enhancer = ImageEnhance.Contrast(image)
|
| 24 |
+
return enhancer.enhance(0.8 - (intensity / 200))
|
| 25 |
+
elif filter_name == "Haze":
|
| 26 |
+
return image.filter(ImageFilter.BLUR)
|
| 27 |
+
elif filter_name == "Monochrome":
|
| 28 |
+
return ImageOps.grayscale(image)
|
| 29 |
+
else:
|
| 30 |
+
return image
|
| 31 |
|
| 32 |
# Gradio UI ๊ตฌ์ฑ
|
| 33 |
with gr.Blocks() as app:
|
| 34 |
+
gr.Markdown("# ์ธ๋ฌผ ์ฌ์ง ํํฐ ์ ์ฉ ์ฑ")
|
| 35 |
|
| 36 |
with gr.Row():
|
| 37 |
+
with gr.Column():
|
| 38 |
+
input_image = gr.Image(label="์๋ณธ ์ด๋ฏธ์ง", type="pil")
|
| 39 |
+
filter_name = gr.Dropdown(
|
| 40 |
+
["Soft Glow", "Portrait Enhancer", "Warm Tone", "Cold Tone",
|
| 41 |
+
"High-Key", "Low-Key", "Haze", "Monochrome"],
|
| 42 |
+
label="ํํฐ ์ ํ"
|
| 43 |
+
)
|
| 44 |
+
intensity = gr.Slider(0, 100, step=1, label="ํํฐ ๊ฐ๋")
|
| 45 |
+
apply_button = gr.Button("ํํฐ ์ ์ฉ")
|
| 46 |
|
| 47 |
+
with gr.Column():
|
| 48 |
+
output_image = gr.Image(label="ํํฐ ์ ์ฉ ์ด๋ฏธ์ง", type="pil")
|
| 49 |
+
comparison = gr.Slider([("Before", input_image), ("After", output_image)], label="๋ณ๊ฒฝ ์ ํ ๋น๊ต")
|
| 50 |
|
| 51 |
+
apply_button.click(
|
| 52 |
+
fn=apply_filter,
|
| 53 |
+
inputs=[input_image, filter_name, intensity],
|
| 54 |
outputs=output_image
|
| 55 |
)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 56 |
|
| 57 |
# ์คํ
|
| 58 |
if __name__ == "__main__":
|