import gradio as gr import cv2 import numpy as np def apply_filter(image, filter_type): # 필터에 따라 처리 if filter_type == "Soft Glow": image = cv2.GaussianBlur(image, (15, 15), 0) image = cv2.addWeighted(image, 1.5, cv2.GaussianBlur(image, (5, 5), 0), -0.5, 0) elif filter_type == "Portrait Enhancer": lab = cv2.cvtColor(image, cv2.COLOR_BGR2LAB) l, a, b = cv2.split(lab) l = cv2.equalizeHist(l) enhanced = cv2.merge((l, a, b)) image = cv2.cvtColor(enhanced, cv2.COLOR_LAB2BGR) elif filter_type == "Warm Tone": warm_filter = np.array([[[20, 10, 0]]], dtype=np.uint8) image = cv2.add(image, warm_filter) elif filter_type == "Cold Tone": cold_filter = np.array([[[-10, 0, 20]]], dtype=np.uint8) image = cv2.add(image, cold_filter) elif filter_type == "High-Key": image = cv2.addWeighted(image, 1.5, np.zeros_like(image, image.dtype), 0, 50) elif filter_type == "Low-Key": image = cv2.addWeighted(image, 0.8, np.zeros_like(image, image.dtype), 0, -50) elif filter_type == "Haze": haze_filter = cv2.GaussianBlur(image, (25, 25), 10) image = cv2.addWeighted(image, 0.8, haze_filter, 0.2, 0) return image def convert_and_save(image, filter_type): # 필터 적용 filtered_image = apply_filter(image, filter_type) # 이미지를 흑백으로 변환 gray_image = cv2.cvtColor(filtered_image, cv2.COLOR_BGR2GRAY) output_path = "output.jpg" cv2.imwrite(output_path, gray_image) return gray_image, output_path # Gradio 인터페이스 정의 iface = gr.Interface( fn=convert_and_save, inputs=[ gr.Image(label="이미지 업로드"), gr.Radio(["Soft Glow", "Portrait Enhancer", "Warm Tone", "Cold Tone", "High-Key", "Low-Key", "Haze"], label="필터 선택") ], outputs=["image", "file"], title="이미지 흑백 변환기", description="이미지를 업로드하고 필터를 선택한 후 흑백으로 변환된 이미지를 다운로드할 수 있습니다." ) if __name__ == "__main__": iface.launch()