import gradio as gr import cv2 import numpy as np from gradio_imageslider import ImageSlider def convert_to_grayscale(image): # 이미지를 흑백으로 변환 gray_image = cv2.cvtColor(image, cv2.COLOR_BGR2GRAY) return gray_image def convert_and_save(image): # 이미지를 흑백으로 변환 gray_image = convert_to_grayscale(image) # 변환된 이미지를 JPG로 저장 output_path = "output.jpg" cv2.imwrite(output_path, gray_image) # 슬라이드 출력용 리스트 [원본이미지, 흑백이미지] 와 저장된 파일 경로 반환 return [image, gray_image], output_path # Gradio 인터페이스 정의 iface = gr.Interface( fn=convert_and_save, inputs="image", outputs=[ImageSlider(label="변경 전후 보기"), "file"], title="이미지 흑백 변환기", description="이미지를 업로드하면 흑백으로 변환하고, 결과 이미지를 슬라이드로 비교해볼 수 있으며, JPG 파일도 다운로드할 수 있습니다." ) if __name__ == "__main__": iface.launch()