Upload 82 files
Browse filesThis view is limited to 50 files because it contains too many changes.
See raw diff
- .gitattributes +31 -0
- .python-version +1 -0
- LICENSE +21 -0
- apps/assets/examples/Real-ESRGAN-Anime-finetuning/1/config.json +5 -0
- apps/assets/examples/Real-ESRGAN-Anime-finetuning/1/frame_0001_2T3.png +3 -0
- apps/assets/examples/Real-ESRGAN-Anime-finetuning/1/frame_0001_2T3_real_esrgan_anime_x2.png +3 -0
- apps/assets/examples/Real-ESRGAN-Anime-finetuning/2/config.json +5 -0
- apps/assets/examples/Real-ESRGAN-Anime-finetuning/2/frame_0001_9T3.png +3 -0
- apps/assets/examples/Real-ESRGAN-Anime-finetuning/2/frame_0001_9T3_real_esrgan_anime_x4.png +3 -0
- apps/assets/examples/Real-ESRGAN-Anime-finetuning/3/config.json +5 -0
- apps/assets/examples/Real-ESRGAN-Anime-finetuning/3/frame_0001_10T3.png +3 -0
- apps/assets/examples/Real-ESRGAN-Anime-finetuning/3/frame_0001_10T3_real_esrgan_anime_x6.png +3 -0
- apps/assets/examples/Real-ESRGAN-Anime-finetuning/4/config.json +5 -0
- apps/assets/examples/Real-ESRGAN-Anime-finetuning/4/frame_0001_14T3.png +3 -0
- apps/assets/examples/Real-ESRGAN-Anime-finetuning/4/frame_0001_14T3_real_esrgan_anime_x8.png +3 -0
- apps/gradio_app.py +103 -0
- apps/gradio_app/__init__.py +0 -0
- apps/gradio_app/examples.py +34 -0
- apps/gradio_app/inference.py +25 -0
- apps/gradio_app/project_info.py +70 -0
- apps/gradio_app/setup_scripts.py +63 -0
- apps/gradio_app/static/outer_scale_warning.js +11 -0
- apps/gradio_app/static/styles.css +543 -0
- apps/old-gradio_app.py +136 -0
- assets/examples/Real-ESRGAN-Anime-finetuning/1/1_x2_zoom.png +3 -0
- assets/examples/Real-ESRGAN-Anime-finetuning/1/1_zoom.png +3 -0
- assets/examples/Real-ESRGAN-Anime-finetuning/1/config.json +5 -0
- assets/examples/Real-ESRGAN-Anime-finetuning/1/frame_0001_2T3.png +3 -0
- assets/examples/Real-ESRGAN-Anime-finetuning/1/frame_0001_2T3_real_esrgan_anime_x2.png +3 -0
- assets/examples/Real-ESRGAN-Anime-finetuning/2/2_x4_zoom.png +3 -0
- assets/examples/Real-ESRGAN-Anime-finetuning/2/2_zoom.png +3 -0
- assets/examples/Real-ESRGAN-Anime-finetuning/2/config.json +5 -0
- assets/examples/Real-ESRGAN-Anime-finetuning/2/frame_0001_9T3.png +3 -0
- assets/examples/Real-ESRGAN-Anime-finetuning/2/frame_0001_9T3_real_esrgan_anime_x4.png +3 -0
- assets/examples/Real-ESRGAN-Anime-finetuning/3/3_x6_zoom.png +3 -0
- assets/examples/Real-ESRGAN-Anime-finetuning/3/3_zoom.png +3 -0
- assets/examples/Real-ESRGAN-Anime-finetuning/3/config.json +5 -0
- assets/examples/Real-ESRGAN-Anime-finetuning/3/frame_0001_10T3.png +3 -0
- assets/examples/Real-ESRGAN-Anime-finetuning/3/frame_0001_10T3_real_esrgan_anime_x6.png +3 -0
- assets/examples/Real-ESRGAN-Anime-finetuning/4/4_x8_zoom.png +3 -0
- assets/examples/Real-ESRGAN-Anime-finetuning/4/4_zoom.png +3 -0
- assets/examples/Real-ESRGAN-Anime-finetuning/4/config.json +5 -0
- assets/examples/Real-ESRGAN-Anime-finetuning/4/frame_0001_14T3.png +3 -0
- assets/examples/Real-ESRGAN-Anime-finetuning/4/frame_0001_14T3_real_esrgan_anime_x8.png +3 -0
- ckpts/.gitkeep +0 -0
- configs/.gitkeep +0 -0
- configs/Real-ESRGAN-Anime-finetuning.yml +188 -0
- configs/model_ckpts.yaml +22 -0
- data/.gitignore +2 -0
- docs/inference/inference_doc.md +116 -0
.gitattributes
CHANGED
@@ -33,3 +33,34 @@ saved_model/**/* filter=lfs diff=lfs merge=lfs -text
|
|
33 |
*.zip filter=lfs diff=lfs merge=lfs -text
|
34 |
*.zst filter=lfs diff=lfs merge=lfs -text
|
35 |
*tfevents* filter=lfs diff=lfs merge=lfs -text
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
33 |
*.zip filter=lfs diff=lfs merge=lfs -text
|
34 |
*.zst filter=lfs diff=lfs merge=lfs -text
|
35 |
*tfevents* filter=lfs diff=lfs merge=lfs -text
|
36 |
+
apps/assets/examples/Real-ESRGAN-Anime-finetuning/1/frame_0001_2T3_real_esrgan_anime_x2.png filter=lfs diff=lfs merge=lfs -text
|
37 |
+
apps/assets/examples/Real-ESRGAN-Anime-finetuning/1/frame_0001_2T3.png filter=lfs diff=lfs merge=lfs -text
|
38 |
+
apps/assets/examples/Real-ESRGAN-Anime-finetuning/2/frame_0001_9T3_real_esrgan_anime_x4.png filter=lfs diff=lfs merge=lfs -text
|
39 |
+
apps/assets/examples/Real-ESRGAN-Anime-finetuning/2/frame_0001_9T3.png filter=lfs diff=lfs merge=lfs -text
|
40 |
+
apps/assets/examples/Real-ESRGAN-Anime-finetuning/3/frame_0001_10T3_real_esrgan_anime_x6.png filter=lfs diff=lfs merge=lfs -text
|
41 |
+
apps/assets/examples/Real-ESRGAN-Anime-finetuning/3/frame_0001_10T3.png filter=lfs diff=lfs merge=lfs -text
|
42 |
+
apps/assets/examples/Real-ESRGAN-Anime-finetuning/4/frame_0001_14T3_real_esrgan_anime_x8.png filter=lfs diff=lfs merge=lfs -text
|
43 |
+
apps/assets/examples/Real-ESRGAN-Anime-finetuning/4/frame_0001_14T3.png filter=lfs diff=lfs merge=lfs -text
|
44 |
+
assets/examples/Real-ESRGAN-Anime-finetuning/1/1_x2_zoom.png filter=lfs diff=lfs merge=lfs -text
|
45 |
+
assets/examples/Real-ESRGAN-Anime-finetuning/1/1_zoom.png filter=lfs diff=lfs merge=lfs -text
|
46 |
+
assets/examples/Real-ESRGAN-Anime-finetuning/1/frame_0001_2T3_real_esrgan_anime_x2.png filter=lfs diff=lfs merge=lfs -text
|
47 |
+
assets/examples/Real-ESRGAN-Anime-finetuning/1/frame_0001_2T3.png filter=lfs diff=lfs merge=lfs -text
|
48 |
+
assets/examples/Real-ESRGAN-Anime-finetuning/2/2_x4_zoom.png filter=lfs diff=lfs merge=lfs -text
|
49 |
+
assets/examples/Real-ESRGAN-Anime-finetuning/2/2_zoom.png filter=lfs diff=lfs merge=lfs -text
|
50 |
+
assets/examples/Real-ESRGAN-Anime-finetuning/2/frame_0001_9T3_real_esrgan_anime_x4.png filter=lfs diff=lfs merge=lfs -text
|
51 |
+
assets/examples/Real-ESRGAN-Anime-finetuning/2/frame_0001_9T3.png filter=lfs diff=lfs merge=lfs -text
|
52 |
+
assets/examples/Real-ESRGAN-Anime-finetuning/3/3_x6_zoom.png filter=lfs diff=lfs merge=lfs -text
|
53 |
+
assets/examples/Real-ESRGAN-Anime-finetuning/3/3_zoom.png filter=lfs diff=lfs merge=lfs -text
|
54 |
+
assets/examples/Real-ESRGAN-Anime-finetuning/3/frame_0001_10T3_real_esrgan_anime_x6.png filter=lfs diff=lfs merge=lfs -text
|
55 |
+
assets/examples/Real-ESRGAN-Anime-finetuning/3/frame_0001_10T3.png filter=lfs diff=lfs merge=lfs -text
|
56 |
+
assets/examples/Real-ESRGAN-Anime-finetuning/4/4_x8_zoom.png filter=lfs diff=lfs merge=lfs -text
|
57 |
+
assets/examples/Real-ESRGAN-Anime-finetuning/4/4_zoom.png filter=lfs diff=lfs merge=lfs -text
|
58 |
+
assets/examples/Real-ESRGAN-Anime-finetuning/4/frame_0001_14T3_real_esrgan_anime_x8.png filter=lfs diff=lfs merge=lfs -text
|
59 |
+
assets/examples/Real-ESRGAN-Anime-finetuning/4/frame_0001_14T3.png filter=lfs diff=lfs merge=lfs -text
|
60 |
+
tests/test_data/frame_0001_real_esrgan_anime.jpg filter=lfs diff=lfs merge=lfs -text
|
61 |
+
tests/test_data/frame_0001_real_esrgan.jpg filter=lfs diff=lfs merge=lfs -text
|
62 |
+
tests/test_data/image_x4.png filter=lfs diff=lfs merge=lfs -text
|
63 |
+
tests/test_data/image_x8.png filter=lfs diff=lfs merge=lfs -text
|
64 |
+
tests/test_data/input_image.png filter=lfs diff=lfs merge=lfs -text
|
65 |
+
tests/test_data/real_esrgan_anime/frame_0235_chunk0_8T1_out.png filter=lfs diff=lfs merge=lfs -text
|
66 |
+
tests/test_data/real_esrgan/frame_0235_chunk0_8T1_out.png filter=lfs diff=lfs merge=lfs -text
|
.python-version
ADDED
@@ -0,0 +1 @@
|
|
|
|
|
1 |
+
3.11.13
|
LICENSE
ADDED
@@ -0,0 +1,21 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
MIT License
|
2 |
+
|
3 |
+
Copyright (c) 2025 Danh Tran
|
4 |
+
|
5 |
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
6 |
+
of this software and associated documentation files (the "Software"), to deal
|
7 |
+
in the Software without restriction, including without limitation the rights
|
8 |
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
9 |
+
copies of the Software, and to permit persons to whom the Software is
|
10 |
+
furnished to do so, subject to the following conditions:
|
11 |
+
|
12 |
+
The above copyright notice and this permission notice shall be included in all
|
13 |
+
copies or substantial portions of the Software.
|
14 |
+
|
15 |
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
16 |
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
17 |
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
18 |
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
19 |
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
20 |
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
21 |
+
SOFTWARE.
|
apps/assets/examples/Real-ESRGAN-Anime-finetuning/1/config.json
ADDED
@@ -0,0 +1,5 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
{
|
2 |
+
"input_file": "frame_0001_2T3.png",
|
3 |
+
"output_file": "frame_0001_2T3_real_esrgan_anime_x2.png",
|
4 |
+
"outer_scale": 2
|
5 |
+
}
|
apps/assets/examples/Real-ESRGAN-Anime-finetuning/1/frame_0001_2T3.png
ADDED
![]() |
Git LFS Details
|
apps/assets/examples/Real-ESRGAN-Anime-finetuning/1/frame_0001_2T3_real_esrgan_anime_x2.png
ADDED
![]() |
Git LFS Details
|
apps/assets/examples/Real-ESRGAN-Anime-finetuning/2/config.json
ADDED
@@ -0,0 +1,5 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
{
|
2 |
+
"input_file": "frame_0001_9T3.png",
|
3 |
+
"output_file": "frame_0001_9T3_real_esrgan_anime_x4.png",
|
4 |
+
"outer_scale": 4
|
5 |
+
}
|
apps/assets/examples/Real-ESRGAN-Anime-finetuning/2/frame_0001_9T3.png
ADDED
![]() |
Git LFS Details
|
apps/assets/examples/Real-ESRGAN-Anime-finetuning/2/frame_0001_9T3_real_esrgan_anime_x4.png
ADDED
![]() |
Git LFS Details
|
apps/assets/examples/Real-ESRGAN-Anime-finetuning/3/config.json
ADDED
@@ -0,0 +1,5 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
{
|
2 |
+
"input_file": "frame_0001_10T3.png",
|
3 |
+
"output_file": "frame_0001_10T3_real_esrgan_anime_x6.png",
|
4 |
+
"outer_scale": 6
|
5 |
+
}
|
apps/assets/examples/Real-ESRGAN-Anime-finetuning/3/frame_0001_10T3.png
ADDED
![]() |
Git LFS Details
|
apps/assets/examples/Real-ESRGAN-Anime-finetuning/3/frame_0001_10T3_real_esrgan_anime_x6.png
ADDED
![]() |
Git LFS Details
|
apps/assets/examples/Real-ESRGAN-Anime-finetuning/4/config.json
ADDED
@@ -0,0 +1,5 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
{
|
2 |
+
"input_file": "frame_0001_14T3.png",
|
3 |
+
"output_file": "frame_0001_14T3_real_esrgan_anime_x8.png",
|
4 |
+
"outer_scale": 8
|
5 |
+
}
|
apps/assets/examples/Real-ESRGAN-Anime-finetuning/4/frame_0001_14T3.png
ADDED
![]() |
Git LFS Details
|
apps/assets/examples/Real-ESRGAN-Anime-finetuning/4/frame_0001_14T3_real_esrgan_anime_x8.png
ADDED
![]() |
Git LFS Details
|
apps/gradio_app.py
ADDED
@@ -0,0 +1,103 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
import gradio as gr
|
2 |
+
import os
|
3 |
+
import subprocess
|
4 |
+
from gradio_app.project_info import (
|
5 |
+
CONTENT_DESCRIPTION,
|
6 |
+
CONTENT_IN_1, CONTENT_IN_2,
|
7 |
+
CONTENT_OUT_1, CONTENT_OUT_2
|
8 |
+
)
|
9 |
+
from gradio_app.inference import run_inference
|
10 |
+
from gradio_app.examples import load_examples, select_example
|
11 |
+
|
12 |
+
|
13 |
+
def run_setup_script():
|
14 |
+
setup_script = os.path.join(os.path.dirname(__file__),
|
15 |
+
"gradio_app", "setup_scripts.py")
|
16 |
+
try:
|
17 |
+
result = subprocess.run(["python", setup_script], capture_output=True, text=True, check=True)
|
18 |
+
return result.stdout
|
19 |
+
except subprocess.CalledProcessError as e:
|
20 |
+
print(f"Setup script failed with error: {e.stderr}")
|
21 |
+
return f"Setup script failed: {e.stderr}"
|
22 |
+
|
23 |
+
def create_gui():
|
24 |
+
# Load custom CSS
|
25 |
+
custom_css = open("apps/gradio_app/static/styles.css").read()
|
26 |
+
|
27 |
+
# JavaScript function to update warning_text Markdown component
|
28 |
+
outer_scale_warning = open("apps/gradio_app/static/outer_scale_warning.js").read()
|
29 |
+
|
30 |
+
# Define Gradio interface
|
31 |
+
with gr.Blocks(css=custom_css) as demo:
|
32 |
+
gr.Markdown("# Anime Super Resolution 🖼️")
|
33 |
+
gr.Markdown(CONTENT_DESCRIPTION)
|
34 |
+
gr.Markdown(CONTENT_IN_1)
|
35 |
+
gr.HTML(CONTENT_IN_2)
|
36 |
+
with gr.Row():
|
37 |
+
with gr.Column(scale=2):
|
38 |
+
input_image = gr.Image(
|
39 |
+
type="filepath",
|
40 |
+
label="Input Image",
|
41 |
+
elem_classes="input-image"
|
42 |
+
)
|
43 |
+
model_id = gr.Textbox(
|
44 |
+
label="Model ID",
|
45 |
+
value="danhtran2mind/Real-ESRGAN-Anime-finetuning"
|
46 |
+
)
|
47 |
+
|
48 |
+
outer_scale = gr.Slider(
|
49 |
+
minimum=1,
|
50 |
+
maximum=8,
|
51 |
+
step=1,
|
52 |
+
value=2,
|
53 |
+
label="Outer Scale",
|
54 |
+
elem_id="outer-scale-slider"
|
55 |
+
)
|
56 |
+
warning_text = gr.HTML(elem_id="warning-text")
|
57 |
+
gr.Markdown(
|
58 |
+
"**Note:** For optimal output quality, set `Outer Scale` to a value between 1 and 4. "
|
59 |
+
"**Values greater than 4 are not recommended**. "
|
60 |
+
"Please ensure `Outer Scale` is greater than or equal to `Inner Scale` (default: 4)."
|
61 |
+
)
|
62 |
+
|
63 |
+
examples_data = load_examples()
|
64 |
+
submit_button = gr.Button("Run Inference")
|
65 |
+
|
66 |
+
with gr.Column(scale=3):
|
67 |
+
output_image = gr.Image(
|
68 |
+
label="Output Image",
|
69 |
+
elem_classes="output-image"
|
70 |
+
)
|
71 |
+
output_text = gr.Textbox(label="Status")
|
72 |
+
|
73 |
+
# Client-side warning update for warning_text
|
74 |
+
outer_scale.change(
|
75 |
+
fn=lambda x: x,
|
76 |
+
inputs=outer_scale,
|
77 |
+
outputs=outer_scale,
|
78 |
+
js=outer_scale_warning
|
79 |
+
)
|
80 |
+
|
81 |
+
gr.Examples(
|
82 |
+
examples=[[input_img, output_img, outer_scale] for input_img, output_img, outer_scale in examples_data],
|
83 |
+
inputs=[input_image, output_image, outer_scale],
|
84 |
+
label="Example Inputs",
|
85 |
+
examples_per_page=4,
|
86 |
+
fn=select_example,
|
87 |
+
outputs=[input_image, outer_scale, output_image, output_text]
|
88 |
+
)
|
89 |
+
|
90 |
+
submit_button.click(
|
91 |
+
fn=run_inference,
|
92 |
+
inputs=[input_image, model_id, outer_scale],
|
93 |
+
outputs=[output_image, output_text]
|
94 |
+
)
|
95 |
+
gr.HTML(CONTENT_OUT_1)
|
96 |
+
gr.Markdown(CONTENT_OUT_2)
|
97 |
+
|
98 |
+
return demo
|
99 |
+
|
100 |
+
if __name__ == "__main__":
|
101 |
+
run_setup_script()
|
102 |
+
demo = create_gui()
|
103 |
+
demo.launch()
|
apps/gradio_app/__init__.py
ADDED
File without changes
|
apps/gradio_app/examples.py
ADDED
@@ -0,0 +1,34 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
import os
|
2 |
+
import json
|
3 |
+
from PIL import Image
|
4 |
+
import gradio as gr
|
5 |
+
|
6 |
+
def load_examples():
|
7 |
+
examples = []
|
8 |
+
examples_base_path = os.path.join("apps", "assets", "examples", "Real-ESRGAN-Anime-finetuning")
|
9 |
+
|
10 |
+
for folder in ["1", "2", "3", "4"]:
|
11 |
+
folder_path = os.path.join(examples_base_path, folder)
|
12 |
+
config_path = os.path.join(folder_path, "config.json")
|
13 |
+
|
14 |
+
if os.path.exists(config_path):
|
15 |
+
with open(config_path, 'r') as f:
|
16 |
+
config = json.load(f)
|
17 |
+
input_filename = config.get("input_file", "input.jpg")
|
18 |
+
output_filename = config.get("output_file", "output.jpg")
|
19 |
+
outer_scale = config.get("outer_scale", 4)
|
20 |
+
|
21 |
+
input_image_path = os.path.join(folder_path, input_filename)
|
22 |
+
output_image_path = os.path.join(folder_path, output_filename)
|
23 |
+
|
24 |
+
if os.path.exists(input_image_path) and os.path.exists(output_image_path):
|
25 |
+
input_image_data = Image.open(input_image_path)
|
26 |
+
output_image_data = Image.open(output_image_path)
|
27 |
+
examples.append([input_image_data, output_image_data, outer_scale])
|
28 |
+
|
29 |
+
return examples
|
30 |
+
|
31 |
+
def select_example(evt: gr.SelectData, examples_data):
|
32 |
+
example_index = evt.index
|
33 |
+
input_image_data, output_image_data, outer_scale = examples_data[example_index]
|
34 |
+
return input_image_data, outer_scale, output_image_data, f"Loaded example with Outer Scale: {outer_scale}"
|
apps/gradio_app/inference.py
ADDED
@@ -0,0 +1,25 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
import gradio as gr
|
2 |
+
from PIL import Image
|
3 |
+
import os
|
4 |
+
import sys
|
5 |
+
|
6 |
+
# Add the project root directory to the Python path
|
7 |
+
sys.path.append(os.path.abspath(os.path.join(os.path.dirname(__file__), '..', '..')))
|
8 |
+
|
9 |
+
from src.anime_super_resolution.infer import infer
|
10 |
+
|
11 |
+
def run_inference(input_image, model_id, outer_scale):
|
12 |
+
if not input_image:
|
13 |
+
return None, "Please upload an image."
|
14 |
+
|
15 |
+
models_config_path = "configs/model_ckpts.yaml"
|
16 |
+
try:
|
17 |
+
output_image = infer(
|
18 |
+
input_path=input_image,
|
19 |
+
model_id=model_id,
|
20 |
+
models_config_path=models_config_path,
|
21 |
+
outer_scale=outer_scale,
|
22 |
+
)
|
23 |
+
return output_image, "Inference completed successfully!"
|
24 |
+
except Exception as e:
|
25 |
+
return None, f"Error during inference: {str(e)}"
|
apps/gradio_app/project_info.py
ADDED
@@ -0,0 +1,70 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
CONTENT_DESCRIPTION = """
|
2 |
+
**Anime-Super-Resolution: High-Quality Anime Image Upscaling with Real-ESRGAN**
|
3 |
+
""".strip()
|
4 |
+
|
5 |
+
CONTENT_IN_1 = """
|
6 |
+
Transforms low-res anime images into sharp, vibrant HD visuals, enhancing textures and details for artwork and games.
|
7 |
+
""".strip()
|
8 |
+
|
9 |
+
CONTENT_IN_2 = """
|
10 |
+
<p class="source">
|
11 |
+
For more information, you can check out my GitHub repo:<br>
|
12 |
+
Source code:
|
13 |
+
<a class="badge" href="https://github.com/danhtran2mind/Anime-Super-Resolution">
|
14 |
+
<img src="https://img.shields.io/badge/GitHub-danhtran2mind%2FAnime--Super--Resolution-blue?style=flat?logo=github" alt="GitHub Repo">
|
15 |
+
</a>,
|
16 |
+
Model Hub:
|
17 |
+
<a class="badge" href="https://huggingface.co/danhtran2mind/Real-ESRGAN-Anime-finetuning">
|
18 |
+
<img src="https://img.shields.io/badge/HuggingFace-danhtran2mind%2FReal--ESRGAN--Anime--finetuning-yellow?style=flat?logo=huggingface" alt="HuggingFace Model">
|
19 |
+
</a>.
|
20 |
+
</p>
|
21 |
+
""".strip()
|
22 |
+
|
23 |
+
CONTENT_OUT_1 = """
|
24 |
+
This project leverages code from:
|
25 |
+
<div class="quote-container">
|
26 |
+
<p>
|
27 |
+
The Original Real-ESRGAN
|
28 |
+
<a class="badge" href="https://github.com/xinntao/Real-ESRGAN">
|
29 |
+
<img src="https://img.shields.io/badge/Built%20on-xinntao%2FReal--ESRGAN-blue?style=flat&logo=github" alt="Built on Real-ESRGAN">
|
30 |
+
</a>
|
31 |
+
by
|
32 |
+
<a class="badge" href="https://github.com/xinntao">
|
33 |
+
<img src="https://img.shields.io/badge/GitHub-xinntao-blue?style=flat&logo=github" alt="xinntao">
|
34 |
+
</a>,
|
35 |
+
with our own bug fixes and enhancements available at
|
36 |
+
<a class="badge" href="https://github.com/danhtran2mind/Real-ESRGAN">
|
37 |
+
<img src="https://img.shields.io/badge/GitHub-danhtran2mind%2FReal--ESRGAN-blue?style=flat&logo=github" alt="Real-ESRGAN Enhancements">
|
38 |
+
</a>.
|
39 |
+
<br>
|
40 |
+
The Inference code
|
41 |
+
<a class="badge" href="https://github.com/ai-forever/Real-ESRGAN">
|
42 |
+
<img src="https://img.shields.io/badge/Built%20on-ai--forever%2FReal--ESRGAN-blue?style=flat&logo=github" alt="Built on Real-ESRGAN">
|
43 |
+
</a>
|
44 |
+
by
|
45 |
+
<a class="badge" href="https://github.com/ai-forever">
|
46 |
+
<img src="https://img.shields.io/badge/GitHub-ai--forever-blue?style=flat&logo=github" alt="xinntao">
|
47 |
+
</a>,
|
48 |
+
with our own bug fixes and enhancements available at
|
49 |
+
<a class="badge" href="https://github.com/danhtran2mind/Real-ESRGAN-inference">
|
50 |
+
<img src="https://img.shields.io/badge/GitHub-danhtran2mind%2FReal--ESRGAN--inference-blue?style=flat&logo=github" alt="Real-ESRGAN Enhancements">
|
51 |
+
</a>.
|
52 |
+
</p>
|
53 |
+
</div>
|
54 |
+
""".strip()
|
55 |
+
|
56 |
+
CONTENT_OUT_2 = """
|
57 |
+
You can explore more Model Hubs at:
|
58 |
+
<div class="quote-container">
|
59 |
+
<p>
|
60 |
+
HuggingFace Model Hub:
|
61 |
+
<a class="badge" href="https://huggingface.co/ai-forever/Real-ESRGAN">
|
62 |
+
<img src="https://img.shields.io/badge/HuggingFace-ai--forever%2FReal--ESRGAN-yellow?style=flat&logo=hugggingface" alt="ai-forever Real-ESRGAN Model">
|
63 |
+
</a>,
|
64 |
+
Real-ESRGAN Model releases:
|
65 |
+
<a class="badge" href="https://github.com/xinntao/Real-ESRGAN/releases">
|
66 |
+
<img src="https://img.shields.io/badge/GitHub-Real--ESRGAN%2Freleases-blue?style=flat&logo=github" alt="Real-ESRGAN releases">
|
67 |
+
</a>.
|
68 |
+
</p>
|
69 |
+
</div>
|
70 |
+
""".strip()
|
apps/gradio_app/setup_scripts.py
ADDED
@@ -0,0 +1,63 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
import subprocess
|
2 |
+
import sys
|
3 |
+
import os
|
4 |
+
|
5 |
+
def run_script(script_path, args=None):
|
6 |
+
"""
|
7 |
+
Run a Python script using subprocess with optional arguments and handle errors.
|
8 |
+
Returns True if successful, False otherwise.
|
9 |
+
"""
|
10 |
+
if not os.path.isfile(script_path):
|
11 |
+
print(f"Script not found: {script_path}")
|
12 |
+
return False
|
13 |
+
|
14 |
+
try:
|
15 |
+
command = [sys.executable, script_path]
|
16 |
+
if args:
|
17 |
+
command.extend(args)
|
18 |
+
result = subprocess.run(
|
19 |
+
command,
|
20 |
+
check=True,
|
21 |
+
text=True,
|
22 |
+
capture_output=True
|
23 |
+
)
|
24 |
+
print(f"Successfully executed {script_path}")
|
25 |
+
print(result.stdout)
|
26 |
+
return True
|
27 |
+
except subprocess.CalledProcessError as e:
|
28 |
+
print(f"Error executing {script_path}:")
|
29 |
+
print(e.stderr)
|
30 |
+
return False
|
31 |
+
except Exception as e:
|
32 |
+
print(f"Unexpected error executing {script_path}: {str(e)}")
|
33 |
+
return False
|
34 |
+
|
35 |
+
def main():
|
36 |
+
"""
|
37 |
+
Main function to execute download_ckpts.py with proper error handling.
|
38 |
+
"""
|
39 |
+
scripts_dir = "scripts"
|
40 |
+
scripts = [
|
41 |
+
{
|
42 |
+
"path": os.path.join(scripts_dir, "download_ckpts.py"),
|
43 |
+
"args": [] # Empty list for args to avoid NoneType issues
|
44 |
+
},
|
45 |
+
{
|
46 |
+
"path": os.path.join(scripts_dir, "setup_third_party.py"),
|
47 |
+
"args": []
|
48 |
+
}
|
49 |
+
]
|
50 |
+
|
51 |
+
for script in scripts:
|
52 |
+
script_path = script["path"]
|
53 |
+
args = script.get("args", []) # Safely get args with default empty list
|
54 |
+
print(f"Starting execution of {script_path}{' with args: ' + ' '.join(args) if args else ''}\n")
|
55 |
+
|
56 |
+
if not run_script(script_path, args):
|
57 |
+
print(f"Stopping execution due to error in {script_path}")
|
58 |
+
sys.exit(1)
|
59 |
+
|
60 |
+
print(f"Completed execution of {script_path}\n")
|
61 |
+
|
62 |
+
if __name__ == "__main__":
|
63 |
+
main()
|
apps/gradio_app/static/outer_scale_warning.js
ADDED
@@ -0,0 +1,11 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
(value) => {
|
2 |
+
const warningElement = document.getElementById('warning-text');
|
3 |
+
if (warningElement) {
|
4 |
+
if (value > 4) {
|
5 |
+
warningElement.innerHTML = '<span style="color:red">To ensure optimal output quality, please set the <code>Outer Scale</code> to a value of 4 or less. The suggested range is from 1 to 4.</span>';
|
6 |
+
} else {
|
7 |
+
warningElement.innerHTML = '';
|
8 |
+
}
|
9 |
+
}
|
10 |
+
return value; // Return the value to maintain slider functionality
|
11 |
+
}
|
apps/gradio_app/static/styles.css
ADDED
@@ -0,0 +1,543 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
/* @import url('https://fonts.googleapis.com/css2?family=Inter:wght@400;500;600;700;800&display=swap'); */
|
2 |
+
/* ─── palette ───────────────────────────────────────────── */
|
3 |
+
body, .gradio-container {
|
4 |
+
font-family: 'Inter', sans-serif;
|
5 |
+
background: #FFFBF7;
|
6 |
+
color: #0F172A;
|
7 |
+
}
|
8 |
+
a {
|
9 |
+
color: #F97316;
|
10 |
+
text-decoration: none;
|
11 |
+
font-weight: 600;
|
12 |
+
}
|
13 |
+
a:hover { color: #C2410C; }
|
14 |
+
/* ─── headline ──────────────────────────────────────────── */
|
15 |
+
#titlebar {
|
16 |
+
text-align: center;
|
17 |
+
margin-top: 2.4rem;
|
18 |
+
margin-bottom: .9rem;
|
19 |
+
}
|
20 |
+
/* ─── card look ─────────────────────────────────────────── */
|
21 |
+
.gr-block,
|
22 |
+
.gr-box,
|
23 |
+
.gr-row,
|
24 |
+
#cite-wrapper {
|
25 |
+
border: 1px solid #F8C89B;
|
26 |
+
border-radius: 10px;
|
27 |
+
background: #fff;
|
28 |
+
box-shadow: 0 3px 6px rgba(0, 0, 0, .05);
|
29 |
+
}
|
30 |
+
.gr-gallery-item { background: #fff; }
|
31 |
+
/* ─── controls / inputs ─────────────────────────────────── */
|
32 |
+
.gr-button-primary,
|
33 |
+
#copy-btn {
|
34 |
+
background: linear-gradient(90deg, #F97316 0%, #C2410C 100%);
|
35 |
+
border: none;
|
36 |
+
color: #fff;
|
37 |
+
border-radius: 6px;
|
38 |
+
font-weight: 600;
|
39 |
+
transition: transform .12s ease, box-shadow .12s ease;
|
40 |
+
}
|
41 |
+
.gr-button-primary:hover,
|
42 |
+
#copy-btn:hover {
|
43 |
+
transform: translateY(-2px);
|
44 |
+
box-shadow: 0 4px 12px rgba(249, 115, 22, .35);
|
45 |
+
}
|
46 |
+
.gr-dropdown input {
|
47 |
+
border: 1px solid #F9731699;
|
48 |
+
}
|
49 |
+
.preview img,
|
50 |
+
.preview canvas { object-fit: contain !important; }
|
51 |
+
/* ─── hero section ─────────────────────────────────────── */
|
52 |
+
#hero-wrapper { text-align: center; }
|
53 |
+
#hero-badge {
|
54 |
+
display: inline-block;
|
55 |
+
padding: .85rem 1.2rem;
|
56 |
+
border-radius: 8px;
|
57 |
+
background: #FFEAD2;
|
58 |
+
border: 1px solid #F9731655;
|
59 |
+
font-size: .95rem;
|
60 |
+
font-weight: 600;
|
61 |
+
margin-bottom: .5rem;
|
62 |
+
}
|
63 |
+
#hero-links {
|
64 |
+
font-size: .95rem;
|
65 |
+
font-weight: 600;
|
66 |
+
margin-bottom: 1.6rem;
|
67 |
+
}
|
68 |
+
#hero-links img {
|
69 |
+
height: 22px;
|
70 |
+
vertical-align: middle;
|
71 |
+
margin-left: .55rem;
|
72 |
+
}
|
73 |
+
/* ─── score area ───────────────────────────────────────── */
|
74 |
+
#score-area {
|
75 |
+
text-align: center;
|
76 |
+
}
|
77 |
+
.title-container {
|
78 |
+
display: flex;
|
79 |
+
align-items: center;
|
80 |
+
gap: 12px;
|
81 |
+
justify-content: center;
|
82 |
+
margin-bottom: 10px;
|
83 |
+
text-align: center;
|
84 |
+
}
|
85 |
+
.match-badge {
|
86 |
+
display: inline-block;
|
87 |
+
padding: .35rem .9rem;
|
88 |
+
border-radius: 9999px;
|
89 |
+
font-weight: 600;
|
90 |
+
font-size: 1.25rem;
|
91 |
+
}
|
92 |
+
/* ─── citation card ────────────────────────────────────── */
|
93 |
+
#cite-wrapper {
|
94 |
+
position: relative;
|
95 |
+
padding: .9rem 1rem;
|
96 |
+
margin-top: 2rem;
|
97 |
+
}
|
98 |
+
#cite-wrapper code {
|
99 |
+
font-family: SFMono-Regular, Consolas, monospace;
|
100 |
+
font-size: .84rem;
|
101 |
+
white-space: pre-wrap;
|
102 |
+
color: #0F172A;
|
103 |
+
}
|
104 |
+
#copy-btn {
|
105 |
+
position: absolute;
|
106 |
+
top: .55rem;
|
107 |
+
right: .6rem;
|
108 |
+
padding: .18rem .7rem;
|
109 |
+
font-size: .72rem;
|
110 |
+
line-height: 1;
|
111 |
+
}
|
112 |
+
/* ─── dark mode ────────────────────────────────────── */
|
113 |
+
.dark body,
|
114 |
+
.dark .gradio-container {
|
115 |
+
background-color: #332a22;
|
116 |
+
color: #e5e7eb;
|
117 |
+
}
|
118 |
+
.dark .gr-block,
|
119 |
+
.dark .gr-box,
|
120 |
+
.dark .gr-row {
|
121 |
+
background-color: #332a22;
|
122 |
+
border: 1px solid #4b5563;
|
123 |
+
}
|
124 |
+
.dark .gr-dropdown input {
|
125 |
+
background-color: #332a22;
|
126 |
+
color: #f1f5f9;
|
127 |
+
border: 1px solid #F97316aa;
|
128 |
+
}
|
129 |
+
.dark #hero-badge {
|
130 |
+
background: #334155;
|
131 |
+
border: 1px solid #F9731655;
|
132 |
+
color: #fefefe;
|
133 |
+
}
|
134 |
+
.dark #cite-wrapper {
|
135 |
+
background-color: #473f38;
|
136 |
+
}
|
137 |
+
.dark #bibtex {
|
138 |
+
color: #f8fafc !important;
|
139 |
+
}
|
140 |
+
.dark .card {
|
141 |
+
background-color: #473f38;
|
142 |
+
}
|
143 |
+
/* ─── switch logo for light/dark theme ─────────────── */
|
144 |
+
.logo-dark { display: none; }
|
145 |
+
.dark .logo-light { display: none; }
|
146 |
+
.dark .logo-dark { display: inline; }
|
147 |
+
|
148 |
+
/* https://fonts.googleapis.com/css2?family=Inter:wght@400;500;600;700;800&display=swap */
|
149 |
+
|
150 |
+
/* cyrillic-ext */
|
151 |
+
@font-face {
|
152 |
+
font-family: 'Inter';
|
153 |
+
font-style: normal;
|
154 |
+
font-weight: 400;
|
155 |
+
font-display: swap;
|
156 |
+
src: url(https://fonts.gstatic.com/s/inter/v19/UcC73FwrK3iLTeHuS_nVMrMxCp50SjIa2JL7SUc.woff2) format('woff2');
|
157 |
+
unicode-range: U+0460-052F, U+1C80-1C8A, U+20B4, U+2DE0-2DFF, U+A640-A69F, U+FE2E-FE2F;
|
158 |
+
}
|
159 |
+
/* cyrillic */
|
160 |
+
@font-face {
|
161 |
+
font-family: 'Inter';
|
162 |
+
font-style: normal;
|
163 |
+
font-weight: 400;
|
164 |
+
font-display: swap;
|
165 |
+
src: url(https://fonts.gstatic.com/s/inter/v19/UcC73FwrK3iLTeHuS_nVMrMxCp50SjIa0ZL7SUc.woff2) format('woff2');
|
166 |
+
unicode-range: U+0301, U+0400-045F, U+0490-0491, U+04B0-04B1, U+2116;
|
167 |
+
}
|
168 |
+
/* greek-ext */
|
169 |
+
@font-face {
|
170 |
+
font-family: 'Inter';
|
171 |
+
font-style: normal;
|
172 |
+
font-weight: 400;
|
173 |
+
font-display: swap;
|
174 |
+
src: url(https://fonts.gstatic.com/s/inter/v19/UcC73FwrK3iLTeHuS_nVMrMxCp50SjIa2ZL7SUc.woff2) format('woff2');
|
175 |
+
unicode-range: U+1F00-1FFF;
|
176 |
+
}
|
177 |
+
/* greek */
|
178 |
+
@font-face {
|
179 |
+
font-family: 'Inter';
|
180 |
+
font-style: normal;
|
181 |
+
font-weight: 400;
|
182 |
+
font-display: swap;
|
183 |
+
src: url(https://fonts.gstatic.com/s/inter/v19/UcC73FwrK3iLTeHuS_nVMrMxCp50SjIa1pL7SUc.woff2) format('woff2');
|
184 |
+
unicode-range: U+0370-0377, U+037A-037F, U+0384-038A, U+038C, U+038E-03A1, U+03A3-03FF;
|
185 |
+
}
|
186 |
+
/* vietnamese */
|
187 |
+
@font-face {
|
188 |
+
font-family: 'Inter';
|
189 |
+
font-style: normal;
|
190 |
+
font-weight: 400;
|
191 |
+
font-display: swap;
|
192 |
+
src: url(https://fonts.gstatic.com/s/inter/v19/UcC73FwrK3iLTeHuS_nVMrMxCp50SjIa2pL7SUc.woff2) format('woff2');
|
193 |
+
unicode-range: U+0102-0103, U+0110-0111, U+0128-0129, U+0168-0169, U+01A0-01A1, U+01AF-01B0, U+0300-0301, U+0303-0304, U+0308-0309, U+0323, U+0329, U+1EA0-1EF9, U+20AB;
|
194 |
+
}
|
195 |
+
/* latin-ext */
|
196 |
+
@font-face {
|
197 |
+
font-family: 'Inter';
|
198 |
+
font-style: normal;
|
199 |
+
font-weight: 400;
|
200 |
+
font-display: swap;
|
201 |
+
src: url(https://fonts.gstatic.com/s/inter/v19/UcC73FwrK3iLTeHuS_nVMrMxCp50SjIa25L7SUc.woff2) format('woff2');
|
202 |
+
unicode-range: U+0100-02BA, U+02BD-02C5, U+02C7-02CC, U+02CE-02D7, U+02DD-02FF, U+0304, U+0308, U+0329, U+1D00-1DBF, U+1E00-1E9F, U+1EF2-1EFF, U+2020, U+20A0-20AB, U+20AD-20C0, U+2113, U+2C60-2C7F, U+A720-A7FF;
|
203 |
+
}
|
204 |
+
/* latin */
|
205 |
+
@font-face {
|
206 |
+
font-family: 'Inter';
|
207 |
+
font-style: normal;
|
208 |
+
font-weight: 400;
|
209 |
+
font-display: swap;
|
210 |
+
src: url(https://fonts.gstatic.com/s/inter/v19/UcC73FwrK3iLTeHuS_nVMrMxCp50SjIa1ZL7.woff2) format('woff2');
|
211 |
+
unicode-range: U+0000-00FF, U+0131, U+0152-0153, U+02BB-02BC, U+02C6, U+02DA, U+02DC, U+0304, U+0308, U+0329, U+2000-206F, U+20AC, U+2122, U+2191, U+2193, U+2212, U+2215, U+FEFF, U+FFFD;
|
212 |
+
}
|
213 |
+
/* cyrillic-ext */
|
214 |
+
@font-face {
|
215 |
+
font-family: 'Inter';
|
216 |
+
font-style: normal;
|
217 |
+
font-weight: 500;
|
218 |
+
font-display: swap;
|
219 |
+
src: url(https://fonts.gstatic.com/s/inter/v19/UcC73FwrK3iLTeHuS_nVMrMxCp50SjIa2JL7SUc.woff2) format('woff2');
|
220 |
+
unicode-range: U+0460-052F, U+1C80-1C8A, U+20B4, U+2DE0-2DFF, U+A640-A69F, U+FE2E-FE2F;
|
221 |
+
}
|
222 |
+
/* cyrillic */
|
223 |
+
@font-face {
|
224 |
+
font-family: 'Inter';
|
225 |
+
font-style: normal;
|
226 |
+
font-weight: 500;
|
227 |
+
font-display: swap;
|
228 |
+
src: url(https://fonts.gstatic.com/s/inter/v19/UcC73FwrK3iLTeHuS_nVMrMxCp50SjIa0ZL7SUc.woff2) format('woff2');
|
229 |
+
unicode-range: U+0301, U+0400-045F, U+0490-0491, U+04B0-04B1, U+2116;
|
230 |
+
}
|
231 |
+
/* greek-ext */
|
232 |
+
@font-face {
|
233 |
+
font-family: 'Inter';
|
234 |
+
font-style: normal;
|
235 |
+
font-weight: 500;
|
236 |
+
font-display: swap;
|
237 |
+
src: url(https://fonts.gstatic.com/s/inter/v19/UcC73FwrK3iLTeHuS_nVMrMxCp50SjIa2ZL7SUc.woff2) format('woff2');
|
238 |
+
unicode-range: U+1F00-1FFF;
|
239 |
+
}
|
240 |
+
/* greek */
|
241 |
+
@font-face {
|
242 |
+
font-family: 'Inter';
|
243 |
+
font-style: normal;
|
244 |
+
font-weight: 500;
|
245 |
+
font-display: swap;
|
246 |
+
src: url(https://fonts.gstatic.com/s/inter/v19/UcC73FwrK3iLTeHuS_nVMrMxCp50SjIa1pL7SUc.woff2) format('woff2');
|
247 |
+
unicode-range: U+0370-0377, U+037A-037F, U+0384-038A, U+038C, U+038E-03A1, U+03A3-03FF;
|
248 |
+
}
|
249 |
+
/* vietnamese */
|
250 |
+
@font-face {
|
251 |
+
font-family: 'Inter';
|
252 |
+
font-style: normal;
|
253 |
+
font-weight: 500;
|
254 |
+
font-display: swap;
|
255 |
+
src: url(https://fonts.gstatic.com/s/inter/v19/UcC73FwrK3iLTeHuS_nVMrMxCp50SjIa2pL7SUc.woff2) format('woff2');
|
256 |
+
unicode-range: U+0102-0103, U+0110-0111, U+0128-0129, U+0168-0169, U+01A0-01A1, U+01AF-01B0, U+0300-0301, U+0303-0304, U+0308-0309, U+0323, U+0329, U+1EA0-1EF9, U+20AB;
|
257 |
+
}
|
258 |
+
/* latin-ext */
|
259 |
+
@font-face {
|
260 |
+
font-family: 'Inter';
|
261 |
+
font-style: normal;
|
262 |
+
font-weight: 500;
|
263 |
+
font-display: swap;
|
264 |
+
src: url(https://fonts.gstatic.com/s/inter/v19/UcC73FwrK3iLTeHuS_nVMrMxCp50SjIa25L7SUc.woff2) format('woff2');
|
265 |
+
unicode-range: U+0100-02BA, U+02BD-02C5, U+02C7-02CC, U+02CE-02D7, U+02DD-02FF, U+0304, U+0308, U+0329, U+1D00-1DBF, U+1E00-1E9F, U+1EF2-1EFF, U+2020, U+20A0-20AB, U+20AD-20C0, U+2113, U+2C60-2C7F, U+A720-A7FF;
|
266 |
+
}
|
267 |
+
/* latin */
|
268 |
+
@font-face {
|
269 |
+
font-family: 'Inter';
|
270 |
+
font-style: normal;
|
271 |
+
font-weight: 500;
|
272 |
+
font-display: swap;
|
273 |
+
src: url(https://fonts.gstatic.com/s/inter/v19/UcC73FwrK3iLTeHuS_nVMrMxCp50SjIa1ZL7.woff2) format('woff2');
|
274 |
+
unicode-range: U+0000-00FF, U+0131, U+0152-0153, U+02BB-02BC, U+02C6, U+02DA, U+02DC, U+0304, U+0308, U+0329, U+2000-206F, U+20AC, U+2122, U+2191, U+2193, U+2212, U+2215, U+FEFF, U+FFFD;
|
275 |
+
}
|
276 |
+
/* cyrillic-ext */
|
277 |
+
@font-face {
|
278 |
+
font-family: 'Inter';
|
279 |
+
font-style: normal;
|
280 |
+
font-weight: 600;
|
281 |
+
font-display: swap;
|
282 |
+
src: url(https://fonts.gstatic.com/s/inter/v19/UcC73FwrK3iLTeHuS_nVMrMxCp50SjIa2JL7SUc.woff2) format('woff2');
|
283 |
+
unicode-range: U+0460-052F, U+1C80-1C8A, U+20B4, U+2DE0-2DFF, U+A640-A69F, U+FE2E-FE2F;
|
284 |
+
}
|
285 |
+
/* cyrillic */
|
286 |
+
@font-face {
|
287 |
+
font-family: 'Inter';
|
288 |
+
font-style: normal;
|
289 |
+
font-weight: 600;
|
290 |
+
font-display: swap;
|
291 |
+
src: url(https://fonts.gstatic.com/s/inter/v19/UcC73FwrK3iLTeHuS_nVMrMxCp50SjIa0ZL7SUc.woff2) format('woff2');
|
292 |
+
unicode-range: U+0301, U+0400-045F, U+0490-0491, U+04B0-04B1, U+2116;
|
293 |
+
}
|
294 |
+
/* greek-ext */
|
295 |
+
@font-face {
|
296 |
+
font-family: 'Inter';
|
297 |
+
font-style: normal;
|
298 |
+
font-weight: 600;
|
299 |
+
font-display: swap;
|
300 |
+
src: url(https://fonts.gstatic.com/s/inter/v19/UcC73FwrK3iLTeHuS_nVMrMxCp50SjIa2ZL7SUc.woff2) format('woff2');
|
301 |
+
unicode-range: U+1F00-1FFF;
|
302 |
+
}
|
303 |
+
/* greek */
|
304 |
+
@font-face {
|
305 |
+
font-family: 'Inter';
|
306 |
+
font-style: normal;
|
307 |
+
font-weight: 600;
|
308 |
+
font-display: swap;
|
309 |
+
src: url(https://fonts.gstatic.com/s/inter/v19/UcC73FwrK3iLTeHuS_nVMrMxCp50SjIa1pL7SUc.woff2) format('woff2');
|
310 |
+
unicode-range: U+0370-0377, U+037A-037F, U+0384-038A, U+038C, U+038E-03A1, U+03A3-03FF;
|
311 |
+
}
|
312 |
+
/* vietnamese */
|
313 |
+
@font-face {
|
314 |
+
font-family: 'Inter';
|
315 |
+
font-style: normal;
|
316 |
+
font-weight: 600;
|
317 |
+
font-display: swap;
|
318 |
+
src: url(https://fonts.gstatic.com/s/inter/v19/UcC73FwrK3iLTeHuS_nVMrMxCp50SjIa2pL7SUc.woff2) format('woff2');
|
319 |
+
unicode-range: U+0102-0103, U+0110-0111, U+0128-0129, U+0168-0169, U+01A0-01A1, U+01AF-01B0, U+0300-0301, U+0303-0304, U+0308-0309, U+0323, U+0329, U+1EA0-1EF9, U+20AB;
|
320 |
+
}
|
321 |
+
/* latin-ext */
|
322 |
+
@font-face {
|
323 |
+
font-family: 'Inter';
|
324 |
+
font-style: normal;
|
325 |
+
font-weight: 600;
|
326 |
+
font-display: swap;
|
327 |
+
src: url(https://fonts.gstatic.com/s/inter/v19/UcC73FwrK3iLTeHuS_nVMrMxCp50SjIa25L7SUc.woff2) format('woff2');
|
328 |
+
unicode-range: U+0100-02BA, U+02BD-02C5, U+02C7-02CC, U+02CE-02D7, U+02DD-02FF, U+0304, U+0308, U+0329, U+1D00-1DBF, U+1E00-1E9F, U+1EF2-1EFF, U+2020, U+20A0-20AB, U+20AD-20C0, U+2113, U+2C60-2C7F, U+A720-A7FF;
|
329 |
+
}
|
330 |
+
/* latin */
|
331 |
+
@font-face {
|
332 |
+
font-family: 'Inter';
|
333 |
+
font-style: normal;
|
334 |
+
font-weight: 600;
|
335 |
+
font-display: swap;
|
336 |
+
src: url(https://fonts.gstatic.com/s/inter/v19/UcC73FwrK3iLTeHuS_nVMrMxCp50SjIa1ZL7.woff2) format('woff2');
|
337 |
+
unicode-range: U+0000-00FF, U+0131, U+0152-0153, U+02BB-02BC, U+02C6, U+02DA, U+02DC, U+0304, U+0308, U+0329, U+2000-206F, U+20AC, U+2122, U+2191, U+2193, U+2212, U+2215, U+FEFF, U+FFFD;
|
338 |
+
}
|
339 |
+
/* cyrillic-ext */
|
340 |
+
@font-face {
|
341 |
+
font-family: 'Inter';
|
342 |
+
font-style: normal;
|
343 |
+
font-weight: 700;
|
344 |
+
font-display: swap;
|
345 |
+
src: url(https://fonts.gstatic.com/s/inter/v19/UcC73FwrK3iLTeHuS_nVMrMxCp50SjIa2JL7SUc.woff2) format('woff2');
|
346 |
+
unicode-range: U+0460-052F, U+1C80-1C8A, U+20B4, U+2DE0-2DFF, U+A640-A69F, U+FE2E-FE2F;
|
347 |
+
}
|
348 |
+
/* cyrillic */
|
349 |
+
@font-face {
|
350 |
+
font-family: 'Inter';
|
351 |
+
font-style: normal;
|
352 |
+
font-weight: 700;
|
353 |
+
font-display: swap;
|
354 |
+
src: url(https://fonts.gstatic.com/s/inter/v19/UcC73FwrK3iLTeHuS_nVMrMxCp50SjIa0ZL7SUc.woff2) format('woff2');
|
355 |
+
unicode-range: U+0301, U+0400-045F, U+0490-0491, U+04B0-04B1, U+2116;
|
356 |
+
}
|
357 |
+
/* greek-ext */
|
358 |
+
@font-face {
|
359 |
+
font-family: 'Inter';
|
360 |
+
font-style: normal;
|
361 |
+
font-weight: 700;
|
362 |
+
font-display: swap;
|
363 |
+
src: url(https://fonts.gstatic.com/s/inter/v19/UcC73FwrK3iLTeHuS_nVMrMxCp50SjIa2ZL7SUc.woff2) format('woff2');
|
364 |
+
unicode-range: U+1F00-1FFF;
|
365 |
+
}
|
366 |
+
/* greek */
|
367 |
+
@font-face {
|
368 |
+
font-family: 'Inter';
|
369 |
+
font-style: normal;
|
370 |
+
font-weight: 700;
|
371 |
+
font-display: swap;
|
372 |
+
src: url(https://fonts.gstatic.com/s/inter/v19/UcC73FwrK3iLTeHuS_nVMrMxCp50SjIa1pL7SUc.woff2) format('woff2');
|
373 |
+
unicode-range: U+0370-0377, U+037A-037F, U+0384-038A, U+038C, U+038E-03A1, U+03A3-03FF;
|
374 |
+
}
|
375 |
+
/* vietnamese */
|
376 |
+
@font-face {
|
377 |
+
font-family: 'Inter';
|
378 |
+
font-style: normal;
|
379 |
+
font-weight: 700;
|
380 |
+
font-display: swap;
|
381 |
+
src: url(https://fonts.gstatic.com/s/inter/v19/UcC73FwrK3iLTeHuS_nVMrMxCp50SjIa2pL7SUc.woff2) format('woff2');
|
382 |
+
unicode-range: U+0102-0103, U+0110-0111, U+0128-0129, U+0168-0169, U+01A0-01A1, U+01AF-01B0, U+0300-0301, U+0303-0304, U+0308-0309, U+0323, U+0329, U+1EA0-1EF9, U+20AB;
|
383 |
+
}
|
384 |
+
/* latin-ext */
|
385 |
+
@font-face {
|
386 |
+
font-family: 'Inter';
|
387 |
+
font-style: normal;
|
388 |
+
font-weight: 700;
|
389 |
+
font-display: swap;
|
390 |
+
src: url(https://fonts.gstatic.com/s/inter/v19/UcC73FwrK3iLTeHuS_nVMrMxCp50SjIa25L7SUc.woff2) format('woff2');
|
391 |
+
unicode-range: U+0100-02BA, U+02BD-02C5, U+02C7-02CC, U+02CE-02D7, U+02DD-02FF, U+0304, U+0308, U+0329, U+1D00-1DBF, U+1E00-1E9F, U+1EF2-1EFF, U+2020, U+20A0-20AB, U+20AD-20C0, U+2113, U+2C60-2C7F, U+A720-A7FF;
|
392 |
+
}
|
393 |
+
/* latin */
|
394 |
+
@font-face {
|
395 |
+
font-family: 'Inter';
|
396 |
+
font-style: normal;
|
397 |
+
font-weight: 700;
|
398 |
+
font-display: swap;
|
399 |
+
src: url(https://fonts.gstatic.com/s/inter/v19/UcC73FwrK3iLTeHuS_nVMrMxCp50SjIa1ZL7.woff2) format('woff2');
|
400 |
+
unicode-range: U+0000-00FF, U+0131, U+0152-0153, U+02BB-02BC, U+02C6, U+02DA, U+02DC, U+0304, U+0308, U+0329, U+2000-206F, U+20AC, U+2122, U+2191, U+2193, U+2212, U+2215, U+FEFF, U+FFFD;
|
401 |
+
}
|
402 |
+
/* cyrillic-ext */
|
403 |
+
@font-face {
|
404 |
+
font-family: 'Inter';
|
405 |
+
font-style: normal;
|
406 |
+
font-weight: 800;
|
407 |
+
font-display: swap;
|
408 |
+
src: url(https://fonts.gstatic.com/s/inter/v19/UcC73FwrK3iLTeHuS_nVMrMxCp50SjIa2JL7SUc.woff2) format('woff2');
|
409 |
+
unicode-range: U+0460-052F, U+1C80-1C8A, U+20B4, U+2DE0-2DFF, U+A640-A69F, U+FE2E-FE2F;
|
410 |
+
}
|
411 |
+
/* cyrillic */
|
412 |
+
@font-face {
|
413 |
+
font-family: 'Inter';
|
414 |
+
font-style: normal;
|
415 |
+
font-weight: 800;
|
416 |
+
font-display: swap;
|
417 |
+
src: url(https://fonts.gstatic.com/s/inter/v19/UcC73FwrK3iLTeHuS_nVMrMxCp50SjIa0ZL7SUc.woff2) format('woff2');
|
418 |
+
unicode-range: U+0301, U+0400-045F, U+0490-0491, U+04B0-04B1, U+2116;
|
419 |
+
}
|
420 |
+
/* greek-ext */
|
421 |
+
@font-face {
|
422 |
+
font-family: 'Inter';
|
423 |
+
font-style: normal;
|
424 |
+
font-weight: 800;
|
425 |
+
font-display: swap;
|
426 |
+
src: url(https://fonts.gstatic.com/s/inter/v19/UcC73FwrK3iLTeHuS_nVMrMxCp50SjIa2ZL7SUc.woff2) format('woff2');
|
427 |
+
unicode-range: U+1F00-1FFF;
|
428 |
+
}
|
429 |
+
/* greek */
|
430 |
+
@font-face {
|
431 |
+
font-family: 'Inter';
|
432 |
+
font-style: normal;
|
433 |
+
font-weight: 800;
|
434 |
+
font-display: swap;
|
435 |
+
src: url(https://fonts.gstatic.com/s/inter/v19/UcC73FwrK3iLTeHuS_nVMrMxCp50SjIa1pL7SUc.woff2) format('woff2');
|
436 |
+
unicode-range: U+0370-0377, U+037A-037F, U+0384-038A, U+038C, U+038E-03A1, U+03A3-03FF;
|
437 |
+
}
|
438 |
+
/* vietnamese */
|
439 |
+
@font-face {
|
440 |
+
font-family: 'Inter';
|
441 |
+
font-style: normal;
|
442 |
+
font-weight: 800;
|
443 |
+
font-display: swap;
|
444 |
+
src: url(https://fonts.gstatic.com/s/inter/v19/UcC73FwrK3iLTeHuS_nVMrMxCp50SjIa2pL7SUc.woff2) format('woff2');
|
445 |
+
unicode-range: U+0102-0103, U+0110-0111, U+0128-0129, U+0168-0169, U+01A0-01A1, U+01AF-01B0, U+0300-0301, U+0303-0304, U+0308-0309, U+0323, U+0329, U+1EA0-1EF9, U+20AB;
|
446 |
+
}
|
447 |
+
/* latin-ext */
|
448 |
+
@font-face {
|
449 |
+
font-family: 'Inter';
|
450 |
+
font-style: normal;
|
451 |
+
font-weight: 800;
|
452 |
+
font-display: swap;
|
453 |
+
src: url(https://fonts.gstatic.com/s/inter/v19/UcC73FwrK3iLTeHuS_nVMrMxCp50SjIa25L7SUc.woff2) format('woff2');
|
454 |
+
unicode-range: U+0100-02BA, U+02BD-02C5, U+02C7-02CC, U+02CE-02D7, U+02DD-02FF, U+0304, U+0308, U+0329, U+1D00-1DBF, U+1E00-1E9F, U+1EF2-1EFF, U+2020, U+20A0-20AB, U+20AD-20C0, U+2113, U+2C60-2C7F, U+A720-A7FF;
|
455 |
+
}
|
456 |
+
/* latin */
|
457 |
+
@font-face {
|
458 |
+
font-family: 'Inter';
|
459 |
+
font-style: normal;
|
460 |
+
font-weight: 800;
|
461 |
+
font-display: swap;
|
462 |
+
src: url(https://fonts.gstatic.com/s/inter/v19/UcC73FwrK3iLTeHuS_nVMrMxCp50SjIa1ZL7.woff2) format('woff2');
|
463 |
+
unicode-range: U+0000-00FF, U+0131, U+0152-0153, U+02BB-02BC, U+02C6, U+02DA, U+02DC, U+0304, U+0308, U+0329, U+2000-206F, U+20AC, U+2122, U+2191, U+2193, U+2212, U+2215, U+FEFF, U+FFFD;
|
464 |
+
}
|
465 |
+
|
466 |
+
/* title_css */
|
467 |
+
#title {
|
468 |
+
font-size: 2.6rem;
|
469 |
+
font-weight: 800;
|
470 |
+
margin: 0;
|
471 |
+
line-height: 1.25;
|
472 |
+
color: #0F172A;
|
473 |
+
}
|
474 |
+
/* brand class is passed in title parameter */
|
475 |
+
#title .brand {
|
476 |
+
background: linear-gradient(90deg, #F97316 0%, #C2410C 90%);
|
477 |
+
-webkit-background-clip: text;
|
478 |
+
color: transparent;
|
479 |
+
}
|
480 |
+
.dark #title {
|
481 |
+
color: #f8fafc;
|
482 |
+
}
|
483 |
+
.title-container {
|
484 |
+
display: flex;
|
485 |
+
align-items: center;
|
486 |
+
gap: 12px;
|
487 |
+
justify-content: center;
|
488 |
+
margin-bottom: 10px;
|
489 |
+
text-align: center;
|
490 |
+
}
|
491 |
+
|
492 |
+
/* Dark Mode */
|
493 |
+
@media (prefers-color-scheme: dark) {
|
494 |
+
body { @extend .dark; }
|
495 |
+
}
|
496 |
+
/* Smaller size for input image */
|
497 |
+
.input-image img {
|
498 |
+
max-width: 300px;
|
499 |
+
height: auto;
|
500 |
+
}
|
501 |
+
/* Larger size for output image */
|
502 |
+
.output-image img {
|
503 |
+
max-width: 500px;
|
504 |
+
height: auto;
|
505 |
+
}
|
506 |
+
|
507 |
+
/* Add styling for warning message */
|
508 |
+
.warning-message {
|
509 |
+
color: red;
|
510 |
+
font-size: 14px;
|
511 |
+
margin-top: 5px;
|
512 |
+
display: block;
|
513 |
+
}
|
514 |
+
#warning-text {
|
515 |
+
min-height: 20px; /* Ensure space for warning */
|
516 |
+
}
|
517 |
+
/*Components for Gradio App*/
|
518 |
+
.quote-container {
|
519 |
+
border-left: 5px solid #007bff;
|
520 |
+
padding-left: 15px;
|
521 |
+
margin-bottom: 15px;
|
522 |
+
font-style: italic;
|
523 |
+
}
|
524 |
+
.attribution p {
|
525 |
+
margin: 10px 0;
|
526 |
+
}
|
527 |
+
.badge {
|
528 |
+
display: inline-block;
|
529 |
+
border-radius: 4px;
|
530 |
+
text-decoration: none;
|
531 |
+
font-size: 14px;
|
532 |
+
transition: background-color 0.3s;
|
533 |
+
}
|
534 |
+
.badge:hover {
|
535 |
+
background-color: #0056b3;
|
536 |
+
}
|
537 |
+
.badge img {
|
538 |
+
vertical-align: middle;
|
539 |
+
margin-right: 5px;
|
540 |
+
}
|
541 |
+
.source {
|
542 |
+
font-size: 14px;
|
543 |
+
}
|
apps/old-gradio_app.py
ADDED
@@ -0,0 +1,136 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
import gradio as gr
|
2 |
+
import os
|
3 |
+
import sys
|
4 |
+
import json
|
5 |
+
from PIL import Image
|
6 |
+
|
7 |
+
from gradio_app.project_info import (
|
8 |
+
CONTENT_DESCRIPTION,
|
9 |
+
CONTENT_IN_1, CONTENT_IN_2,
|
10 |
+
CONTENT_OUT_1, CONTENT_OUT_2
|
11 |
+
)
|
12 |
+
# Add the project root directory to the Python path
|
13 |
+
sys.path.append(os.path.abspath(os.path.join(os.path.dirname(__file__), '..')))
|
14 |
+
|
15 |
+
from src.anime_super_resolution.infer import infer
|
16 |
+
|
17 |
+
def run_inference(input_image, model_id, outer_scale):
|
18 |
+
if not input_image:
|
19 |
+
return None, "Please upload an image."
|
20 |
+
|
21 |
+
models_config_path = "configs/model_ckpts.yaml"
|
22 |
+
try:
|
23 |
+
output_image = infer(
|
24 |
+
input_path=input_image,
|
25 |
+
model_id=model_id,
|
26 |
+
models_config_path=models_config_path,
|
27 |
+
outer_scale=outer_scale,
|
28 |
+
)
|
29 |
+
return output_image, "Inference completed successfully!"
|
30 |
+
except Exception as e:
|
31 |
+
return None, f"Error during inference: {str(e)}"
|
32 |
+
|
33 |
+
def load_examples():
|
34 |
+
examples = []
|
35 |
+
examples_base_path = os.path.join("apps", "assets", "examples", "Real-ESRGAN-Anime-finetuning")
|
36 |
+
|
37 |
+
for folder in ["1", "2", "3", "4"]:
|
38 |
+
folder_path = os.path.join(examples_base_path, folder)
|
39 |
+
config_path = os.path.join(folder_path, "config.json")
|
40 |
+
|
41 |
+
if os.path.exists(config_path):
|
42 |
+
with open(config_path, 'r') as f:
|
43 |
+
config = json.load(f)
|
44 |
+
input_filename = config.get("input_file", "input.jpg")
|
45 |
+
output_filename = config.get("output_file", "output.jpg")
|
46 |
+
outer_scale = config.get("outer_scale", 4)
|
47 |
+
|
48 |
+
input_image_path = os.path.join(folder_path, input_filename)
|
49 |
+
output_image_path = os.path.join(folder_path, output_filename)
|
50 |
+
|
51 |
+
if os.path.exists(input_image_path) and os.path.exists(output_image_path):
|
52 |
+
input_image_data = Image.open(input_image_path)
|
53 |
+
output_image_data = Image.open(output_image_path)
|
54 |
+
examples.append([input_image_data, output_image_data, outer_scale])
|
55 |
+
|
56 |
+
return examples
|
57 |
+
|
58 |
+
def select_example(evt: gr.SelectData, examples_data):
|
59 |
+
example_index = evt.index
|
60 |
+
input_image_data, output_image_data, outer_scale = examples_data[example_index]
|
61 |
+
return input_image_data, outer_scale, output_image_data, f"Loaded example with Outer Scale: {outer_scale}"
|
62 |
+
|
63 |
+
# Load custom CSS
|
64 |
+
custom_css = open("apps/gradio_app/static/styles.css").read()
|
65 |
+
|
66 |
+
# JavaScript function to update warning_text Markdown component
|
67 |
+
outer_scale_warning = open("apps/gradio_app/static/outer_scale_warning.js").read()
|
68 |
+
|
69 |
+
# Define Gradio interface
|
70 |
+
with gr.Blocks(css=custom_css) as demo:
|
71 |
+
gr.Markdown("# Anime Super Resolution 🖼️")
|
72 |
+
gr.Markdown(CONTENT_DESCRIPTION)
|
73 |
+
gr.Markdown(CONTENT_IN_1)
|
74 |
+
gr.HTML(CONTENT_IN_2)
|
75 |
+
with gr.Row():
|
76 |
+
with gr.Column(scale=2):
|
77 |
+
input_image = gr.Image(
|
78 |
+
type="filepath",
|
79 |
+
label="Input Image",
|
80 |
+
elem_classes="input-image"
|
81 |
+
)
|
82 |
+
model_id = gr.Textbox(
|
83 |
+
label="Model ID",
|
84 |
+
value="danhtran2mind/Real-ESRGAN-Anime-finetuning"
|
85 |
+
)
|
86 |
+
|
87 |
+
outer_scale = gr.Slider(
|
88 |
+
minimum=1,
|
89 |
+
maximum=8,
|
90 |
+
step=1,
|
91 |
+
value=2,
|
92 |
+
label="Outer Scale",
|
93 |
+
elem_id="outer-scale-slider"
|
94 |
+
)
|
95 |
+
warning_text = gr.HTML(elem_id="warning-text") # Added elem_id for JS targeting
|
96 |
+
gr.Markdown(
|
97 |
+
"**Note:** For optimal output quality, set `Outer Scale` to a value between 1 and 4. "
|
98 |
+
"**Values greater than 4 are not recommended**. "
|
99 |
+
"Please ensure `Outer Scale` is greater than or equal to `Inner Scale` (default: 4)."
|
100 |
+
)
|
101 |
+
|
102 |
+
examples_data = load_examples()
|
103 |
+
submit_button = gr.Button("Run Inference")
|
104 |
+
|
105 |
+
with gr.Column(scale=3):
|
106 |
+
output_image = gr.Image(
|
107 |
+
label="Output Image",
|
108 |
+
elem_classes="output-image"
|
109 |
+
)
|
110 |
+
output_text = gr.Textbox(label="Status")
|
111 |
+
|
112 |
+
# Client-side warning update for warning_text
|
113 |
+
outer_scale.change(
|
114 |
+
fn=lambda x: x, # Pass-through function to satisfy Gradio
|
115 |
+
inputs=outer_scale,
|
116 |
+
outputs=outer_scale, # Return value to maintain slider functionality
|
117 |
+
js=outer_scale_warning # Update warning_text via JavaScript
|
118 |
+
)
|
119 |
+
|
120 |
+
gr.Examples(
|
121 |
+
examples=[[input_img, output_img, outer_scale] for input_img, output_img, outer_scale in examples_data],
|
122 |
+
inputs=[input_image, output_image, outer_scale],
|
123 |
+
label="Example Inputs",
|
124 |
+
examples_per_page=4
|
125 |
+
)
|
126 |
+
|
127 |
+
submit_button.click(
|
128 |
+
fn=run_inference,
|
129 |
+
inputs=[input_image, model_id, outer_scale],
|
130 |
+
outputs=[output_image, output_text]
|
131 |
+
)
|
132 |
+
gr.HTML(CONTENT_OUT_1)
|
133 |
+
gr.Markdown(CONTENT_OUT_2)
|
134 |
+
|
135 |
+
if __name__ == "__main__":
|
136 |
+
demo.launch(share=True) # Changed to local launch for safety; use share=True for public URL if needed
|
assets/examples/Real-ESRGAN-Anime-finetuning/1/1_x2_zoom.png
ADDED
![]() |
Git LFS Details
|
assets/examples/Real-ESRGAN-Anime-finetuning/1/1_zoom.png
ADDED
![]() |
Git LFS Details
|
assets/examples/Real-ESRGAN-Anime-finetuning/1/config.json
ADDED
@@ -0,0 +1,5 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
{
|
2 |
+
"input_file": "frame_0001_2T3.png",
|
3 |
+
"output_file": "frame_0001_2T3_real_esrgan_anime_x2.png",
|
4 |
+
"outer_scale": 2
|
5 |
+
}
|
assets/examples/Real-ESRGAN-Anime-finetuning/1/frame_0001_2T3.png
ADDED
![]() |
Git LFS Details
|
assets/examples/Real-ESRGAN-Anime-finetuning/1/frame_0001_2T3_real_esrgan_anime_x2.png
ADDED
![]() |
Git LFS Details
|
assets/examples/Real-ESRGAN-Anime-finetuning/2/2_x4_zoom.png
ADDED
![]() |
Git LFS Details
|
assets/examples/Real-ESRGAN-Anime-finetuning/2/2_zoom.png
ADDED
![]() |
Git LFS Details
|
assets/examples/Real-ESRGAN-Anime-finetuning/2/config.json
ADDED
@@ -0,0 +1,5 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
{
|
2 |
+
"input_file": "frame_0001_9T3.png",
|
3 |
+
"output_file": "frame_0001_9T3_real_esrgan_anime_x4.png",
|
4 |
+
"outer_scale": 4
|
5 |
+
}
|
assets/examples/Real-ESRGAN-Anime-finetuning/2/frame_0001_9T3.png
ADDED
![]() |
Git LFS Details
|
assets/examples/Real-ESRGAN-Anime-finetuning/2/frame_0001_9T3_real_esrgan_anime_x4.png
ADDED
![]() |
Git LFS Details
|
assets/examples/Real-ESRGAN-Anime-finetuning/3/3_x6_zoom.png
ADDED
![]() |
Git LFS Details
|
assets/examples/Real-ESRGAN-Anime-finetuning/3/3_zoom.png
ADDED
![]() |
Git LFS Details
|
assets/examples/Real-ESRGAN-Anime-finetuning/3/config.json
ADDED
@@ -0,0 +1,5 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
{
|
2 |
+
"input_file": "frame_0001_10T3.png",
|
3 |
+
"output_file": "frame_0001_10T3_real_esrgan_anime_x6.png",
|
4 |
+
"outer_scale": 6
|
5 |
+
}
|
assets/examples/Real-ESRGAN-Anime-finetuning/3/frame_0001_10T3.png
ADDED
![]() |
Git LFS Details
|
assets/examples/Real-ESRGAN-Anime-finetuning/3/frame_0001_10T3_real_esrgan_anime_x6.png
ADDED
![]() |
Git LFS Details
|
assets/examples/Real-ESRGAN-Anime-finetuning/4/4_x8_zoom.png
ADDED
![]() |
Git LFS Details
|
assets/examples/Real-ESRGAN-Anime-finetuning/4/4_zoom.png
ADDED
![]() |
Git LFS Details
|
assets/examples/Real-ESRGAN-Anime-finetuning/4/config.json
ADDED
@@ -0,0 +1,5 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
{
|
2 |
+
"input_file": "frame_0001_14T3.png",
|
3 |
+
"output_file": "frame_0001_14T3_real_esrgan_anime_x8.png",
|
4 |
+
"outer_scale": 8
|
5 |
+
}
|
assets/examples/Real-ESRGAN-Anime-finetuning/4/frame_0001_14T3.png
ADDED
![]() |
Git LFS Details
|
assets/examples/Real-ESRGAN-Anime-finetuning/4/frame_0001_14T3_real_esrgan_anime_x8.png
ADDED
![]() |
Git LFS Details
|
ckpts/.gitkeep
ADDED
File without changes
|
configs/.gitkeep
ADDED
File without changes
|
configs/Real-ESRGAN-Anime-finetuning.yml
ADDED
@@ -0,0 +1,188 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
# general settings
|
2 |
+
name: Real-ESRGAN-Anime-finetuning
|
3 |
+
model_type: RealESRGANModel
|
4 |
+
scale: 4
|
5 |
+
num_gpu: auto
|
6 |
+
manual_seed: 0
|
7 |
+
|
8 |
+
# ----------------- options for synthesizing training data in RealESRGANModel ----------------- #
|
9 |
+
# USM the ground-truth
|
10 |
+
l1_gt_usm: True
|
11 |
+
percep_gt_usm: True
|
12 |
+
gan_gt_usm: False
|
13 |
+
|
14 |
+
# the first degradation process
|
15 |
+
resize_prob: [0.2, 0.7, 0.1] # up, down, keep
|
16 |
+
resize_range: [0.15, 1.5]
|
17 |
+
gaussian_noise_prob: 0.5
|
18 |
+
noise_range: [1, 30]
|
19 |
+
poisson_scale_range: [0.05, 3]
|
20 |
+
gray_noise_prob: 0.4
|
21 |
+
jpeg_range: [30, 95]
|
22 |
+
|
23 |
+
# the second degradation process
|
24 |
+
second_blur_prob: 0.8
|
25 |
+
resize_prob2: [0.3, 0.4, 0.3] # up, down, keep
|
26 |
+
resize_range2: [0.3, 1.2]
|
27 |
+
gaussian_noise_prob2: 0.5
|
28 |
+
noise_range2: [1, 25]
|
29 |
+
poisson_scale_range2: [0.05, 2.5]
|
30 |
+
gray_noise_prob2: 0.4
|
31 |
+
jpeg_range2: [30, 95]
|
32 |
+
|
33 |
+
gt_size: 256
|
34 |
+
queue_size: 180
|
35 |
+
|
36 |
+
# dataset and data loader settings
|
37 |
+
datasets:
|
38 |
+
train:
|
39 |
+
name: DF2K+OST
|
40 |
+
type: RealESRGANDataset
|
41 |
+
dataroot_gt: './data'
|
42 |
+
meta_info: './data/meta_info/meta_info_multiscale.txt'
|
43 |
+
io_backend:
|
44 |
+
type: disk
|
45 |
+
|
46 |
+
blur_kernel_size: 21
|
47 |
+
kernel_list: ['iso', 'aniso', 'generalized_iso', 'generalized_aniso', 'plateau_iso', 'plateau_aniso']
|
48 |
+
kernel_prob: [0.45, 0.25, 0.12, 0.03, 0.12, 0.03]
|
49 |
+
sinc_prob: 0.1
|
50 |
+
blur_sigma: [0.2, 3]
|
51 |
+
betag_range: [0.5, 4]
|
52 |
+
betap_range: [1, 2]
|
53 |
+
|
54 |
+
blur_kernel_size2: 21
|
55 |
+
kernel_list2: ['iso', 'aniso', 'generalized_iso', 'generalized_aniso', 'plateau_iso', 'plateau_aniso']
|
56 |
+
kernel_prob2: [0.45, 0.25, 0.12, 0.03, 0.12, 0.03]
|
57 |
+
sinc_prob2: 0.1
|
58 |
+
blur_sigma2: [0.2, 1.5]
|
59 |
+
betag_range2: [0.5, 4]
|
60 |
+
betap_range2: [1, 2]
|
61 |
+
|
62 |
+
final_sinc_prob: 0.8
|
63 |
+
|
64 |
+
gt_size: 256
|
65 |
+
use_hflip: True
|
66 |
+
use_rot: False
|
67 |
+
|
68 |
+
# data loader
|
69 |
+
use_shuffle: true
|
70 |
+
num_worker_per_gpu: 5
|
71 |
+
batch_size_per_gpu: 10
|
72 |
+
dataset_enlarge_ratio: 1
|
73 |
+
prefetch_mode: ~
|
74 |
+
|
75 |
+
# Uncomment these for validation
|
76 |
+
# val:
|
77 |
+
# name: validation
|
78 |
+
# type: PairedImageDataset
|
79 |
+
# dataroot_gt: path_to_gt
|
80 |
+
# dataroot_lq: path_to_lq
|
81 |
+
# io_backend:
|
82 |
+
# type: disk
|
83 |
+
|
84 |
+
# network structures
|
85 |
+
network_g:
|
86 |
+
type: RRDBNet
|
87 |
+
num_in_ch: 3
|
88 |
+
num_out_ch: 3
|
89 |
+
num_feat: 64
|
90 |
+
num_block: 23
|
91 |
+
num_grow_ch: 32
|
92 |
+
|
93 |
+
network_d:
|
94 |
+
type: UNetDiscriminatorSN
|
95 |
+
num_in_ch: 3
|
96 |
+
num_feat: 64
|
97 |
+
skip_connection: True
|
98 |
+
|
99 |
+
# path
|
100 |
+
path:
|
101 |
+
# use the pre-trained Real-ESRNet model
|
102 |
+
pretrain_network_g: ./ckpts/Real-ESRGAN/RealESRGAN_x4plus.pth
|
103 |
+
param_key_g: params_ema
|
104 |
+
strict_load_g: true
|
105 |
+
pretrain_network_d: ./ckpts/Real-ESRGAN/RealESRGAN_x4plus_netD.pth
|
106 |
+
param_key_d: params
|
107 |
+
strict_load_d: true
|
108 |
+
resume_state: ~
|
109 |
+
|
110 |
+
# training settings
|
111 |
+
train:
|
112 |
+
ema_decay: 0.999
|
113 |
+
optim_g:
|
114 |
+
type: Adam
|
115 |
+
lr: !!float 1e-4
|
116 |
+
weight_decay: 0
|
117 |
+
betas: [0.9, 0.99]
|
118 |
+
optim_d:
|
119 |
+
type: Adam
|
120 |
+
lr: !!float 1e-4
|
121 |
+
weight_decay: 0
|
122 |
+
betas: [0.9, 0.99]
|
123 |
+
|
124 |
+
scheduler:
|
125 |
+
type: MultiStepLR
|
126 |
+
milestones: [1]
|
127 |
+
gamma: 0.5
|
128 |
+
|
129 |
+
total_iter: 20000
|
130 |
+
warmup_iter: -1 # no warm up
|
131 |
+
|
132 |
+
# losses
|
133 |
+
pixel_opt:
|
134 |
+
type: L1Loss
|
135 |
+
loss_weight: 1.0
|
136 |
+
reduction: mean
|
137 |
+
# perceptual loss (content and style losses)
|
138 |
+
perceptual_opt:
|
139 |
+
type: PerceptualLoss
|
140 |
+
layer_weights:
|
141 |
+
# before relu
|
142 |
+
'conv1_2': 0.1
|
143 |
+
'conv2_2': 0.1
|
144 |
+
'conv3_4': 1
|
145 |
+
'conv4_4': 1
|
146 |
+
'conv5_4': 1
|
147 |
+
vgg_type: vgg19
|
148 |
+
use_input_norm: true
|
149 |
+
perceptual_weight: !!float 1.0
|
150 |
+
style_weight: 0
|
151 |
+
range_norm: false
|
152 |
+
criterion: l1
|
153 |
+
# gan loss
|
154 |
+
gan_opt:
|
155 |
+
type: GANLoss
|
156 |
+
gan_type: vanilla
|
157 |
+
real_label_val: 1.0
|
158 |
+
fake_label_val: 0.0
|
159 |
+
loss_weight: !!float 1e-1
|
160 |
+
|
161 |
+
net_d_iters: 1
|
162 |
+
net_d_init_iters: 0
|
163 |
+
|
164 |
+
# Uncomment these for validation
|
165 |
+
# validation settings
|
166 |
+
# val:
|
167 |
+
# val_freq: !!float 5e3
|
168 |
+
# save_img: True
|
169 |
+
|
170 |
+
# metrics:
|
171 |
+
# psnr: # metric name
|
172 |
+
# type: calculate_psnr
|
173 |
+
# crop_border: 4
|
174 |
+
# test_y_channel: false
|
175 |
+
|
176 |
+
# logging settings
|
177 |
+
logger:
|
178 |
+
print_freq: 100
|
179 |
+
save_checkpoint_freq: !!float 5e3
|
180 |
+
use_tb_logger: true
|
181 |
+
wandb:
|
182 |
+
project: ~
|
183 |
+
resume_id: ~
|
184 |
+
|
185 |
+
# dist training settings
|
186 |
+
dist_params:
|
187 |
+
backend: nccl
|
188 |
+
port: 29500
|
configs/model_ckpts.yaml
ADDED
@@ -0,0 +1,22 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
- model_id: "danhtran2mind/Real-ESRGAN-Anime-finetuning"
|
2 |
+
local_dir: "ckpts/Real-ESRGAN-Anime-finetuning"
|
3 |
+
filename: "net_g_latest.pth"
|
4 |
+
for_inference: true
|
5 |
+
base_model: false
|
6 |
+
platform: "HuggingFace"
|
7 |
+
|
8 |
+
- model_id: "xinntao/Real-ESRGAN-x4plus-netD"
|
9 |
+
url: "https://github.com/xinntao/Real-ESRGAN/releases/download/v0.2.2.3/RealESRGAN_x4plus_netD.pth"
|
10 |
+
local_dir: "ckpts/Real-ESRGAN"
|
11 |
+
filename: "RealESRGAN_x4plus_netD.pth"
|
12 |
+
for_inference: false
|
13 |
+
base_model: true
|
14 |
+
platform: "GitHub"
|
15 |
+
|
16 |
+
- model_id: "xinntao/Real-ESRGAN-x4plus"
|
17 |
+
url: "https://github.com/xinntao/Real-ESRGAN/releases/download/v0.1.0/RealESRGAN_x4plus.pth"
|
18 |
+
local_dir: "ckpts/Real-ESRGAN"
|
19 |
+
filename: "RealESRGAN_x4plus.pth"
|
20 |
+
for_inference: true
|
21 |
+
base_model: true
|
22 |
+
platform: "GitHub"
|
data/.gitignore
ADDED
@@ -0,0 +1,2 @@
|
|
|
|
|
|
|
1 |
+
*
|
2 |
+
!.gitignore
|
docs/inference/inference_doc.md
ADDED
@@ -0,0 +1,116 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
# Inference Documentation
|
2 |
+
|
3 |
+
This document provides instructions for using the Real-ESRGAN inference script to perform super-resolution on anime images. The script uses a pre-trained Real-ESRGAN model to upscale images, with configurable input and output options.
|
4 |
+
|
5 |
+
## Prerequisites
|
6 |
+
|
7 |
+
- **Python Libraries**: Ensure the following Python packages are installed:
|
8 |
+
- `argparse`
|
9 |
+
- `PIL` (Pillow)
|
10 |
+
- `numpy`
|
11 |
+
- `torch`
|
12 |
+
- `opencv-python` (cv2)
|
13 |
+
- `pyyaml`
|
14 |
+
- `huggingface_hub`
|
15 |
+
- **Model Configuration**: A YAML file specifying model details (model ID, local directory, and filename).
|
16 |
+
- **Input Image**: A valid image file (e.g., PNG, JPEG) in RGB format.
|
17 |
+
- **Hardware**: CUDA-compatible GPU (optional, for faster processing) or CPU.
|
18 |
+
|
19 |
+
## Script Overview
|
20 |
+
|
21 |
+
The script (`inference.py`) performs super-resolution on an input image using the Real-ESRGAN model. It supports:
|
22 |
+
- Downloading model weights from Hugging Face if not available locally.
|
23 |
+
- Upscaling images using an inner scale (model-specific) and an optional outer scale (post-processing resizing).
|
24 |
+
- Saving the upscaled image to a specified output path or a default location.
|
25 |
+
|
26 |
+
## Command-Line Arguments
|
27 |
+
|
28 |
+
The script accepts the following command-line arguments:
|
29 |
+
|
30 |
+
| Argument | Type | Required | Default | Description |
|
31 |
+
|-------------------------|------|----------|---------|-----------------------------------------------------------------------------|
|
32 |
+
| `--input_path` | str | Yes | None | Path to the input image file (e.g., `image.png`). |
|
33 |
+
| `--output_path` | str | No | None | Path to save the upscaled image. If not provided, the image is returned but not saved automatically. |
|
34 |
+
| `--model_id` | str | Yes | None | Model ID for the Real-ESRGAN model (e.g., `danhtran2mind/Real-ESRGAN-Anime-finetuning`). |
|
35 |
+
| `--models_config_path` | str | Yes | None | Path to the YAML configuration file containing model details. |
|
36 |
+
| `--batch_size` | int | No | 1 | Batch Ascertain batch size (not used in this implementation). |
|
37 |
+
| `--outer_scale` | int | Yes | None | Desired final scale factor for super-resolution (e.g., 4, 8). |
|
38 |
+
| `--inner_scale` | int | No | 4 | Internal scale factor used by the model (typically 4). |
|
39 |
+
|
40 |
+
## Usage
|
41 |
+
|
42 |
+
1. **Prepare the Models Configuration File**:
|
43 |
+
Create a YAML file (e.g., `models_config.yaml`) with the following structure:
|
44 |
+
|
45 |
+
```yaml
|
46 |
+
- model_id: "danhtran2mind/Real-ESRGAN-Anime-finetuning"
|
47 |
+
local_dir: "./weights"
|
48 |
+
filename: "model.pth"
|
49 |
+
```
|
50 |
+
|
51 |
+
This file specifies the model ID, local directory for weights, and the filename of the model checkpoint.
|
52 |
+
|
53 |
+
2. **Run the Script**:
|
54 |
+
Use the following command to run the inference:
|
55 |
+
|
56 |
+
```bash
|
57 |
+
python inference.py \
|
58 |
+
--input_path path/to/input/image.png \
|
59 |
+
--output_path path/to/output/image.png \
|
60 |
+
--model_id danhtran2mind/Real-ESRGAN-Anime-finetuning \
|
61 |
+
--models_config_path path/to/models_config.yaml \
|
62 |
+
--outer_scale 4
|
63 |
+
```
|
64 |
+
|
65 |
+
Example:
|
66 |
+
|
67 |
+
```bash
|
68 |
+
python inference.py \
|
69 |
+
--input_path input.png \
|
70 |
+
--output_path output.png \
|
71 |
+
--model_id danhtran2mind/Real-ESRGAN-Anime-finetuning \
|
72 |
+
--models_config_path models_config.yaml \
|
73 |
+
--outer_scale 8
|
74 |
+
```
|
75 |
+
|
76 |
+
3. **Output**:
|
77 |
+
- The script processes the input image and applies super-resolution.
|
78 |
+
- If `--output_path` is provided, the upscaled image is saved to the specified path.
|
79 |
+
- If `--outer_scale` differs from `--inner_scale`, the output image is resized using OpenCV's `INTER_CUBIC` (for upscaling) or `INTER_AREA` (for downscaling) interpolation.
|
80 |
+
|
81 |
+
## How It Works
|
82 |
+
|
83 |
+
1. **Model Loading**:
|
84 |
+
- The script reads the `models_config_path` YAML file to locate the model configuration.
|
85 |
+
- If the model weights are not found locally, they are downloaded from the Hugging Face Hub using the specified `model_id` and `filename`.
|
86 |
+
- The Real-ESRGAN model is initialized with the specified `inner_scale` and loaded with the weights.
|
87 |
+
|
88 |
+
2. **Image Processing**:
|
89 |
+
- The input image is opened and converted to RGB format using Pillow.
|
90 |
+
- The Real-ESRGAN model upscales the image by the `inner_scale` factor.
|
91 |
+
- If `outer_scale` differs from `inner_scale`, the image is further resized to achieve the desired scale using OpenCV.
|
92 |
+
|
93 |
+
3. **Output Handling**:
|
94 |
+
- The upscaled image is saved to `output_path` if provided.
|
95 |
+
- The processed image is returned as a Pillow Image object.
|
96 |
+
|
97 |
+
## Notes
|
98 |
+
|
99 |
+
- **Device Selection**: The script automatically uses CUDA if available; otherwise, it falls back to CPU.
|
100 |
+
- **Model Weights**: Ensure the `local_dir` specified in the YAML file exists or is writable for downloading weights.
|
101 |
+
- **Outer vs. Inner Scale**:
|
102 |
+
- `inner_scale` is the scale factor used by the Real-ESRGAN model (typically fixed at 4).
|
103 |
+
- `outer_scale` is the final desired scale, achieved through additional resizing if necessary.
|
104 |
+
- **Batch Size**: The `--batch_size` argument is included but not used in this implementation, as the script processes one image at a time.
|
105 |
+
|
106 |
+
## Example Models Configuration File
|
107 |
+
|
108 |
+
Here is an example `models_config.yaml`:
|
109 |
+
|
110 |
+
<xaiArtifact artifact_id="0b60a214-8c91-48ed-ad50-fae3467a0508" artifact_version_id="35ae4a0a-da96-44d0-b8ed-7c1d62b59527" title="models_config.yaml" contentType="text/yaml">
|
111 |
+
|
112 |
+
```yaml
|
113 |
+
- model_id: "danhtran2mind/Real-ESRGAN-Anime-finetuning"
|
114 |
+
local_dir: "./weights"
|
115 |
+
filename: "model.pth"
|
116 |
+
```
|