Spaces:
Running
Running
Update app.py
Browse files
app.py
CHANGED
@@ -1,34 +1,71 @@
|
|
1 |
import gradio as gr
|
2 |
import cv2
|
3 |
import numpy as np
|
|
|
|
|
4 |
|
5 |
-
# ์ด๋ฏธ์ง ์
์ค์ผ์ผ ํจ์
|
6 |
def upscale_image(input_image, upscale_factor):
|
7 |
-
|
8 |
-
|
9 |
-
|
10 |
-
|
11 |
-
|
12 |
-
|
13 |
-
|
14 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
15 |
|
16 |
# ์ธํฐํ์ด์ค ์ค๋ช
|
17 |
DESCRIPTION = """
|
18 |
-
|
19 |
-
|
|
|
20 |
|
21 |
-
|
22 |
-
|
|
|
|
|
|
|
23 |
|
24 |
# Gradio ์ธํฐํ์ด์ค ์ ์
|
25 |
demo = gr.Interface(
|
26 |
fn=upscale_image,
|
27 |
-
inputs=[
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
28 |
outputs=gr.File(label="์
์ค์ผ์ผ๋ ์ด๋ฏธ์ง ๋ค์ด๋ก๋ (Download Upscaled Image)"),
|
29 |
title="Image Upscaler",
|
30 |
-
description=DESCRIPTION
|
|
|
|
|
|
|
|
|
31 |
)
|
32 |
|
33 |
# ์ธํฐํ์ด์ค ์คํ
|
34 |
-
demo.launch(
|
|
|
1 |
import gradio as gr
|
2 |
import cv2
|
3 |
import numpy as np
|
4 |
+
import os
|
5 |
+
from PIL import Image
|
6 |
|
|
|
7 |
def upscale_image(input_image, upscale_factor):
|
8 |
+
try:
|
9 |
+
# PIL Image๋ก ๋ณํ
|
10 |
+
if isinstance(input_image, np.ndarray):
|
11 |
+
input_image = Image.fromarray(input_image)
|
12 |
+
|
13 |
+
# ํ์ฌ ์ด๋ฏธ์ง ํฌ๊ธฐ
|
14 |
+
current_width, current_height = input_image.size
|
15 |
+
|
16 |
+
# ์๋ก์ด ํฌ๊ธฐ ๊ณ์ฐ
|
17 |
+
new_width = int(current_width * upscale_factor)
|
18 |
+
new_height = int(current_height * upscale_factor)
|
19 |
+
|
20 |
+
# ์ด๋ฏธ์ง ๋ฆฌ์ฌ์ด์ฆ
|
21 |
+
output_image = input_image.resize((new_width, new_height), Image.Resampling.LANCZOS)
|
22 |
+
|
23 |
+
# ์์ ํ์ผ ์ ์ฅ์ ์ํ ๋๋ ํ ๋ฆฌ ํ์ธ ๋ฐ ์์ฑ
|
24 |
+
if not os.path.exists("temp"):
|
25 |
+
os.makedirs("temp")
|
26 |
+
|
27 |
+
# ๊ฒฐ๊ณผ ์ด๋ฏธ์ง ์ ์ฅ
|
28 |
+
output_path = os.path.join("temp", "upscaled_image.png")
|
29 |
+
output_image.save(output_path, "PNG", quality=100)
|
30 |
+
|
31 |
+
return output_path
|
32 |
+
|
33 |
+
except Exception as e:
|
34 |
+
print(f"Error in upscale_image: {str(e)}")
|
35 |
+
raise gr.Error("์ด๋ฏธ์ง ์ฒ๋ฆฌ ์ค ์ค๋ฅ๊ฐ ๋ฐ์ํ์ต๋๋ค. ๋ค์ ์๋ํด์ฃผ์ธ์.")
|
36 |
|
37 |
# ์ธํฐํ์ด์ค ์ค๋ช
|
38 |
DESCRIPTION = """
|
39 |
+
# ์ด๋ฏธ์ง ์
์ค์ผ์ผ๋ฌ (Image Upscaler)
|
40 |
+
์ด๋ฏธ์ง์ ํฌ๊ธฐ์ ํ์ง์ ํฅ์์์ผ ๋ณด์ธ์!
|
41 |
+
You can increase the size and quality of your images!
|
42 |
|
43 |
+
## ์ฌ์ฉ ๋ฐฉ๋ฒ (How to use):
|
44 |
+
1. ์ด๋ฏธ์ง๋ฅผ ์
๋ก๋ํ์ธ์ (Upload an image)
|
45 |
+
2. ์
์ค์ผ์ผ ๋ ๋ฒจ์ ์ ํํ์ธ์ (Select upscale level)
|
46 |
+
3. Submit ๋ฒํผ์ ํด๋ฆญํ์ธ์ (Click submit)
|
47 |
+
"""
|
48 |
|
49 |
# Gradio ์ธํฐํ์ด์ค ์ ์
|
50 |
demo = gr.Interface(
|
51 |
fn=upscale_image,
|
52 |
+
inputs=[
|
53 |
+
gr.Image(label="์
๋ ฅ ์ด๋ฏธ์ง (Input Image)", type="pil"),
|
54 |
+
gr.Radio(
|
55 |
+
label="์
์ค์ผ์ผ ๋ ๋ฒจ (Upscale Level)",
|
56 |
+
choices=[2, 4, 6, 8],
|
57 |
+
value=2,
|
58 |
+
type="number"
|
59 |
+
)
|
60 |
+
],
|
61 |
outputs=gr.File(label="์
์ค์ผ์ผ๋ ์ด๋ฏธ์ง ๋ค์ด๋ก๋ (Download Upscaled Image)"),
|
62 |
title="Image Upscaler",
|
63 |
+
description=DESCRIPTION,
|
64 |
+
allow_flagging="never",
|
65 |
+
examples=[
|
66 |
+
["example.jpg", 2] # examples ํด๋์ example.jpg ํ์ผ์ ์ถ๊ฐํด์ผ ํฉ๋๋ค
|
67 |
+
]
|
68 |
)
|
69 |
|
70 |
# ์ธํฐํ์ด์ค ์คํ
|
71 |
+
demo.launch()
|