Image_Upscaler / app.py
jpjp9292's picture
Update app.py
e8edb87 verified
raw
history blame
1.41 kB
import gradio as gr
import cv2
import numpy as np
# ์ด๋ฏธ์ง€ ์—…์Šค์ผ€์ผ ํ•จ์ˆ˜
def upscale_image(input_image, upscale_factor):
upscale_factor = int(upscale_factor) # ์—…์Šค์ผ€์ผ ๋น„์œจ์„ ์ •์ˆ˜ํ˜•์œผ๋กœ ๋ณ€ํ™˜
# ์ž…๋ ฅ ์ด๋ฏธ์ง€๋ฅผ ์ฃผ์–ด์ง„ ์—…์Šค์ผ€์ผ ๋น„์œจ๋กœ ํฌ๊ธฐ ๋ณ€๊ฒฝ (๋ณด๊ฐ„๋ฒ•: INTER_CUBIC)
output_image = cv2.resize(input_image, None, fx=upscale_factor, fy=upscale_factor, interpolation=cv2.INTER_CUBIC)
# ์ด๋ฏธ์ง€๋ฅผ PNG ํ˜•์‹์œผ๋กœ ์ €์žฅ
output_image_bgr = cv2.cvtColor(output_image, cv2.COLOR_RGB2BGR) # RGB์—์„œ BGR๋กœ ๋ณ€ํ™˜
output_filename = "upscaled_image.png"
cv2.imwrite(output_filename, output_image_bgr)
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=upscale_image,
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)