Update app.py
Browse files
app.py
CHANGED
@@ -2,8 +2,12 @@ import gradio as gr
|
|
2 |
import cv2
|
3 |
import numpy as np
|
4 |
from PIL import Image, ImageEnhance
|
|
|
5 |
|
6 |
def apply_filter(image, filter_type, intensity):
|
|
|
|
|
|
|
7 |
# ๊ฐ๋๋ฅผ 0.0์์ 1.0 ์ฌ์ด๋ก ์ ๊ทํ
|
8 |
normalized_intensity = intensity / 100.0
|
9 |
|
@@ -62,9 +66,7 @@ def convert_to_grayscale(image):
|
|
62 |
|
63 |
def convert_and_save(image, filter_type, intensity):
|
64 |
filtered_image = apply_filter(image, filter_type, intensity)
|
65 |
-
|
66 |
-
cv2.imwrite(output_path, filtered_image)
|
67 |
-
return filtered_image, output_path
|
68 |
|
69 |
def get_filter_description(filter_type):
|
70 |
descriptions = {
|
@@ -92,10 +94,18 @@ with gr.Blocks() as iface:
|
|
92 |
description_output = gr.Markdown(get_filter_description("Soft Glow"))
|
93 |
|
94 |
with gr.Column():
|
95 |
-
|
|
|
|
|
96 |
|
97 |
-
filter_input.change(fn=lambda filter_type: get_filter_description(filter_type), inputs=filter_input, outputs=description_output)
|
98 |
process_button = gr.Button("ํํฐ ์ ์ฉ")
|
99 |
-
process_button.click(
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
100 |
|
101 |
iface.launch()
|
|
|
2 |
import cv2
|
3 |
import numpy as np
|
4 |
from PIL import Image, ImageEnhance
|
5 |
+
from gradio_imageslider import ImageSlider
|
6 |
|
7 |
def apply_filter(image, filter_type, intensity):
|
8 |
+
# PIL ์ด๋ฏธ์ง๋ฅผ numpy array๋ก ๋ณํ
|
9 |
+
image = np.array(image)
|
10 |
+
|
11 |
# ๊ฐ๋๋ฅผ 0.0์์ 1.0 ์ฌ์ด๋ก ์ ๊ทํ
|
12 |
normalized_intensity = intensity / 100.0
|
13 |
|
|
|
66 |
|
67 |
def convert_and_save(image, filter_type, intensity):
|
68 |
filtered_image = apply_filter(image, filter_type, intensity)
|
69 |
+
return Image.fromarray(image), Image.fromarray(filtered_image) # ์๋ณธ๊ณผ ํํฐ ์ ์ฉ๋ ์ด๋ฏธ์ง๋ฅผ ๋ฐํ
|
|
|
|
|
70 |
|
71 |
def get_filter_description(filter_type):
|
72 |
descriptions = {
|
|
|
94 |
description_output = gr.Markdown(get_filter_description("Soft Glow"))
|
95 |
|
96 |
with gr.Column():
|
97 |
+
slider_output = ImageSlider(label="Before and After", type="pil")
|
98 |
+
|
99 |
+
filter_input.change(fn=get_filter_description, inputs=filter_input, outputs=description_output)
|
100 |
|
|
|
101 |
process_button = gr.Button("ํํฐ ์ ์ฉ")
|
102 |
+
process_button.click(
|
103 |
+
fn=convert_and_save,
|
104 |
+
inputs=[image_input, filter_input, intensity_slider],
|
105 |
+
outputs=slider_output
|
106 |
+
)
|
107 |
+
|
108 |
+
iface.title = "์ธ๋ฌผ ์ฌ์ง์ ์ต์ ํ๋ ํํฐ"
|
109 |
+
iface.description = "์ธ๋ฌผ ์ฌ์ง์ ์ต์ ํ๋ ๋ค์ํ ํํฐ๋ฅผ ์ ์ฉํ ์ ์์ต๋๋ค."
|
110 |
|
111 |
iface.launch()
|