import gradio as gr import cv2 import numpy as np # 이미지 업스케일 함수 def upscale_image(input_image, radio_input): upscale_factor = int(radio_input) # 업스케일 비율을 정수형으로 변환 # 입력 이미지를 주어진 업스케일 비율로 크기 변경 (보간법: INTER_CUBIC) output_image = cv2.resize(input_image, None, fx=upscale_factor, fy=upscale_factor, interpolation=cv2.INTER_CUBIC) return output_image # 업스케일 이미지를 PNG로 저장하는 함수 def save_image_as_png(input_image, radio_input): upscale_factor = int(radio_input) # 업스케일 비율을 정수형으로 변환 # 입력 이미지를 주어진 업스케일 비율로 크기 변경 (보간법: INTER_CUBIC) output_image = cv2.resize(input_image, None, fx=upscale_factor, fy=upscale_factor, interpolation=cv2.INTER_CUBIC) # 이미지를 PNG 형식으로 저장 output_filename = "upscaled_image.png" cv2.imwrite(output_filename, output_image) return output_filename # 인터페이스 설명 DESCRIPTION = """ 이미지의 크기와 품질을 향상시켜 보세요! (you can increase the size and quality of your images) """ # 업스케일 레벨 선택 라디오 버튼 radio_input = gr.Radio(label="업스케일 레벨 선택 (Select Upscaling level)", choices=[2, 4, 6, 8, 10], value=2) # Gradio 인터페이스 정의 demo = gr.Interface( fn=save_image_as_png, inputs=[gr.Image(label="입력 이미지 (Input Image)", type="numpy"), radio_input], outputs=gr.File(label="업스케일된 이미지 다운로드 (Download Upscaled Image)"), title="Image Upscaler", description=DESCRIPTION ) # 인터페이스 실행 demo.launch(show_api=False)