Update apps/gradio_app.py
Browse files- apps/gradio_app.py +20 -14
apps/gradio_app.py
CHANGED
@@ -9,20 +9,25 @@ from gradio_app.project_info import (
|
|
9 |
from gradio_app.inference import run_inference
|
10 |
from gradio_app.examples import load_examples, select_example
|
11 |
|
|
|
12 |
def run_setup_script():
|
13 |
-
setup_script = os.path.join(os.path.dirname(__file__),
|
|
|
14 |
try:
|
15 |
result = subprocess.run(["python", setup_script], capture_output=True, text=True, check=True)
|
16 |
return result.stdout
|
17 |
except subprocess.CalledProcessError as e:
|
18 |
print(f"Setup script failed with error: {e.stderr}")
|
19 |
return f"Setup script failed: {e.stderr}"
|
20 |
-
|
21 |
def create_gui():
|
22 |
-
# Load CSS
|
23 |
-
custom_css = open(
|
24 |
-
outer_scale_warning = open(os.path.join(os.path.dirname(__file__), "gradio_app", "static", "outer_scale_warning.js")).read()
|
25 |
|
|
|
|
|
|
|
|
|
26 |
with gr.Blocks(css=custom_css) as demo:
|
27 |
gr.Markdown("# Anime Super Resolution 🖼️")
|
28 |
gr.Markdown(CONTENT_DESCRIPTION)
|
@@ -39,6 +44,7 @@ def create_gui():
|
|
39 |
label="Model ID",
|
40 |
value="danhtran2mind/Real-ESRGAN-Anime-finetuning"
|
41 |
)
|
|
|
42 |
outer_scale = gr.Slider(
|
43 |
minimum=1,
|
44 |
maximum=8,
|
@@ -53,35 +59,35 @@ def create_gui():
|
|
53 |
"**Values greater than 4 are not recommended**. "
|
54 |
"Please ensure `Outer Scale` is greater than or equal to `Inner Scale` (default: 4)."
|
55 |
)
|
|
|
56 |
examples_data = load_examples()
|
57 |
-
if not examples_data:
|
58 |
-
gr.Warning("No examples found. Check the 'apps/assets/examples' directory.")
|
59 |
submit_button = gr.Button("Run Inference")
|
60 |
-
|
61 |
with gr.Column(scale=3):
|
62 |
output_image = gr.Image(
|
63 |
label="Output Image",
|
64 |
elem_classes="output-image"
|
65 |
)
|
66 |
output_text = gr.Textbox(label="Status")
|
67 |
-
|
|
|
68 |
outer_scale.change(
|
69 |
fn=lambda x: x,
|
70 |
inputs=outer_scale,
|
71 |
outputs=outer_scale,
|
72 |
js=outer_scale_warning
|
73 |
)
|
74 |
-
|
75 |
gr.Examples(
|
76 |
examples=[[input_img, output_img, outer_scale] for input_img, output_img, outer_scale in examples_data],
|
77 |
-
inputs=[input_image, outer_scale],
|
78 |
label="Example Inputs",
|
79 |
examples_per_page=4,
|
80 |
cache_examples=False,
|
81 |
fn=select_example,
|
82 |
outputs=[input_image, outer_scale, output_image, output_text]
|
83 |
)
|
84 |
-
|
85 |
submit_button.click(
|
86 |
fn=run_inference,
|
87 |
inputs=[input_image, model_id, outer_scale],
|
@@ -90,8 +96,8 @@ def create_gui():
|
|
90 |
gr.HTML(CONTENT_OUT_1)
|
91 |
gr.HTML(CONTENT_OUT_2)
|
92 |
|
93 |
-
|
94 |
-
|
95 |
if __name__ == "__main__":
|
96 |
run_setup_script()
|
97 |
demo = create_gui()
|
|
|
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)
|
|
|
44 |
label="Model ID",
|
45 |
value="danhtran2mind/Real-ESRGAN-Anime-finetuning"
|
46 |
)
|
47 |
+
|
48 |
outer_scale = gr.Slider(
|
49 |
minimum=1,
|
50 |
maximum=8,
|
|
|
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 |
cache_examples=False,
|
87 |
fn=select_example,
|
88 |
outputs=[input_image, outer_scale, output_image, output_text]
|
89 |
)
|
90 |
+
|
91 |
submit_button.click(
|
92 |
fn=run_inference,
|
93 |
inputs=[input_image, model_id, outer_scale],
|
|
|
96 |
gr.HTML(CONTENT_OUT_1)
|
97 |
gr.HTML(CONTENT_OUT_2)
|
98 |
|
99 |
+
return demo
|
100 |
+
|
101 |
if __name__ == "__main__":
|
102 |
run_setup_script()
|
103 |
demo = create_gui()
|