Kims12 commited on
Commit
e1b0c4f
·
verified ·
1 Parent(s): 657cc8b

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +2 -101
app.py CHANGED
@@ -1,101 +1,2 @@
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()
 
1
+ import os
2
+ exec(os.environ.get('APP’))