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()