taeyeol commited on
Commit
a62776c
ยท
verified ยท
1 Parent(s): 7ea15ed

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +53 -0
app.py CHANGED
@@ -0,0 +1,53 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import gradio as gr
2
+ import cv2
3
+ import numpy as np
4
+
5
+ def apply_filter(image, filter_type):
6
+ # ํ•„ํ„ฐ์— ๋”ฐ๋ผ ์ฒ˜๋ฆฌ
7
+ if filter_type == "Soft Glow":
8
+ image = cv2.GaussianBlur(image, (15, 15), 0)
9
+ image = cv2.addWeighted(image, 1.5, cv2.GaussianBlur(image, (5, 5), 0), -0.5, 0)
10
+ elif filter_type == "Portrait Enhancer":
11
+ lab = cv2.cvtColor(image, cv2.COLOR_BGR2LAB)
12
+ l, a, b = cv2.split(lab)
13
+ l = cv2.equalizeHist(l)
14
+ enhanced = cv2.merge((l, a, b))
15
+ image = cv2.cvtColor(enhanced, cv2.COLOR_LAB2BGR)
16
+ elif filter_type == "Warm Tone":
17
+ warm_filter = np.array([[[20, 10, 0]]], dtype=np.uint8)
18
+ image = cv2.add(image, warm_filter)
19
+ elif filter_type == "Cold Tone":
20
+ cold_filter = np.array([[[-10, 0, 20]]], dtype=np.uint8)
21
+ image = cv2.add(image, cold_filter)
22
+ elif filter_type == "High-Key":
23
+ image = cv2.addWeighted(image, 1.5, np.zeros_like(image, image.dtype), 0, 50)
24
+ elif filter_type == "Low-Key":
25
+ image = cv2.addWeighted(image, 0.8, np.zeros_like(image, image.dtype), 0, -50)
26
+ elif filter_type == "Haze":
27
+ haze_filter = cv2.GaussianBlur(image, (25, 25), 10)
28
+ image = cv2.addWeighted(image, 0.8, haze_filter, 0.2, 0)
29
+ return image
30
+
31
+ def convert_and_save(image, filter_type):
32
+ # ํ•„ํ„ฐ ์ ์šฉ
33
+ filtered_image = apply_filter(image, filter_type)
34
+ # ์ด๋ฏธ์ง€๋ฅผ ํ‘๋ฐฑ์œผ๋กœ ๋ณ€ํ™˜
35
+ gray_image = cv2.cvtColor(filtered_image, cv2.COLOR_BGR2GRAY)
36
+ output_path = "output.jpg"
37
+ cv2.imwrite(output_path, gray_image)
38
+ return gray_image, output_path
39
+
40
+ # Gradio ์ธํ„ฐํŽ˜์ด์Šค ์ •์˜
41
+ iface = gr.Interface(
42
+ fn=convert_and_save,
43
+ inputs=[
44
+ gr.Image(label="์ด๋ฏธ์ง€ ์—…๋กœ๋“œ"),
45
+ gr.Radio(["Soft Glow", "Portrait Enhancer", "Warm Tone", "Cold Tone", "High-Key", "Low-Key", "Haze"], label="ํ•„ํ„ฐ ์„ ํƒ")
46
+ ],
47
+ outputs=["image", "file"],
48
+ title="์ด๋ฏธ์ง€ ํ‘๋ฐฑ ๋ณ€ํ™˜๊ธฐ",
49
+ description="์ด๋ฏธ์ง€๋ฅผ ์—…๋กœ๋“œํ•˜๊ณ  ํ•„ํ„ฐ๋ฅผ ์„ ํƒํ•œ ํ›„ ํ‘๋ฐฑ์œผ๋กœ ๋ณ€ํ™˜๋œ ์ด๋ฏธ์ง€๋ฅผ ๋‹ค์šด๋กœ๋“œํ•  ์ˆ˜ ์žˆ์Šต๋‹ˆ๋‹ค."
50
+ )
51
+
52
+ if __name__ == "__main__":
53
+ iface.launch()