Update app.py
Browse files
app.py
CHANGED
@@ -1,71 +1,76 @@
|
|
1 |
import gradio as gr
|
2 |
-
import
|
3 |
import numpy as np
|
4 |
|
5 |
-
def apply_filter(image,
|
6 |
-
|
7 |
-
|
|
|
|
|
8 |
|
9 |
-
|
10 |
-
|
11 |
-
|
12 |
-
|
13 |
-
|
14 |
-
return
|
15 |
-
|
16 |
-
|
17 |
-
|
18 |
-
|
19 |
-
|
20 |
-
|
21 |
-
|
22 |
-
|
23 |
-
|
24 |
-
|
25 |
-
|
26 |
-
|
27 |
-
|
28 |
-
|
29 |
-
|
30 |
-
|
31 |
-
|
32 |
-
[0.0, 0.0, 1.0 - 0.2 * normalized_intensity]])
|
33 |
-
warm_image = cv2.transform(image, increase_red)
|
34 |
-
return warm_image
|
35 |
-
elif filter_type == "Cold Tone":
|
36 |
-
increase_blue = np.array([[1.0 - 0.2 * normalized_intensity, 0.0, 0.0],
|
37 |
-
[0.0, 1.0, 0.0],
|
38 |
-
[0.0, 0.0, 1.0 + 0.2 * normalized_intensity]])
|
39 |
-
cold_image = cv2.transform(image, increase_blue)
|
40 |
-
return cold_image
|
41 |
-
elif filter_type == "High-Key":
|
42 |
-
high_key = cv2.convertScaleAbs(image, alpha=1.0 + 0.2 * normalized_intensity, beta=30)
|
43 |
return high_key
|
44 |
-
|
45 |
-
|
|
|
|
|
|
|
|
|
46 |
return low_key
|
47 |
-
|
48 |
-
|
|
|
|
|
|
|
49 |
return haze
|
50 |
-
|
51 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
52 |
|
53 |
def convert_to_grayscale(image):
|
54 |
-
gray_image =
|
55 |
return gray_image
|
56 |
|
57 |
def convert_and_save(image, filter_type, intensity):
|
58 |
filtered_image = apply_filter(image, filter_type, intensity)
|
59 |
output_path = "output.jpg"
|
60 |
-
|
61 |
return filtered_image, output_path
|
62 |
|
63 |
iface = gr.Interface(
|
64 |
fn=convert_and_save,
|
65 |
inputs=[
|
66 |
-
"
|
67 |
gr.Radio(
|
68 |
-
["Grayscale", "Soft Glow", "Portrait Enhancer", "Warm Tone", "Cold Tone", "High-Key", "Low-Key", "Haze"],
|
69 |
label="νν° μ ν"
|
70 |
),
|
71 |
gr.Slider(minimum=1, maximum=100, value=50, label="νν° κ°λ")
|
|
|
1 |
import gradio as gr
|
2 |
+
from PIL import Image, ImageEnhance, ImageOps, ImageFilter
|
3 |
import numpy as np
|
4 |
|
5 |
+
def apply_filter(image, filter_name, intensity):
|
6 |
+
if filter_name == "Soft Glow":
|
7 |
+
glow = image.filter(ImageFilter.GaussianBlur(intensity))
|
8 |
+
enhanced_image = Image.blend(image, glow, 0.5)
|
9 |
+
return enhanced_image
|
10 |
|
11 |
+
elif filter_name == "Portrait Enhancer":
|
12 |
+
enhancer = ImageEnhance.Sharpness(image)
|
13 |
+
image = enhancer.enhance(1 + 0.1 * intensity)
|
14 |
+
enhancer = ImageEnhance.Color(image)
|
15 |
+
image = enhancer.enhance(1 + 0.1 * intensity)
|
16 |
+
return image
|
17 |
+
|
18 |
+
elif filter_name == "Warm Tone":
|
19 |
+
warm_tone = ImageEnhance.Color(image).enhance(1 + 0.1 * intensity)
|
20 |
+
return warm_tone
|
21 |
+
|
22 |
+
elif filter_name == "Cold Tone":
|
23 |
+
blue_overlay = Image.new('RGB', image.size, (173, 216, 230))
|
24 |
+
blended_image = Image.blend(image, blue_overlay, 0.05 * intensity)
|
25 |
+
enhancer = ImageEnhance.Sharpness(blended_image)
|
26 |
+
sharpened_image = enhancer.enhance(1 + 0.3 * intensity)
|
27 |
+
return sharpened_image
|
28 |
+
|
29 |
+
elif filter_name == "High-Key":
|
30 |
+
enhancer = ImageEnhance.Brightness(image)
|
31 |
+
high_key = enhancer.enhance(1 + 0.1 * intensity)
|
32 |
+
enhancer = ImageEnhance.Contrast(high_key)
|
33 |
+
high_key = enhancer.enhance(0.8 + 0.02 * intensity)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
34 |
return high_key
|
35 |
+
|
36 |
+
elif filter_name == "Low-Key":
|
37 |
+
enhancer = ImageEnhance.Contrast(image)
|
38 |
+
low_key = enhancer.enhance(1 + 0.1 * intensity)
|
39 |
+
enhancer = ImageEnhance.Brightness(low_key)
|
40 |
+
low_key = enhancer.enhance(1 - 0.05 * intensity)
|
41 |
return low_key
|
42 |
+
|
43 |
+
elif filter_name == "Haze":
|
44 |
+
haze = image.filter(ImageFilter.GaussianBlur(2 * intensity))
|
45 |
+
enhancer = ImageEnhance.Brightness(haze)
|
46 |
+
haze = enhancer.enhance(1 + 0.05 * intensity)
|
47 |
return haze
|
48 |
+
|
49 |
+
elif filter_name == "Monochrome":
|
50 |
+
mono = image.convert("L")
|
51 |
+
mono = ImageOps.colorize(mono, black="black", white="white")
|
52 |
+
enhancer = ImageEnhance.Contrast(mono)
|
53 |
+
mono = enhancer.enhance(1 + 0.1 * intensity)
|
54 |
+
return mono
|
55 |
+
|
56 |
+
return image
|
57 |
|
58 |
def convert_to_grayscale(image):
|
59 |
+
gray_image = ImageOps.grayscale(image)
|
60 |
return gray_image
|
61 |
|
62 |
def convert_and_save(image, filter_type, intensity):
|
63 |
filtered_image = apply_filter(image, filter_type, intensity)
|
64 |
output_path = "output.jpg"
|
65 |
+
filtered_image.save(output_path)
|
66 |
return filtered_image, output_path
|
67 |
|
68 |
iface = gr.Interface(
|
69 |
fn=convert_and_save,
|
70 |
inputs=[
|
71 |
+
gr.Image(type="pil", label="μ΄λ―Έμ§ μ
λ‘λ"),
|
72 |
gr.Radio(
|
73 |
+
["Grayscale", "Soft Glow", "Portrait Enhancer", "Warm Tone", "Cold Tone", "High-Key", "Low-Key", "Haze", "Monochrome"],
|
74 |
label="νν° μ ν"
|
75 |
),
|
76 |
gr.Slider(minimum=1, maximum=100, value=50, label="νν° κ°λ")
|