File size: 2,939 Bytes
8abf425
2463a13
8060b41
 
8abf425
2463a13
7d57d7a
 
 
428752b
7d57d7a
 
428752b
7d57d7a
428752b
7d57d7a
428752b
7d57d7a
428752b
7d57d7a
428752b
7d57d7a
428752b
7d57d7a
428752b
7d57d7a
 
7d3fad5
7d57d7a
 
2463a13
7d57d7a
fd106ea
 
7d57d7a
 
 
507145e
2463a13
7d57d7a
 
 
 
7d3fad5
2463a13
8060b41
2463a13
 
 
8060b41
2463a13
 
 
 
 
 
 
 
 
 
 
 
 
7d57d7a
2463a13
7d57d7a
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
import gradio as gr
from PIL import Image
import cv2
import numpy as np

# ν•„ν„° 적용 ν•¨μˆ˜
def apply_filter(image, filter_type, intensity):
    img = np.array(image)

    if filter_type == "Soft Glow":
        gaussian = cv2.GaussianBlur(img, (15, 15), 0)
        img = cv2.addWeighted(img, 1 - intensity, gaussian, intensity, 0)
    elif filter_type == "Portrait Enhancer":
        img = cv2.bilateralFilter(img, 9, 75, 75)
    elif filter_type == "Warm Tone":
        img[:, :, 0] = cv2.add(img[:, :, 0], int(50 * intensity))  # Red 증가
    elif filter_type == "Cold Tone":
        img[:, :, 2] = cv2.add(img[:, :, 2], int(50 * intensity))  # Blue 증가
    elif filter_type == "High-Key":
        img = cv2.convertScaleAbs(img, alpha=1 + intensity, beta=int(30 * intensity))
    elif filter_type == "Low-Key":
        img = cv2.convertScaleAbs(img, alpha=1 - intensity, beta=int(-30 * intensity))
    elif filter_type == "Haze":
        img = cv2.addWeighted(img, 1 - intensity, np.full(img.shape, 255, dtype=np.uint8), intensity, 0)
    elif filter_type == "Monochrome":
        gray = cv2.cvtColor(img, cv2.COLOR_BGR2GRAY)
        img = cv2.cvtColor(gray, cv2.COLOR_GRAY2BGR)

    return Image.fromarray(img)

# 파일 μ €μž₯ ν•¨μˆ˜
def save_file(image, format):
    # 'JPG'λ₯Ό 'JPEG'둜 λ³€ν™˜
    format = "JPEG" if format.upper() == "JPG" else format.upper()
    file_path = f"processed_image.{format.lower()}"
    image.save(file_path, format=format)
    return file_path

# 이미지 λ³€ν™˜ ν›„ λ°˜ν™˜
def process_image(image, filter_type, intensity, file_format):
    filtered_image = apply_filter(image, filter_type, intensity)
    download_path = save_file(filtered_image, file_format)
    return filtered_image, download_path

# Gradio UI ꡬ성
with gr.Blocks() as demo:
    gr.Markdown("# πŸ“· 이미지 ν•„ν„° λ³€ν™˜κΈ°")
    gr.Markdown("이미지λ₯Ό μ—…λ‘œλ“œν•˜κ³  μ›ν•˜λŠ” ν•„ν„°λ₯Ό 클릭해 λ³€ν™˜ν•΄ λ³΄μ„Έμš”!")
    
    with gr.Row():
        image_input = gr.Image(type="pil", label="이미지 선택")
        with gr.Column():
            filter_selector = gr.Dropdown(
                ["Soft Glow", "Portrait Enhancer", "Warm Tone", "Cold Tone", 
                 "High-Key", "Low-Key", "Haze", "Monochrome"], 
                label="ν•„ν„° 선택"
            )
            intensity_slider = gr.Slider(0.0, 1.0, value=0.5, label="ν•„ν„° 강도")
            file_format_selector = gr.Radio(["JPG", "PNG", "PDF"], label="파일 ν˜•μ‹")
            submit_button = gr.Button("λ³€ν™˜ 적용")
    
    output_image = gr.Image(label="λ³€ν™˜λœ 이미지")
    download_button = gr.File(label="λ‹€μš΄λ‘œλ“œ 링크")

    # λ²„νŠΌ 클릭 μ‹œ λ™μž‘ μ—°κ²°
    submit_button.click(
        process_image, 
        inputs=[image_input, filter_selector, intensity_slider, file_format_selector], 
        outputs=[output_image, download_button]
    )

# μ‹€ν–‰
if __name__ == "__main__":
    demo.launch()