Kims12 commited on
Commit
657cc8b
ยท
verified ยท
1 Parent(s): 1d7bc9d

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +101 -2
app.py CHANGED
@@ -1,2 +1,101 @@
1
- import os
2
- exec(os.environ.get('APP'))
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import gradio as gr
2
+ from PIL import Image, ImageEnhance, ImageFilter
3
+
4
+ # ํ•„ํ„ฐ ์ ์šฉ ํ•จ์ˆ˜
5
+ def apply_filter(image, filter_type, intensity):
6
+ image = image.convert("RGB")
7
+
8
+ if filter_type == "Soft Glow":
9
+ return image.filter(ImageFilter.GaussianBlur(radius=intensity))
10
+ elif filter_type == "Portrait Enhancer":
11
+ enhancer = ImageEnhance.Color(image)
12
+ return enhancer.enhance(1 + intensity / 10)
13
+ elif filter_type == "Warm Tone":
14
+ r, g, b = image.split()
15
+ r = r.point(lambda i: min(255, i + intensity * 10))
16
+ return Image.merge("RGB", (r, g, b))
17
+ elif filter_type == "Cold Tone":
18
+ r, g, b = image.split()
19
+ b = b.point(lambda i: min(255, i + intensity * 10))
20
+ return Image.merge("RGB", (r, g, b))
21
+ elif filter_type == "High-Key":
22
+ enhancer = ImageEnhance.Brightness(image)
23
+ return enhancer.enhance(1 + intensity / 10)
24
+ elif filter_type == "Low-Key":
25
+ enhancer = ImageEnhance.Brightness(image)
26
+ return enhancer.enhance(1 - intensity / 10)
27
+ elif filter_type == "Haze":
28
+ return image.filter(ImageFilter.BLUR)
29
+ elif filter_type == "Monochrome":
30
+ return image.convert("L").convert("RGB")
31
+ else:
32
+ return image
33
+
34
+ # ์ดˆ๊ธฐ๊ฐ’ ์„ค์ • ํ•จ์ˆ˜
35
+ def set_initial_intensity(filter_type):
36
+ # ํ•„ํ„ฐ๋ณ„ ์ดˆ๊ธฐ๊ฐ’ ์ง€์ •
37
+ initial_values = {
38
+ "Soft Glow": 3,
39
+ "Portrait Enhancer": 2,
40
+ "Warm Tone": 5,
41
+ "Cold Tone": 5,
42
+ "High-Key": 3,
43
+ "Low-Key": 3,
44
+ "Haze": 2,
45
+ "Monochrome": 0
46
+ }
47
+ return initial_values.get(filter_type, 0)
48
+
49
+ # Gradio UI ๊ตฌ์„ฑ
50
+ with gr.Blocks() as demo:
51
+ gr.Markdown("# ์ธ๋ฌผ ์‚ฌ์ง„ ํ•„ํ„ฐ ์ ์šฉ๊ธฐ")
52
+
53
+ with gr.Row():
54
+ with gr.Column():
55
+ image_input = gr.Image(type="pil", label="์ด๋ฏธ์ง€ ์—…๋กœ๋“œ")
56
+ filter_type = gr.Dropdown(
57
+ choices=[
58
+ "Soft Glow", "Portrait Enhancer", "Warm Tone",
59
+ "Cold Tone", "High-Key", "Low-Key", "Haze", "Monochrome"
60
+ ],
61
+ value="Soft Glow", # ๊ธฐ๋ณธ๊ฐ’ ์„ค์ •
62
+ label="ํ•„ํ„ฐ ์„ ํƒ"
63
+ )
64
+ intensity = gr.Slider(
65
+ 0, 10, value=3, step=1, label="ํ•„ํ„ฐ ๊ฐ•๋„"
66
+ )
67
+ with gr.Column():
68
+ filtered_image = gr.Image(type="pil", label="ํ•„ํ„ฐ ์ ์šฉ ์ด๋ฏธ์ง€")
69
+
70
+ # ํ•„ํ„ฐ ์ ์šฉ ๋ฐ ๊ฒฐ๊ณผ ์—ฐ๊ฒฐ
71
+ def process_image(image, filter_type, intensity):
72
+ if image is None:
73
+ return None
74
+ filtered_image = apply_filter(image, filter_type, intensity)
75
+ return filtered_image
76
+
77
+ def update_intensity_on_filter_change(filter_type):
78
+ return set_initial_intensity(filter_type)
79
+
80
+ # UI ์ด๋ฒคํŠธ ์—ฐ๊ฒฐ
81
+ filter_type.change(
82
+ update_intensity_on_filter_change,
83
+ inputs=filter_type,
84
+ outputs=intensity
85
+ )
86
+
87
+ image_input.change(
88
+ process_image,
89
+ inputs=[image_input, filter_type, intensity],
90
+ outputs=[filtered_image]
91
+ )
92
+
93
+ intensity.change(
94
+ process_image,
95
+ inputs=[image_input, filter_type, intensity],
96
+ outputs=[filtered_image]
97
+ )
98
+
99
+ # ์•ฑ ์‹คํ–‰
100
+ if __name__ == "__main__":
101
+ demo.launch()