Spaces:
Running
Running
File size: 1,726 Bytes
4ede2da f42ceb6 4ede2da a78ac24 4ede2da f42ceb6 4ede2da a78ac24 48e3649 4ede2da a78ac24 4ede2da a78ac24 4ede2da 48e3649 4ede2da a78ac24 |
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 |
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)
|