Spaces:
Runtime error
Runtime error
chore(app): update to Gradio 5
Browse files- .gitignore +1 -0
- app.py +44 -62
- process_image.py +16 -9
- requirements.txt +1 -1
.gitignore
CHANGED
@@ -1,5 +1,6 @@
|
|
1 |
# folder
|
2 |
.vscode
|
|
|
3 |
|
4 |
# file type
|
5 |
*.svg
|
|
|
1 |
# folder
|
2 |
.vscode
|
3 |
+
/upscaled
|
4 |
|
5 |
# file type
|
6 |
*.svg
|
app.py
CHANGED
@@ -5,53 +5,11 @@ from run_cmd import run_cmd
|
|
5 |
|
6 |
is_colab = util.is_google_colab()
|
7 |
|
8 |
-
css = '''
|
9 |
-
.file-preview {
|
10 |
-
overflow: hidden !important;
|
11 |
-
margin: 5px 0 !important;
|
12 |
-
padding: 0 10px !important;
|
13 |
-
}
|
14 |
-
|
15 |
-
.file-preview div div:nth-child(2) {
|
16 |
-
flex-grow: 1 !important;
|
17 |
-
}
|
18 |
-
|
19 |
-
.file-preview div div:nth-child(3) {
|
20 |
-
text-align: right !important;
|
21 |
-
padding: 0.5rem 0;
|
22 |
-
width: auto;
|
23 |
-
}
|
24 |
-
|
25 |
-
#preview_file .h-full.min-h-\[15rem\].flex.justify-center.items-center {
|
26 |
-
min-height: initial !important;
|
27 |
-
padding: 10px 0;
|
28 |
-
}
|
29 |
-
|
30 |
-
#preview_file a {
|
31 |
-
border-radius: 0.5rem;
|
32 |
-
padding-top: 0.5rem;
|
33 |
-
padding-bottom: 0.5rem;
|
34 |
-
padding-left: 1rem;
|
35 |
-
padding-right: 1rem;
|
36 |
-
font-size: 1rem;
|
37 |
-
line-height: 1.5rem;
|
38 |
-
font-weight: 600;
|
39 |
-
color: white;
|
40 |
-
background-color: gray;
|
41 |
-
}
|
42 |
-
|
43 |
-
.colab_img {
|
44 |
-
margin: 10px 0;
|
45 |
-
display: inline-block;
|
46 |
-
margin: 0 10px;
|
47 |
-
}
|
48 |
-
'''
|
49 |
-
|
50 |
title = "ESRGAN Upscaling With Custom Models"
|
51 |
|
52 |
-
with gr.Blocks(title=title,
|
53 |
gr.Markdown(
|
54 |
-
|
55 |
# {title}
|
56 |
This space uses old ESRGAN architecture to upscale images, using models made by the community.
|
57 |
|
@@ -62,25 +20,49 @@ with gr.Blocks(title=title, css=css) as demo:
|
|
62 |
|
63 |
gr.HTML(value="<a href='https://ko-fi.com/Y8Y7GVAAF' target='_blank' style='display:block;margin-bottom:5px'><img height='36' style='border:0px;height:36px;' src='https://storage.ko-fi.com/cdn/kofi1.png?v=3' border='0' alt='Buy Me a Coffee at ko-fi.com' /></a>")
|
64 |
|
65 |
-
with gr.
|
66 |
-
with gr.
|
67 |
-
|
68 |
-
|
69 |
-
|
70 |
-
|
71 |
-
|
72 |
-
|
73 |
-
|
74 |
-
|
75 |
-
|
76 |
-
|
77 |
-
|
78 |
-
|
79 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
80 |
|
81 |
gr.HTML(value="<p><a href='https://upscale.wiki/wiki/Model_Database'>Model Database</a></p>")
|
82 |
-
|
83 |
-
upscale_btn.click(
|
|
|
|
|
|
|
|
|
84 |
|
85 |
demo.queue()
|
86 |
-
demo.launch(debug=is_colab, share=is_colab, inline=is_colab)
|
|
|
5 |
|
6 |
is_colab = util.is_google_colab()
|
7 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
8 |
title = "ESRGAN Upscaling With Custom Models"
|
9 |
|
10 |
+
with gr.Blocks(title=title, fill_height=True) as demo:
|
11 |
gr.Markdown(
|
12 |
+
f"""
|
13 |
# {title}
|
14 |
This space uses old ESRGAN architecture to upscale images, using models made by the community.
|
15 |
|
|
|
20 |
|
21 |
gr.HTML(value="<a href='https://ko-fi.com/Y8Y7GVAAF' target='_blank' style='display:block;margin-bottom:5px'><img height='36' style='border:0px;height:36px;' src='https://storage.ko-fi.com/cdn/kofi1.png?v=3' border='0' alt='Buy Me a Coffee at ko-fi.com' /></a>")
|
22 |
|
23 |
+
with gr.Row():
|
24 |
+
with gr.Column():
|
25 |
+
input_image = gr.Image(
|
26 |
+
sources="upload",
|
27 |
+
type="filepath",
|
28 |
+
label="Image to upscale"
|
29 |
+
)
|
30 |
+
|
31 |
+
upscale_size = gr.Radio(
|
32 |
+
["x4", "x2"],
|
33 |
+
label="Upscale by:",
|
34 |
+
value="x4"
|
35 |
+
)
|
36 |
+
|
37 |
+
upscale_type = gr.Radio(
|
38 |
+
["Manga", "Anime", "Photo", "General"],
|
39 |
+
label="Select the type of picture you want to upscale:",
|
40 |
+
value="Manga"
|
41 |
+
)
|
42 |
+
|
43 |
+
with gr.Row():
|
44 |
+
upscale_btn = gr.Button(value="Upscale", variant="primary")
|
45 |
+
|
46 |
+
with gr.Column():
|
47 |
+
output_image = gr.Image(
|
48 |
+
type="pil",
|
49 |
+
interactive=False,
|
50 |
+
label="Upscaled image",
|
51 |
+
elem_id="preview_img"
|
52 |
+
)
|
53 |
+
|
54 |
+
with gr.Row():
|
55 |
+
out_file = gr.DownloadButton(
|
56 |
+
visible=False,
|
57 |
+
)
|
58 |
|
59 |
gr.HTML(value="<p><a href='https://upscale.wiki/wiki/Model_Database'>Model Database</a></p>")
|
60 |
+
|
61 |
+
upscale_btn.click(
|
62 |
+
process_image.inference,
|
63 |
+
inputs=[input_image, upscale_size, upscale_type],
|
64 |
+
outputs=[output_image, out_file]
|
65 |
+
)
|
66 |
|
67 |
demo.queue()
|
68 |
+
demo.launch(debug=is_colab, share=is_colab, inline=is_colab)
|
process_image.py
CHANGED
@@ -2,19 +2,22 @@ import os
|
|
2 |
import gradio as gr
|
3 |
from run_cmd import run_cmd
|
4 |
from PIL import Image
|
5 |
-
import tempfile
|
6 |
import uuid
|
7 |
import numpy as np
|
8 |
|
9 |
-
temp_path =
|
|
|
10 |
|
11 |
def inference(img, size, type):
|
12 |
-
if not
|
13 |
-
|
|
|
|
|
|
|
|
|
|
|
14 |
|
15 |
-
|
16 |
-
|
17 |
-
img.save(OUTPUT_PATH)
|
18 |
|
19 |
if type == "Manga":
|
20 |
run_cmd(f"python inference_manga_v2.py {OUTPUT_PATH}")
|
@@ -24,8 +27,12 @@ def inference(img, size, type):
|
|
24 |
img_out = Image.open(OUTPUT_PATH)
|
25 |
|
26 |
if size == "x2":
|
27 |
-
img_out = img_out.resize(
|
|
|
28 |
|
29 |
img_out = np.array(img_out)
|
30 |
|
31 |
-
return img_out, gr.
|
|
|
|
|
|
|
|
2 |
import gradio as gr
|
3 |
from run_cmd import run_cmd
|
4 |
from PIL import Image
|
|
|
5 |
import uuid
|
6 |
import numpy as np
|
7 |
|
8 |
+
temp_path = "./upscaled"
|
9 |
+
|
10 |
|
11 |
def inference(img, size, type):
|
12 |
+
if not os.path.exists(temp_path):
|
13 |
+
os.mkdir(temp_path)
|
14 |
+
|
15 |
+
image = Image.open(img)
|
16 |
+
|
17 |
+
OUTPUT_PATH = os.path.join(
|
18 |
+
temp_path, f"{str(uuid.uuid4())[0:12]}_{size}.png")
|
19 |
|
20 |
+
image.save(OUTPUT_PATH)
|
|
|
|
|
21 |
|
22 |
if type == "Manga":
|
23 |
run_cmd(f"python inference_manga_v2.py {OUTPUT_PATH}")
|
|
|
27 |
img_out = Image.open(OUTPUT_PATH)
|
28 |
|
29 |
if size == "x2":
|
30 |
+
img_out = img_out.resize(
|
31 |
+
(img_out.width // 2, img_out.height // 2), resample=Image.BICUBIC)
|
32 |
|
33 |
img_out = np.array(img_out)
|
34 |
|
35 |
+
return img_out, gr.DownloadButton(
|
36 |
+
value=OUTPUT_PATH,
|
37 |
+
visible=True,
|
38 |
+
)
|
requirements.txt
CHANGED
@@ -3,7 +3,7 @@ numpy
|
|
3 |
opencv-python-headless
|
4 |
setuptools
|
5 |
Pillow
|
6 |
-
gradio==
|
7 |
torchvision
|
8 |
addict
|
9 |
future
|
|
|
3 |
opencv-python-headless
|
4 |
setuptools
|
5 |
Pillow
|
6 |
+
gradio==5.1.0
|
7 |
torchvision
|
8 |
addict
|
9 |
future
|