Spaces:
Sleeping
Sleeping
File size: 2,198 Bytes
4ede2da eb901ad 4ede2da f3b13b5 eb901ad a78ac24 4ede2da eb901ad f42ceb6 eb901ad 48e3649 4ede2da f3b13b5 eb901ad 088c8d3 eb901ad a78ac24 4ede2da eb901ad 088c8d3 4ede2da 48e3649 4ede2da eb901ad |
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 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 |
import gradio as gr
import numpy as np
import os
from PIL import Image
def upscale_image(input_image, upscale_factor):
try:
# PIL Image๋ก ๋ณํ
if isinstance(input_image, np.ndarray):
input_image = Image.fromarray(input_image)
# ํ์ฌ ์ด๋ฏธ์ง ํฌ๊ธฐ
current_width, current_height = input_image.size
# ์๋ก์ด ํฌ๊ธฐ ๊ณ์ฐ
new_width = int(current_width * upscale_factor)
new_height = int(current_height * upscale_factor)
# ์ด๋ฏธ์ง ๋ฆฌ์ฌ์ด์ฆ
output_image = input_image.resize((new_width, new_height), Image.Resampling.LANCZOS)
# ์์ ํ์ผ ์ ์ฅ์ ์ํ ๋๋ ํ ๋ฆฌ ํ์ธ ๋ฐ ์์ฑ
if not os.path.exists("temp"):
os.makedirs("temp")
# ๊ฒฐ๊ณผ ์ด๋ฏธ์ง ์ ์ฅ
output_path = os.path.join("temp", "upscaled_image.png")
output_image.save(output_path, "PNG", quality=100)
return output_path
except Exception as e:
print(f"Error in upscale_image: {str(e)}")
raise gr.Error("์ด๋ฏธ์ง ์ฒ๋ฆฌ ์ค ์ค๋ฅ๊ฐ ๋ฐ์ํ์ต๋๋ค. ๋ค์ ์๋ํด์ฃผ์ธ์.")
# ์ธํฐํ์ด์ค ์ค๋ช
DESCRIPTION = """
# ์ด๋ฏธ์ง ์
์ค์ผ์ผ๋ฌ (Image Upscaler)
์ด๋ฏธ์ง์ ํฌ๊ธฐ์ ํ์ง์ ํฅ์์์ผ ๋ณด์ธ์!
You can increase the size and quality of your images!
## ์ฌ์ฉ ๋ฐฉ๋ฒ (How to use):
1. ์ด๋ฏธ์ง๋ฅผ ์
๋ก๋ํ์ธ์ (Upload an image)
2. ์
์ค์ผ์ผ ๋ ๋ฒจ์ ์ ํํ์ธ์ (Select upscale level)
3. Submit ๋ฒํผ์ ํด๋ฆญํ์ธ์ (Click submit)
"""
# Gradio ์ธํฐํ์ด์ค ์ ์
demo = gr.Interface(
fn=upscale_image,
inputs=[
gr.Image(label="์
๋ ฅ ์ด๋ฏธ์ง (Input Image)", type="pil"),
gr.Radio(
label="์
์ค์ผ์ผ ๋ ๋ฒจ (Upscale Level)",
choices=[2, 4, 6, 8],
value=2,
type="value" # 'number' ์์ 'value'๋ก ๋ณ๊ฒฝ
)
],
outputs=gr.File(label="์
์ค์ผ์ผ๋ ์ด๋ฏธ์ง ๋ค์ด๋ก๋ (Download Upscaled Image)"),
title="Image Upscaler",
description=DESCRIPTION,
allow_flagging="never"
)
# ์ธํฐํ์ด์ค ์คํ
demo.launch() |