Skip to content

Commit 6bdcfeb

Browse files
committed
Improved readability of the code 2
1 parent 74c873e commit 6bdcfeb

File tree

1 file changed

+64
-18
lines changed

1 file changed

+64
-18
lines changed

sdcpp_webui.py

Lines changed: 64 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -7,10 +7,25 @@
77

88
import gradio as gr
99

10-
from modules.ui_txt2img import txt2img_block, pprompt_txt2img, nprompt_txt2img, width_txt2img, height_txt2img, steps_txt2img, sampling_txt2img, cfg_txt2img, seed_txt2img
11-
from modules.ui_img2img import img2img_block, pprompt_img2img, nprompt_img2img, width_img2img, height_img2img, steps_img2img, sampling_img2img, cfg_img2img, seed_img2img, img_inp
12-
from modules.ui_any2video import any2video_block, pprompt_any2video, nprompt_any2video, width_any2video, height_any2video, steps_any2video, sampling_any2video, cfg_any2video, seed_any2video
13-
from modules.ui_gallery import gallery_block, cpy_2_txt2img_btn, cpy_2_img2img_btn, cpy_2_any2video_btn, pprompt_info, nprompt_info, width_info, height_info, steps_info, sampler_info, cfg_info, seed_info, path_info
10+
from modules.ui_txt2img import (
11+
txt2img_block, pprompt_txt2img, nprompt_txt2img, width_txt2img,
12+
height_txt2img, steps_txt2img, sampling_txt2img, cfg_txt2img, seed_txt2img
13+
)
14+
from modules.ui_img2img import (
15+
img2img_block, pprompt_img2img, nprompt_img2img, width_img2img,
16+
height_img2img, steps_img2img, sampling_img2img, cfg_img2img, seed_img2img,
17+
img_inp
18+
)
19+
from modules.ui_any2video import (
20+
any2video_block, pprompt_any2video, nprompt_any2video, width_any2video,
21+
height_any2video, steps_any2video, sampling_any2video, cfg_any2video,
22+
seed_any2video
23+
)
24+
from modules.ui_gallery import (
25+
gallery_block, cpy_2_txt2img_btn, cpy_2_img2img_btn, cpy_2_any2video_btn,
26+
pprompt_info, nprompt_info, width_info, height_info, steps_info,
27+
sampler_info, cfg_info, seed_info, path_info
28+
)
1429
from modules.ui_convert import convert_block
1530
from modules.ui_options import options_block
1631

@@ -40,15 +55,34 @@ def main():
4055
sdcpp_launch(args.listen, args.autostart, args.darkmode)
4156

4257

43-
def cpy_2_txt2img(pprompt_info, nprompt_info, width_info, height_info, steps_info, sampler_info, cfg_info, seed_info):
44-
return gr.Tabs(selected="txt2img"), pprompt_info, nprompt_info, width_info, height_info, steps_info, sampler_info, cfg_info, seed_info
58+
def cpy_2_txt2img(
59+
pprompt_info, nprompt_info, width_info, height_info, steps_info,
60+
sampler_info, cfg_info, seed_info
61+
):
62+
return (
63+
gr.Tabs(selected="txt2img"), pprompt_info, nprompt_info, width_info,
64+
height_info, steps_info, sampler_info, cfg_info, seed_info
65+
)
4566

4667

47-
def cpy_2_img2img(pprompt_info, nprompt_info, width_info, height_info, steps_info, sampler_info, cfg_info, seed_info, path_info):
48-
return gr.Tabs(selected="img2img"), pprompt_info, nprompt_info, width_info, height_info, steps_info, sampler_info, cfg_info, seed_info, path_info
68+
def cpy_2_img2img(
69+
pprompt_info, nprompt_info, width_info, height_info, steps_info,
70+
sampler_info, cfg_info, seed_info, path_info
71+
):
72+
return (
73+
gr.Tabs(selected="img2img"), pprompt_info, nprompt_info, width_info,
74+
height_info, steps_info, sampler_info, cfg_info, seed_info, path_info
75+
)
76+
4977

50-
def cpy_2_any2video(pprompt_info, nprompt_info, width_info, height_info, steps_info, sampler_info, cfg_info, seed_info, path_info):
51-
return gr.Tabs(selected="any2video"), pprompt_info, nprompt_info, width_info, height_info, steps_info, sampler_info, cfg_info, seed_info, path_info
78+
def cpy_2_any2video(
79+
pprompt_info, nprompt_info, width_info, height_info, steps_info,
80+
sampler_info, cfg_info, seed_info, path_info
81+
):
82+
return (
83+
gr.Tabs(selected="any2video"), pprompt_info, nprompt_info, width_info,
84+
height_info, steps_info, sampler_info, cfg_info, seed_info, path_info
85+
)
5286

5387

5488
def sdcpp_launch(
@@ -74,8 +108,10 @@ def sdcpp_launch(
74108
}
75109
""" if darkmode else None
76110

77-
78-
with gr.Blocks(css="footer {visibility: hidden}", title="sd.cpp-webui", theme="default", js=dark_js) as sdcpp:
111+
with gr.Blocks(
112+
css="footer {visibility: hidden}", title="sd.cpp-webui",
113+
theme="default", js=dark_js
114+
) as sdcpp:
79115
with gr.Tabs() as tabs:
80116
with gr.TabItem("txt2img", id="txt2img"):
81117
txt2img_block.render()
@@ -93,18 +129,28 @@ def sdcpp_launch(
93129
# Set up the button click event
94130
cpy_2_txt2img_btn.click(
95131
cpy_2_txt2img,
96-
inputs=[pprompt_info, nprompt_info, width_info, height_info, steps_info, sampler_info, cfg_info, seed_info],
97-
outputs=[tabs, pprompt_txt2img, nprompt_txt2img, width_txt2img, height_txt2img, steps_txt2img, sampling_txt2img, cfg_txt2img, seed_txt2img]
132+
inputs=[pprompt_info, nprompt_info, width_info, height_info,
133+
steps_info, sampler_info, cfg_info, seed_info],
134+
outputs=[tabs, pprompt_txt2img, nprompt_txt2img, width_txt2img,
135+
height_txt2img, steps_txt2img, sampling_txt2img,
136+
cfg_txt2img, seed_txt2img]
98137
)
99138
cpy_2_img2img_btn.click(
100139
cpy_2_img2img,
101-
inputs=[pprompt_info, nprompt_info, width_info, height_info, steps_info, sampler_info, cfg_info, seed_info, path_info],
102-
outputs=[tabs, pprompt_img2img, nprompt_img2img, width_img2img, height_img2img, steps_img2img, sampling_img2img, cfg_img2img, seed_img2img, img_inp]
140+
inputs=[pprompt_info, nprompt_info, width_info, height_info,
141+
steps_info, sampler_info, cfg_info, seed_info, path_info],
142+
outputs=[tabs, pprompt_img2img, nprompt_img2img, width_img2img,
143+
height_img2img, steps_img2img, sampling_img2img,
144+
cfg_img2img, seed_img2img, img_inp]
103145
)
104146
cpy_2_any2video_btn.click(
105147
cpy_2_any2video,
106-
inputs=[pprompt_info, nprompt_info, width_info, height_info, steps_info, sampler_info, cfg_info, seed_info, path_info],
107-
outputs=[tabs, pprompt_any2video, nprompt_any2video, width_any2video, height_any2video, steps_any2video, sampling_any2video, cfg_any2video, seed_any2video, img_inp]
148+
inputs=[pprompt_info, nprompt_info, width_info, height_info,
149+
steps_info, sampler_info, cfg_info, seed_info, path_info],
150+
outputs=[tabs, pprompt_any2video, nprompt_any2video,
151+
width_any2video, height_any2video, steps_any2video,
152+
sampling_any2video, cfg_any2video, seed_any2video,
153+
img_inp]
108154
)
109155

110156
# Pass the arguments to sdcpp.launch with argument unpacking

0 commit comments

Comments
 (0)