danhtran2mind commited on
Commit
c416731
·
verified ·
1 Parent(s): aa6de37

Update apps/gradio_app.py

Browse files
Files changed (1) hide show
  1. apps/gradio_app.py +96 -96
apps/gradio_app.py CHANGED
@@ -1,97 +1,97 @@
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
- def run_setup_script():
13
- setup_script = os.path.join(os.path.dirname(__file__), "gradio_app", "setup_scripts.py")
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 and JavaScript
23
- custom_css = open(os.path.join(os.path.dirname(__file__), "gradio_app", "static", "styles.css")).read()
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)
29
- gr.Markdown(CONTENT_IN_1)
30
- gr.HTML(CONTENT_IN_2)
31
- with gr.Row():
32
- with gr.Column(scale=2):
33
- input_image = gr.Image(
34
- type="filepath",
35
- label="Input Image",
36
- elem_classes="input-image"
37
- )
38
- model_id = gr.Textbox(
39
- label="Model ID",
40
- value="danhtran2mind/Real-ESRGAN-Anime-finetuning"
41
- )
42
- outer_scale = gr.Slider(
43
- minimum=1,
44
- maximum=8,
45
- step=1,
46
- value=2,
47
- label="Outer Scale",
48
- elem_id="outer-scale-slider"
49
- )
50
- warning_text = gr.HTML(elem_id="warning-text")
51
- gr.Markdown(
52
- "**Note:** For optimal output quality, set `Outer Scale` to a value between 1 and 4. "
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
- fn=select_example,
81
- outputs=[input_image, outer_scale, output_image, output_text]
82
- )
83
-
84
- submit_button.click(
85
- fn=run_inference,
86
- inputs=[input_image, model_id, outer_scale],
87
- outputs=[output_image, output_text]
88
- )
89
- gr.HTML(CONTENT_OUT_1)
90
- gr.Markdown(CONTENT_OUT_2)
91
-
92
- return demo
93
-
94
- if __name__ == "__main__":
95
- run_setup_script()
96
- demo = create_gui()
97
  demo.launch(debug=True)
 
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
+ def run_setup_script():
13
+ setup_script = os.path.join(os.path.dirname(__file__), "gradio_app", "setup_scripts.py")
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 and JavaScript
23
+ custom_css = open(os.path.join(os.path.dirname(__file__), "gradio_app", "static", "styles.css")).read()
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)
29
+ gr.Markdown(CONTENT_IN_1)
30
+ gr.HTML(CONTENT_IN_2)
31
+ with gr.Row():
32
+ with gr.Column(scale=2):
33
+ input_image = gr.Image(
34
+ type="filepath",
35
+ label="Input Image",
36
+ elem_classes="input-image"
37
+ )
38
+ model_id = gr.Textbox(
39
+ label="Model ID",
40
+ value="danhtran2mind/Real-ESRGAN-Anime-finetuning"
41
+ )
42
+ outer_scale = gr.Slider(
43
+ minimum=1,
44
+ maximum=8,
45
+ step=1,
46
+ value=2,
47
+ label="Outer Scale",
48
+ elem_id="outer-scale-slider"
49
+ )
50
+ warning_text = gr.HTML(elem_id="warning-text")
51
+ gr.Markdown(
52
+ "**Note:** For optimal output quality, set `Outer Scale` to a value between 1 and 4. "
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
+ # fn=select_example,
81
+ # outputs=[input_image, outer_scale, output_image, output_text]
82
+ # )
83
+
84
+ submit_button.click(
85
+ fn=run_inference,
86
+ inputs=[input_image, model_id, outer_scale],
87
+ outputs=[output_image, output_text]
88
+ )
89
+ gr.HTML(CONTENT_OUT_1)
90
+ gr.Markdown(CONTENT_OUT_2)
91
+
92
+ return demo
93
+
94
+ if __name__ == "__main__":
95
+ run_setup_script()
96
+ demo = create_gui()
97
  demo.launch(debug=True)