Kims12 commited on
Commit
ec0dbf0
โ€ข
1 Parent(s): 9b607f2

Create app.py

Browse files
Files changed (1) hide show
  1. app.py +58 -0
app.py ADDED
@@ -0,0 +1,58 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import gradio as gr
2
+ import cv2
3
+ import numpy as np
4
+
5
+ def apply_filter(image, filter_type):
6
+ if filter_type == "Soft Glow":
7
+ # Soft Glow ํšจ๊ณผ
8
+ gaussian = cv2.GaussianBlur(image, (15, 15), 0)
9
+ soft_glow = cv2.addWeighted(image, 0.5, gaussian, 0.5, 0)
10
+ return soft_glow
11
+ elif filter_type == "Portrait Enhancer":
12
+ # ๊ฐ„๋‹จํ•œ ํฌํŠธ๋ ˆ์ดํŠธ ํ–ฅ์ƒ (์˜ˆ: ๋Œ€๋น„ ๋ฐ ๋ฐ๊ธฐ ์กฐ์ •)
13
+ enhanced = cv2.detailEnhance(image, sigma_s=10, sigma_r=0.15)
14
+ return enhanced
15
+ elif filter_type == "Warm Tone":
16
+ # ๋”ฐ๋œปํ•œ ํ†ค ํšจ๊ณผ
17
+ warm_image = cv2.applyColorMap(image, cv2.COLORMAP_AUTUMN)
18
+ return warm_image
19
+ elif filter_type == "Cold Tone":
20
+ # ์ฐจ๊ฐ€์šด ํ†ค ํšจ๊ณผ
21
+ cold_image = cv2.applyColorMap(image, cv2.COLORMAP_WINTER)
22
+ return cold_image
23
+ elif filter_type == "High-Key":
24
+ # High-Key ํšจ๊ณผ (๋ฐ๊ธฐ ์ฆ๊ฐ€)
25
+ high_key = cv2.convertScaleAbs(image, alpha=1.2, beta=30)
26
+ return high_key
27
+ elif filter_type == "Low-Key":
28
+ # Low-Key ํšจ๊ณผ (๋ฐ๊ธฐ ๊ฐ์†Œ)
29
+ low_key = cv2.convertScaleAbs(image, alpha=0.7, beta=-30)
30
+ return low_key
31
+ elif filter_type == "Haze":
32
+ # Haze ํšจ๊ณผ
33
+ haze = cv2.addWeighted(image, 0.7, np.full(image.shape, 255, dtype=np.uint8), 0.3, 0)
34
+ return haze
35
+ else:
36
+ # ํ•„ํ„ฐ๋ฅผ ์ ์šฉํ•˜์ง€ ์•Š์Œ
37
+ return image
38
+
39
+ def convert_and_save(image, filter_type):
40
+ # ์„ ํƒํ•œ ํ•„ํ„ฐ๋ฅผ ์ด๋ฏธ์ง€์— ์ ์šฉ
41
+ filtered_image = apply_filter(image, filter_type)
42
+ # ์ด๋ฏธ์ง€๋ฅผ ํ‘๋ฐฑ์œผ๋กœ ๋ณ€ํ™˜
43
+ gray_image = convert_to_grayscale(filtered_image)
44
+ # ์ด๋ฏธ์ง€๋ฅผ ์ €์žฅ
45
+ output_path = "output.jpg"
46
+ cv2.imwrite(output_path, gray_image)
47
+ return gray_image, output_path
48
+
49
+ # Gradio ์ธํ„ฐํŽ˜์ด์Šค ์ •์˜
50
+ iface = gr.Interface(
51
+ fn=convert_and_save,
52
+ inputs=["image", gr.Radio(["Soft Glow", "Portrait Enhancer", "Warm Tone", "Cold Tone", "High-Key", "Low-Key", "Haze"], label="ํ•„ํ„ฐ ์„ ํƒ")],
53
+ outputs=["image", "file"],
54
+ title="์ด๋ฏธ์ง€ ํ‘๋ฐฑ ๋ณ€ํ™˜๊ธฐ",
55
+ description="์ด๋ฏธ์ง€๋ฅผ ์—…๋กœ๋“œํ•˜๊ณ  ํ•„ํ„ฐ๋ฅผ ์„ ํƒํ•˜๋ฉด, ํ‘๋ฐฑ์œผ๋กœ ๋ณ€ํ™˜ํ•˜๊ณ  JPG ํŒŒ์ผ๋กœ ๋‹ค์šด๋กœ๋“œํ•  ์ˆ˜ ์žˆ์Šต๋‹ˆ๋‹ค."
56
+ )
57
+
58
+ iface.launch()