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
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
import random
|
2 |
+
import gradio as gr
|
3 |
+
|
4 |
+
from modules import sd_models
|
5 |
+
from modules import sd_vae
|
6 |
+
from modules import ui_components
|
7 |
+
from modules import shared
|
8 |
+
from modules import extras
|
9 |
+
from modules import images
|
10 |
+
|
11 |
+
from sd_bmab import constants
|
12 |
+
from sd_bmab import util
|
13 |
+
from sd_bmab import detectors
|
14 |
+
from sd_bmab import parameters
|
15 |
+
from sd_bmab.base import context
|
16 |
+
from sd_bmab.base import filter
|
17 |
+
from sd_bmab.base import installer
|
18 |
+
from sd_bmab import pipeline
|
19 |
+
from sd_bmab import masking
|
20 |
+
from sd_bmab.util import debug_print
|
21 |
+
|
22 |
+
|
23 |
+
bmab_version = 'v23.12.05.0'
|
24 |
+
|
25 |
+
final_images = []
|
26 |
+
last_process = None
|
27 |
+
bmab_script = None
|
28 |
+
gallery_select_index = 0
|
29 |
+
|
30 |
+
|
31 |
+
def create_ui(bscript, is_img2img):
|
32 |
+
class ListOv(list):
|
33 |
+
def __iadd__(self, x):
|
34 |
+
self.append(x)
|
35 |
+
return self
|
36 |
+
|
37 |
+
elem = ListOv()
|
38 |
+
with gr.Group():
|
39 |
+
with gr.Row():
|
40 |
+
with gr.Column():
|
41 |
+
elem += gr.Checkbox(label=f'Enable BMAB', value=False)
|
42 |
+
with gr.Column():
|
43 |
+
btn_stop = ui_components.ToolButton('⏹️', visible=True, interactive=True, tooltip='stop generation', elem_id='bmab_stop_generation')
|
44 |
+
with gr.Accordion(f'BMAB Preprocessor', open=False):
|
45 |
+
with gr.Row():
|
46 |
+
with gr.Tab('Context', id='bmab_context', elem_id='bmab_context_tabs'):
|
47 |
+
with gr.Tab('Generic'):
|
48 |
+
with gr.Row():
|
49 |
+
with gr.Column():
|
50 |
+
with gr.Row():
|
51 |
+
checkpoints = [constants.checkpoint_default]
|
52 |
+
checkpoints.extend([str(x) for x in sd_models.checkpoints_list.keys()])
|
53 |
+
checkpoint_models = gr.Dropdown(label='CheckPoint', visible=True, value=checkpoints[0], choices=checkpoints)
|
54 |
+
elem += checkpoint_models
|
55 |
+
refresh_checkpoint_models = ui_components.ToolButton(value='🔄', visible=True, interactive=True)
|
56 |
+
with gr.Column():
|
57 |
+
with gr.Row():
|
58 |
+
vaes = [constants.vae_default]
|
59 |
+
vaes.extend([str(x) for x in sd_vae.vae_dict.keys()])
|
60 |
+
vaes_models = gr.Dropdown(label='SD VAE', visible=True, value=vaes[0], choices=vaes)
|
61 |
+
elem += vaes_models
|
62 |
+
refresh_vae_models = ui_components.ToolButton(value='🔄', visible=True, interactive=True)
|
63 |
+
with gr.Row():
|
64 |
+
gr.Markdown(constants.checkpoint_description)
|
65 |
+
with gr.Row():
|
66 |
+
elem += gr.Slider(minimum=0, maximum=1.5, value=1, step=0.001, label='txt2img noise multiplier for hires.fix (EXPERIMENTAL)', elem_id='bmab_txt2img_noise_multiplier')
|
67 |
+
with gr.Row():
|
68 |
+
elem += gr.Slider(minimum=0, maximum=1, value=0, step=0.01, label='txt2img extra noise multiplier for hires.fix (EXPERIMENTAL)', elem_id='bmab_txt2img_extra_noise_multiplier')
|
69 |
+
with gr.Row():
|
70 |
+
with gr.Column():
|
71 |
+
with gr.Row():
|
72 |
+
dd_hiresfix_filter1 = gr.Dropdown(label='Hires.fix filter before upscale', visible=True, value=filter.filters[0], choices=filter.filters)
|
73 |
+
elem += dd_hiresfix_filter1
|
74 |
+
with gr.Column():
|
75 |
+
with gr.Row():
|
76 |
+
dd_hiresfix_filter2 = gr.Dropdown(label='Hires.fix filter after upscale', visible=True, value=filter.filters[0], choices=filter.filters)
|
77 |
+
elem += dd_hiresfix_filter2
|
78 |
+
with gr.Tab('Kohya Hires.fix'):
|
79 |
+
with gr.Row():
|
80 |
+
with gr.Column():
|
81 |
+
elem += gr.Checkbox(label='Enable Kohya hires.fix', value=False)
|
82 |
+
with gr.Row():
|
83 |
+
gr.HTML(constants.kohya_hiresfix_description)
|
84 |
+
with gr.Row():
|
85 |
+
elem += gr.Slider(minimum=0, maximum=0.5, step=0.01, label="Stop at, first", value=0.15)
|
86 |
+
elem += gr.Slider(minimum=1, maximum=10, step=1, label="Depth, first", value=3)
|
87 |
+
with gr.Row():
|
88 |
+
elem += gr.Slider(minimum=0, maximum=0.5, step=0.01, label="Stop at, second", value=0.4)
|
89 |
+
elem += gr.Slider(minimum=1, maximum=10, step=1, label="Depth, second", value=4)
|
90 |
+
with gr.Row():
|
91 |
+
elem += gr.Dropdown(['bicubic', 'bilinear', 'nearest', 'nearest-exact'], label='Layer scaler', value='bicubic')
|
92 |
+
elem += gr.Slider(minimum=0.1, maximum=1.0, step=0.05, label="Downsampling scale", value=0.5)
|
93 |
+
elem += gr.Slider(minimum=1.0, maximum=4.0, step=0.1, label="Upsampling scale", value=2.0)
|
94 |
+
with gr.Row():
|
95 |
+
elem += gr.Checkbox(label="Smooth scaling", value=True)
|
96 |
+
elem += gr.Checkbox(label="Early upsampling", value=False)
|
97 |
+
elem += gr.Checkbox(label='Disable for additional passes', value=True)
|
98 |
+
with gr.Tab('Resample', id='bmab_resample', elem_id='bmab_resample_tabs'):
|
99 |
+
with gr.Row():
|
100 |
+
with gr.Column():
|
101 |
+
elem += gr.Checkbox(label='Enable self resample', value=False)
|
102 |
+
with gr.Column():
|
103 |
+
elem += gr.Checkbox(label='Save image before processing', value=False)
|
104 |
+
with gr.Row():
|
105 |
+
elem += gr.Checkbox(label='Enable resample before hires.fix', value=False)
|
106 |
+
with gr.Row():
|
107 |
+
with gr.Column():
|
108 |
+
with gr.Row():
|
109 |
+
checkpoints = [constants.checkpoint_default]
|
110 |
+
checkpoints.extend([str(x) for x in sd_models.checkpoints_list.keys()])
|
111 |
+
resample_models = gr.Dropdown(label='CheckPoint', visible=True, value=checkpoints[0], choices=checkpoints)
|
112 |
+
elem += resample_models
|
113 |
+
refresh_resample_models = ui_components.ToolButton(value='🔄', visible=True, interactive=True)
|
114 |
+
with gr.Column():
|
115 |
+
with gr.Row():
|
116 |
+
vaes = [constants.vae_default]
|
117 |
+
vaes.extend([str(x) for x in sd_vae.vae_dict.keys()])
|
118 |
+
resample_vaes = gr.Dropdown(label='SD VAE', visible=True, value=vaes[0], choices=vaes)
|
119 |
+
elem += resample_vaes
|
120 |
+
refresh_resample_vaes = ui_components.ToolButton(value='🔄', visible=True, interactive=True)
|
121 |
+
with gr.Row():
|
122 |
+
with gr.Column(min_width=100):
|
123 |
+
methods = ['txt2img-1pass', 'txt2img-2pass', 'img2img-1pass']
|
124 |
+
elem += gr.Dropdown(label='Resample method', visible=True, value=methods[0], choices=methods)
|
125 |
+
with gr.Column():
|
126 |
+
dd_resample_filter = gr.Dropdown(label='Resample filter', visible=True, value=filter.filters[0], choices=filter.filters)
|
127 |
+
elem += dd_resample_filter
|
128 |
+
with gr.Row():
|
129 |
+
elem += gr.Textbox(placeholder='prompt. if empty, use main prompt', lines=3, visible=True, value='', label='Resample prompt')
|
130 |
+
with gr.Row():
|
131 |
+
elem += gr.Textbox(placeholder='negative prompt. if empty, use main negative prompt', lines=3, visible=True, value='', label='Resample negative prompt')
|
132 |
+
with gr.Row():
|
133 |
+
with gr.Column(min_width=100):
|
134 |
+
asamplers = [constants.sampler_default]
|
135 |
+
asamplers.extend([x.name for x in shared.list_samplers()])
|
136 |
+
elem += gr.Dropdown(label='Sampling method', visible=True, value=asamplers[0], choices=asamplers)
|
137 |
+
with gr.Column(min_width=100):
|
138 |
+
upscalers = [constants.fast_upscaler]
|
139 |
+
upscalers.extend([x.name for x in shared.sd_upscalers])
|
140 |
+
elem += gr.Dropdown(label='Upscaler', visible=True, value=upscalers[0], choices=upscalers)
|
141 |
+
with gr.Row():
|
142 |
+
with gr.Column(min_width=100):
|
143 |
+
elem += gr.Slider(minimum=1, maximum=150, value=20, step=1, label='Resample Sampling Steps', elem_id='bmab_resample_steps')
|
144 |
+
elem += gr.Slider(minimum=1, maximum=30, value=7, step=0.5, label='Resample CFG Scale', elem_id='bmab_resample_cfg_scale')
|
145 |
+
elem += gr.Slider(minimum=0, maximum=1, value=0.75, step=0.01, label='Resample Denoising Strength', elem_id='bmab_resample_denoising')
|
146 |
+
elem += gr.Slider(minimum=0.0, maximum=2, value=0.5, step=0.05, label='Resample strength', elem_id='bmab_resample_cn_strength')
|
147 |
+
elem += gr.Slider(minimum=0.0, maximum=1.0, value=0.1, step=0.01, label='Resample begin', elem_id='bmab_resample_cn_begin')
|
148 |
+
elem += gr.Slider(minimum=0.0, maximum=1.0, value=0.9, step=0.01, label='Resample end', elem_id='bmab_resample_cn_end')
|
149 |
+
with gr.Tab('Pretraining', id='bmab_pretraining', elem_id='bmab_pretraining_tabs'):
|
150 |
+
with gr.Row():
|
151 |
+
elem += gr.Checkbox(label='Enable pretraining detailer', value=False)
|
152 |
+
with gr.Row():
|
153 |
+
elem += gr.Checkbox(label='Enable pretraining before hires.fix', value=False)
|
154 |
+
with gr.Column(min_width=100):
|
155 |
+
with gr.Row():
|
156 |
+
models = ['Select Model']
|
157 |
+
models.extend(util.list_pretraining_models())
|
158 |
+
pretraining_models = gr.Dropdown(label='Pretraining Model', visible=True, value=models[0], choices=models, elem_id='bmab_pretraining_models')
|
159 |
+
elem += pretraining_models
|
160 |
+
refresh_pretraining_models = ui_components.ToolButton(value='🔄', visible=True, interactive=True)
|
161 |
+
with gr.Row():
|
162 |
+
elem += gr.Textbox(placeholder='prompt. if empty, use main prompt', lines=3, visible=True, value='', label='Pretraining prompt')
|
163 |
+
with gr.Row():
|
164 |
+
elem += gr.Textbox(placeholder='negative prompt. if empty, use main negative prompt', lines=3, visible=True, value='', label='Pretraining negative prompt')
|
165 |
+
with gr.Row():
|
166 |
+
with gr.Column(min_width=100):
|
167 |
+
asamplers = [constants.sampler_default]
|
168 |
+
asamplers.extend([x.name for x in shared.list_samplers()])
|
169 |
+
elem += gr.Dropdown(label='Sampling method', visible=True, value=asamplers[0], choices=asamplers)
|
170 |
+
with gr.Row():
|
171 |
+
with gr.Column(min_width=100):
|
172 |
+
elem += gr.Slider(minimum=1, maximum=150, value=20, step=1, label='Pretraining sampling steps', elem_id='bmab_pretraining_steps')
|
173 |
+
elem += gr.Slider(minimum=1, maximum=30, value=7, step=0.5, label='Pretraining CFG scale', elem_id='bmab_pretraining_cfg_scale')
|
174 |
+
elem += gr.Slider(minimum=0, maximum=1, value=0.75, step=0.01, label='Pretraining denoising Strength', elem_id='bmab_pretraining_denoising')
|
175 |
+
elem += gr.Slider(minimum=0, maximum=128, value=4, step=1, label='Pretraining dilation', elem_id='bmab_pretraining_dilation')
|
176 |
+
elem += gr.Slider(minimum=0.1, maximum=1, value=0.35, step=0.01, label='Pretraining box threshold', elem_id='bmab_pretraining_box_threshold')
|
177 |
+
with gr.Tab('Edge', elem_id='bmab_edge_tabs'):
|
178 |
+
with gr.Row():
|
179 |
+
elem += gr.Checkbox(label='Enable edge enhancement', value=False)
|
180 |
+
with gr.Row():
|
181 |
+
elem += gr.Slider(minimum=1, maximum=255, value=50, step=1, label='Edge low threshold')
|
182 |
+
elem += gr.Slider(minimum=1, maximum=255, value=200, step=1, label='Edge high threshold')
|
183 |
+
with gr.Row():
|
184 |
+
elem += gr.Slider(minimum=0, maximum=1, value=0.5, step=0.05, label='Edge strength')
|
185 |
+
gr.Markdown('')
|
186 |
+
with gr.Tab('Resize', elem_id='bmab_preprocess_resize_tab'):
|
187 |
+
with gr.Row():
|
188 |
+
elem += gr.Checkbox(label='Enable resize (intermediate)', value=False)
|
189 |
+
with gr.Row():
|
190 |
+
elem += gr.Checkbox(label='Resized by person', value=True)
|
191 |
+
with gr.Row():
|
192 |
+
gr.HTML(constants.resize_description)
|
193 |
+
with gr.Row():
|
194 |
+
with gr.Column():
|
195 |
+
methods = ['stretching', 'inpaint', 'inpaint+lama', 'inpaint_only', 'inpaint_only+lama']
|
196 |
+
elem += gr.Dropdown(label='Method', visible=True, value=methods[0], choices=methods)
|
197 |
+
with gr.Column():
|
198 |
+
align = [x for x in util.alignment.keys()]
|
199 |
+
elem += gr.Dropdown(label='Alignment', visible=True, value=align[4], choices=align)
|
200 |
+
with gr.Row():
|
201 |
+
with gr.Column():
|
202 |
+
dd_resize_filter = gr.Dropdown(label='Resize filter', visible=True, value=filter.filters[0], choices=filter.filters)
|
203 |
+
elem += dd_resize_filter
|
204 |
+
with gr.Column():
|
205 |
+
gr.Markdown('')
|
206 |
+
with gr.Row():
|
207 |
+
elem += gr.Slider(minimum=0.10, maximum=0.95, value=0.85, step=0.01, label='Resize by person intermediate')
|
208 |
+
with gr.Row():
|
209 |
+
elem += gr.Slider(minimum=0, maximum=1, value=0.75, step=0.01, label='Denoising Strength for inpaint and inpaint+lama', elem_id='bmab_resize_intermediate_denoising')
|
210 |
+
with gr.Tab('Refiner', id='bmab_refiner', elem_id='bmab_refiner_tabs'):
|
211 |
+
with gr.Row():
|
212 |
+
elem += gr.Checkbox(label='Enable refiner', value=False)
|
213 |
+
with gr.Row():
|
214 |
+
with gr.Column():
|
215 |
+
with gr.Row():
|
216 |
+
checkpoints = [constants.checkpoint_default]
|
217 |
+
checkpoints.extend([str(x) for x in sd_models.checkpoints_list.keys()])
|
218 |
+
refiner_models = gr.Dropdown(label='CheckPoint', visible=True, value=checkpoints[0], choices=checkpoints)
|
219 |
+
elem += refiner_models
|
220 |
+
refresh_refiner_models = ui_components.ToolButton(value='🔄', visible=True, interactive=True)
|
221 |
+
with gr.Column():
|
222 |
+
gr.Markdown('')
|
223 |
+
with gr.Row():
|
224 |
+
elem += gr.Checkbox(label='Use this checkpoint for detailing(Face, Person, Hand)', value=True)
|
225 |
+
with gr.Row():
|
226 |
+
elem += gr.Textbox(placeholder='prompt. if empty, use main prompt', lines=3, visible=True, value='', label='Prompt')
|
227 |
+
with gr.Row():
|
228 |
+
elem += gr.Textbox(placeholder='negative prompt. if empty, use main negative prompt', lines=3, visible=True, value='', label='Negative Prompt')
|
229 |
+
with gr.Row():
|
230 |
+
with gr.Column(min_width=100):
|
231 |
+
asamplers = [constants.sampler_default]
|
232 |
+
asamplers.extend([x.name for x in shared.list_samplers()])
|
233 |
+
elem += gr.Dropdown(label='Sampling method', visible=True, value=asamplers[0], choices=asamplers)
|
234 |
+
with gr.Column(min_width=100):
|
235 |
+
upscalers = [constants.fast_upscaler]
|
236 |
+
upscalers.extend([x.name for x in shared.sd_upscalers])
|
237 |
+
elem += gr.Dropdown(label='Upscaler', visible=True, value=upscalers[0], choices=upscalers)
|
238 |
+
with gr.Row():
|
239 |
+
with gr.Column(min_width=100):
|
240 |
+
elem += gr.Slider(minimum=1, maximum=150, value=20, step=1, label='Refiner Sampling Steps', elem_id='bmab_refiner_steps')
|
241 |
+
elem += gr.Slider(minimum=1, maximum=30, value=7, step=0.5, label='Refiner CFG Scale', elem_id='bmab_refiner_cfg_scale')
|
242 |
+
elem += gr.Slider(minimum=0, maximum=1, value=0.75, step=0.01, label='Refiner Denoising Strength', elem_id='bmab_refiner_denoising')
|
243 |
+
with gr.Row():
|
244 |
+
with gr.Column(min_width=100):
|
245 |
+
elem += gr.Slider(minimum=0, maximum=4, value=1, step=0.1, label='Refiner Scale', elem_id='bmab_refiner_scale')
|
246 |
+
elem += gr.Slider(minimum=0, maximum=2048, value=0, step=1, label='Refiner Width', elem_id='bmab_refiner_width')
|
247 |
+
elem += gr.Slider(minimum=0, maximum=2048, value=0, step=1, label='Refiner Height', elem_id='bmab_refiner_height')
|
248 |
+
with gr.Accordion(f'BMAB', open=False):
|
249 |
+
with gr.Row():
|
250 |
+
with gr.Tabs(elem_id='bmab_tabs'):
|
251 |
+
with gr.Tab('Basic', elem_id='bmab_basic_tabs'):
|
252 |
+
with gr.Row():
|
253 |
+
with gr.Column():
|
254 |
+
elem += gr.Slider(minimum=0, maximum=2, value=1, step=0.05, label='Contrast')
|
255 |
+
elem += gr.Slider(minimum=0, maximum=2, value=1, step=0.05, label='Brightness')
|
256 |
+
elem += gr.Slider(minimum=-5, maximum=5, value=1, step=0.1, label='Sharpeness')
|
257 |
+
elem += gr.Slider(minimum=0, maximum=2, value=1, step=0.01, label='Color')
|
258 |
+
with gr.Column():
|
259 |
+
elem += gr.Slider(minimum=-2000, maximum=+2000, value=0, step=1, label='Color temperature')
|
260 |
+
elem += gr.Slider(minimum=0, maximum=1, value=0, step=0.05, label='Noise alpha')
|
261 |
+
elem += gr.Slider(minimum=0, maximum=1, value=0, step=0.05, label='Noise alpha at final stage')
|
262 |
+
with gr.Tab('Imaging', elem_id='bmab_imaging_tabs'):
|
263 |
+
with gr.Row():
|
264 |
+
elem += gr.Image(source='upload', type='pil')
|
265 |
+
with gr.Row():
|
266 |
+
elem += gr.Checkbox(label='Blend enabled', value=False)
|
267 |
+
with gr.Row():
|
268 |
+
with gr.Column():
|
269 |
+
elem += gr.Slider(minimum=0, maximum=1, value=1, step=0.05, label='Blend alpha')
|
270 |
+
with gr.Column():
|
271 |
+
gr.Markdown('')
|
272 |
+
with gr.Row():
|
273 |
+
elem += gr.Checkbox(label='Enable detect', value=False)
|
274 |
+
with gr.Row():
|
275 |
+
elem += gr.Textbox(placeholder='1girl', visible=True, value='', label='Prompt')
|
276 |
+
with gr.Tab('Person', elem_id='bmab_person_tabs'):
|
277 |
+
with gr.Row():
|
278 |
+
elem += gr.Checkbox(label='Enable person detailing for landscape', value=False)
|
279 |
+
with gr.Row():
|
280 |
+
elem += gr.Checkbox(label='Enable best quality (EXPERIMENTAL, Use more GPU)', value=False)
|
281 |
+
elem += gr.Checkbox(label='Force upscale ratio 1:1 without area limit', value=False)
|
282 |
+
with gr.Row():
|
283 |
+
elem += gr.Checkbox(label='Block over-scaled image', value=True)
|
284 |
+
elem += gr.Checkbox(label='Auto Upscale if Block over-scaled image enabled', value=True)
|
285 |
+
with gr.Row():
|
286 |
+
with gr.Column(min_width=100):
|
287 |
+
elem += gr.Slider(minimum=0.1, maximum=8, value=4, step=0.01, label='Upscale Ratio')
|
288 |
+
elem += gr.Slider(minimum=0, maximum=20, value=3, step=1, label='Dilation mask')
|
289 |
+
elem += gr.Slider(minimum=0.01, maximum=1, value=0.1, step=0.01, label='Large person area limit')
|
290 |
+
elem += gr.Slider(minimum=0, maximum=20, value=1, step=1, label='Limit')
|
291 |
+
elem += gr.Slider(minimum=0, maximum=2, value=1, step=0.01, visible=shared.opts.data.get('bmab_test_function', False), label='Background color (HIDDEN)')
|
292 |
+
elem += gr.Slider(minimum=0, maximum=30, value=0, step=1, visible=shared.opts.data.get('bmab_test_function', False), label='Background blur (HIDDEN)')
|
293 |
+
with gr.Column(min_width=100):
|
294 |
+
elem += gr.Slider(minimum=0, maximum=1, value=0.4, step=0.01, label='Denoising Strength')
|
295 |
+
elem += gr.Slider(minimum=1, maximum=30, value=7, step=0.5, label='CFG Scale')
|
296 |
+
gr.Markdown('')
|
297 |
+
with gr.Tab('Face', elem_id='bmab_face_tabs'):
|
298 |
+
with gr.Row():
|
299 |
+
elem += gr.Checkbox(label='Enable face detailing', value=False)
|
300 |
+
with gr.Row():
|
301 |
+
elem += gr.Checkbox(label='Enable face detailing before hires.fix', value=False)
|
302 |
+
with gr.Row():
|
303 |
+
elem += gr.Checkbox(label='Disable extra networks in prompt (LORA, Hypernetwork, ...)', value=False)
|
304 |
+
with gr.Row():
|
305 |
+
with gr.Column(min_width=100):
|
306 |
+
elem += gr.Dropdown(label='Face detailing sort by', choices=['Score', 'Size', 'Left', 'Right', 'Center'], type='value', value='Score')
|
307 |
+
with gr.Column(min_width=100):
|
308 |
+
elem += gr.Slider(minimum=0, maximum=20, value=1, step=1, label='Limit')
|
309 |
+
with gr.Tab('Face1', elem_id='bmab_face1_tabs'):
|
310 |
+
with gr.Row():
|
311 |
+
elem += gr.Textbox(placeholder='prompt. if empty, use main prompt', lines=3, visible=True, value='', label='Prompt')
|
312 |
+
with gr.Row():
|
313 |
+
elem += gr.Textbox(placeholder='negative prompt. if empty, use main negative prompt', lines=3, visible=True, value='', label='Negative Prompt')
|
314 |
+
with gr.Tab('Face2', elem_id='bmab_face2_tabs'):
|
315 |
+
with gr.Row():
|
316 |
+
elem += gr.Textbox(placeholder='prompt. if empty, use main prompt', lines=3, visible=True, value='', label='Prompt')
|
317 |
+
with gr.Row():
|
318 |
+
elem += gr.Textbox(placeholder='negative prompt. if empty, use main negative prompt', lines=3, visible=True, value='', label='Negative Prompt')
|
319 |
+
with gr.Tab('Face3', elem_id='bmab_face3_tabs'):
|
320 |
+
with gr.Row():
|
321 |
+
elem += gr.Textbox(placeholder='prompt. if empty, use main prompt', lines=3, visible=True, value='', label='Prompt')
|
322 |
+
with gr.Row():
|
323 |
+
elem += gr.Textbox(placeholder='negative prompt. if empty, use main negative prompt', lines=3, visible=True, value='', label='Negative Prompt')
|
324 |
+
with gr.Tab('Face4', elem_id='bmab_face4_tabs'):
|
325 |
+
with gr.Row():
|
326 |
+
elem += gr.Textbox(placeholder='prompt. if empty, use main prompt', lines=3, visible=True, value='', label='Prompt')
|
327 |
+
with gr.Row():
|
328 |
+
elem += gr.Textbox(placeholder='negative prompt. if empty, use main negative prompt', lines=3, visible=True, value='', label='Negative Prompt')
|
329 |
+
with gr.Tab('Face5', elem_id='bmab_face5_tabs'):
|
330 |
+
with gr.Row():
|
331 |
+
elem += gr.Textbox(placeholder='prompt. if empty, use main prompt', lines=3, visible=True, value='', label='Prompt')
|
332 |
+
with gr.Row():
|
333 |
+
elem += gr.Textbox(placeholder='negative prompt. if empty, use main negative prompt', lines=3, visible=True, value='', label='Negative Prompt')
|
334 |
+
with gr.Row():
|
335 |
+
with gr.Tab('Parameters', elem_id='bmab_parameter_tabs'):
|
336 |
+
with gr.Row():
|
337 |
+
elem += gr.Checkbox(label='Overide Parameters', value=False)
|
338 |
+
with gr.Row():
|
339 |
+
with gr.Column(min_width=100):
|
340 |
+
elem += gr.Slider(minimum=64, maximum=2048, value=512, step=8, label='Width')
|
341 |
+
elem += gr.Slider(minimum=64, maximum=2048, value=512, step=8, label='Height')
|
342 |
+
with gr.Column(min_width=100):
|
343 |
+
elem += gr.Slider(minimum=1, maximum=30, value=7, step=0.5, label='CFG Scale')
|
344 |
+
elem += gr.Slider(minimum=1, maximum=150, value=20, step=1, label='Steps')
|
345 |
+
elem += gr.Slider(minimum=0, maximum=64, value=4, step=1, label='Mask Blur')
|
346 |
+
with gr.Row():
|
347 |
+
with gr.Column(min_width=100):
|
348 |
+
asamplers = [constants.sampler_default]
|
349 |
+
asamplers.extend([x.name for x in shared.list_samplers()])
|
350 |
+
elem += gr.Dropdown(label='Sampler', visible=True, value=asamplers[0], choices=asamplers)
|
351 |
+
inpaint_area = gr.Radio(label='Inpaint area', choices=['Whole picture', 'Only masked'], type='value', value='Only masked')
|
352 |
+
elem += inpaint_area
|
353 |
+
elem += gr.Slider(label='Only masked padding, pixels', minimum=0, maximum=256, step=4, value=32)
|
354 |
+
choices = detectors.list_face_detectors()
|
355 |
+
elem += gr.Dropdown(label='Detection Model', choices=choices, type='value', value=choices[0])
|
356 |
+
with gr.Column():
|
357 |
+
elem += gr.Slider(minimum=0, maximum=1, value=0.4, step=0.01, label='Face Denoising Strength', elem_id='bmab_face_denoising_strength')
|
358 |
+
elem += gr.Slider(minimum=0, maximum=64, value=4, step=1, label='Face Dilation', elem_id='bmab_face_dilation')
|
359 |
+
elem += gr.Slider(minimum=0.1, maximum=1, value=0.35, step=0.01, label='Face Box threshold')
|
360 |
+
elem += gr.Checkbox(label='Skip face detailing by area', value=False)
|
361 |
+
elem += gr.Slider(minimum=0.0, maximum=3.0, value=0.26, step=0.01, label='Face area (MegaPixel)')
|
362 |
+
with gr.Tab('Hand', elem_id='bmab_hand_tabs'):
|
363 |
+
with gr.Row():
|
364 |
+
elem += gr.Checkbox(label='Enable hand detailing (EXPERIMENTAL)', value=False)
|
365 |
+
elem += gr.Checkbox(label='Block over-scaled image', value=True)
|
366 |
+
with gr.Row():
|
367 |
+
elem += gr.Checkbox(label='Enable best quality (EXPERIMENTAL, Use more GPU)', value=False)
|
368 |
+
with gr.Row():
|
369 |
+
elem += gr.Dropdown(label='Method', visible=True, interactive=True, value='subframe', choices=['subframe', 'each hand', 'inpaint each hand', 'at once'])
|
370 |
+
with gr.Row():
|
371 |
+
elem += gr.Textbox(placeholder='prompt. if empty, use main prompt', lines=3, visible=True, value='', label='Prompt')
|
372 |
+
with gr.Row():
|
373 |
+
elem += gr.Textbox(placeholder='negative prompt. if empty, use main negative prompt', lines=3, visible=True, value='', label='Negative Prompt')
|
374 |
+
with gr.Row():
|
375 |
+
with gr.Column():
|
376 |
+
elem += gr.Slider(minimum=0, maximum=1, value=0.4, step=0.01, label='Denoising Strength')
|
377 |
+
elem += gr.Slider(minimum=1, maximum=30, value=7, step=0.5, label='CFG Scale')
|
378 |
+
elem += gr.Checkbox(label='Auto Upscale if Block over-scaled image enabled', value=True)
|
379 |
+
with gr.Column():
|
380 |
+
elem += gr.Slider(minimum=1, maximum=4, value=2, step=0.01, label='Upscale Ratio')
|
381 |
+
elem += gr.Slider(minimum=0, maximum=1, value=0.3, step=0.01, label='Box Threshold')
|
382 |
+
elem += gr.Slider(minimum=0, maximum=0.3, value=0.1, step=0.01, label='Box Dilation')
|
383 |
+
with gr.Row():
|
384 |
+
inpaint_area = gr.Radio(label='Inpaint area', choices=['Whole picture', 'Only masked'], type='value', value='Whole picture')
|
385 |
+
elem += inpaint_area
|
386 |
+
with gr.Row():
|
387 |
+
with gr.Column():
|
388 |
+
elem += gr.Slider(label='Only masked padding, pixels', minimum=0, maximum=256, step=4, value=32)
|
389 |
+
with gr.Column():
|
390 |
+
gr.Markdown('')
|
391 |
+
with gr.Row():
|
392 |
+
elem += gr.Textbox(placeholder='Additional parameter for advanced user', visible=True, value='', label='Additional Parameter')
|
393 |
+
with gr.Tab('ControlNet', elem_id='bmab_controlnet_tabs'):
|
394 |
+
with gr.Row():
|
395 |
+
elem += gr.Checkbox(label='Enable ControlNet access', value=False)
|
396 |
+
with gr.Row():
|
397 |
+
elem += gr.Checkbox(label='Process with BMAB refiner', value=False)
|
398 |
+
with gr.Row():
|
399 |
+
with gr.Tab('Noise', elem_id='bmab_cn_noise_tabs'):
|
400 |
+
with gr.Row():
|
401 |
+
elem += gr.Checkbox(label='Enable noise', value=False)
|
402 |
+
with gr.Row():
|
403 |
+
with gr.Column():
|
404 |
+
elem += gr.Slider(minimum=0.0, maximum=2, value=0.4, step=0.05, elem_id='bmab_cn_noise', label='Noise strength')
|
405 |
+
elem += gr.Slider(minimum=0.0, maximum=1.0, value=0.1, step=0.01, elem_id='bmab_cn_noise_begin', label='Noise begin')
|
406 |
+
elem += gr.Slider(minimum=0.0, maximum=1.0, value=0.9, step=0.01, elem_id='bmab_cn_noise_end', label='Noise end')
|
407 |
+
with gr.Column():
|
408 |
+
gr.Markdown('')
|
409 |
+
with gr.Accordion(f'BMAB Postprocessor', open=False):
|
410 |
+
with gr.Row():
|
411 |
+
with gr.Tab('Resize by person', elem_id='bmab_postprocess_resize_tab'):
|
412 |
+
with gr.Row():
|
413 |
+
elem += gr.Checkbox(label='Enable resize by person', value=False)
|
414 |
+
mode = ['Inpaint', 'ControlNet inpaint+lama']
|
415 |
+
elem += gr.Dropdown(label='Mode', visible=True, value=mode[0], choices=mode)
|
416 |
+
with gr.Row():
|
417 |
+
with gr.Column():
|
418 |
+
elem += gr.Slider(minimum=0.15, maximum=0.95, value=0.15, step=0.01, label='Resize by person')
|
419 |
+
with gr.Column():
|
420 |
+
elem += gr.Slider(minimum=0, maximum=1, value=0.6, step=0.01, label='Denoising Strength for Inpaint, ControlNet')
|
421 |
+
with gr.Row():
|
422 |
+
with gr.Column():
|
423 |
+
gr.Markdown('')
|
424 |
+
with gr.Column():
|
425 |
+
elem += gr.Slider(minimum=4, maximum=128, value=30, step=1, label='Mask Dilation')
|
426 |
+
with gr.Tab('Upscale', elem_id='bmab_postprocess_upscale_tab'):
|
427 |
+
with gr.Row():
|
428 |
+
with gr.Column(min_width=100):
|
429 |
+
elem += gr.Checkbox(label='Enable upscale at final stage', value=False)
|
430 |
+
elem += gr.Checkbox(label='Detailing after upscale', value=True)
|
431 |
+
with gr.Column(min_width=100):
|
432 |
+
gr.Markdown('')
|
433 |
+
with gr.Row():
|
434 |
+
with gr.Column(min_width=100):
|
435 |
+
upscalers = [x.name for x in shared.sd_upscalers]
|
436 |
+
elem += gr.Dropdown(label='Upscaler', visible=True, value=upscalers[0], choices=upscalers)
|
437 |
+
elem += gr.Slider(minimum=1, maximum=4, value=1.5, step=0.1, label='Upscale ratio')
|
438 |
+
with gr.Tab('Filter', id='bmab_final_filter', elem_id='bmab_final_filter_tab'):
|
439 |
+
with gr.Row():
|
440 |
+
dd_final_filter = gr.Dropdown(label='Final filter', visible=True, value=filter.filters[0], choices=filter.filters)
|
441 |
+
elem += dd_final_filter
|
442 |
+
with gr.Accordion(f'BMAB Config, Preset, Installer', open=False):
|
443 |
+
with gr.Row():
|
444 |
+
configs = parameters.Parameters().list_config()
|
445 |
+
config = '' if not configs else configs[0]
|
446 |
+
with gr.Tab('Configuration', elem_id='bmab_configuration_tabs'):
|
447 |
+
with gr.Row():
|
448 |
+
with gr.Column(scale=2):
|
449 |
+
with gr.Row():
|
450 |
+
config_dd = gr.Dropdown(label='Configuration', visible=True, interactive=True, allow_custom_value=True, value=config, choices=configs)
|
451 |
+
elem += config_dd
|
452 |
+
load_btn = ui_components.ToolButton('⬇️', visible=True, interactive=True, tooltip='load configuration', elem_id='bmab_load_configuration')
|
453 |
+
save_btn = ui_components.ToolButton('⬆️', visible=True, interactive=True, tooltip='save configuration', elem_id='bmab_save_configuration')
|
454 |
+
reset_btn = ui_components.ToolButton('🔃', visible=True, interactive=True, tooltip='reset to default', elem_id='bmab_reset_configuration')
|
455 |
+
with gr.Column(scale=1):
|
456 |
+
gr.Markdown('')
|
457 |
+
with gr.Row():
|
458 |
+
with gr.Column(scale=1):
|
459 |
+
btn_reload_filter = gr.Button('reload filter', visible=True, interactive=True, elem_id='bmab_reload_filter')
|
460 |
+
with gr.Column(scale=1):
|
461 |
+
gr.Markdown('')
|
462 |
+
with gr.Column(scale=1):
|
463 |
+
gr.Markdown('')
|
464 |
+
with gr.Column(scale=1):
|
465 |
+
gr.Markdown('')
|
466 |
+
with gr.Tab('Preset', elem_id='bmab_configuration_tabs'):
|
467 |
+
with gr.Row():
|
468 |
+
with gr.Column(min_width=100):
|
469 |
+
gr.Markdown('Preset Loader : preset override UI configuration.')
|
470 |
+
with gr.Row():
|
471 |
+
presets = parameters.Parameters().list_preset()
|
472 |
+
with gr.Column(min_width=100):
|
473 |
+
with gr.Row():
|
474 |
+
preset_dd = gr.Dropdown(label='Preset', visible=True, interactive=True, allow_custom_value=True, value=presets[0], choices=presets)
|
475 |
+
elem += preset_dd
|
476 |
+
refresh_btn = ui_components.ToolButton('🔄', visible=True, interactive=True, tooltip='refresh preset', elem_id='bmab_preset_refresh')
|
477 |
+
with gr.Tab('Toy', elem_id='bmab_toy_tabs'):
|
478 |
+
with gr.Row():
|
479 |
+
merge_result = gr.Markdown('Result here')
|
480 |
+
with gr.Row():
|
481 |
+
random_checkpoint = gr.Button('Merge Random Checkpoint', visible=True, interactive=True, elem_id='bmab_merge_random_checkpoint')
|
482 |
+
with gr.Tab('Installer', elem_id='bmab_install_tabs'):
|
483 |
+
with gr.Row():
|
484 |
+
pkgs = ['GroundingDINO']
|
485 |
+
dd_pkg = gr.Dropdown(label='Package', visible=True, value=pkgs[0], choices=pkgs)
|
486 |
+
btn_install = ui_components.ToolButton('🔄', visible=True, interactive=True, tooltip='Install package', elem_id='bmab_btn_install')
|
487 |
+
with gr.Row():
|
488 |
+
markdown_install = gr.Markdown('')
|
489 |
+
with gr.Accordion(f'BMAB Testroom', open=False, visible=shared.opts.data.get('bmab_for_developer', False)):
|
490 |
+
with gr.Row():
|
491 |
+
gallery = gr.Gallery(label='Images', value=[], elem_id='bmab_testroom_gallery')
|
492 |
+
result_image = gr.Image(elem_id='bmab_result_image')
|
493 |
+
with gr.Row():
|
494 |
+
btn_fetch_images = ui_components.ToolButton('🔄', visible=True, interactive=True, tooltip='fetch images', elem_id='bmab_fetch_images')
|
495 |
+
btn_process_pipeline = ui_components.ToolButton('▶️', visible=True, interactive=True, tooltip='fetch images', elem_id='bmab_fetch_images')
|
496 |
+
|
497 |
+
gr.Markdown(f'<div style="text-align: right; vertical-align: bottom"><span style="color: green">{bmab_version}</span></div>')
|
498 |
+
|
499 |
+
def load_config(*args):
|
500 |
+
name = args[0]
|
501 |
+
ret = parameters.Parameters().load_config(name)
|
502 |
+
return ret
|
503 |
+
|
504 |
+
def save_config(*args):
|
505 |
+
name = parameters.Parameters().get_save_config_name(args)
|
506 |
+
parameters.Parameters().save_config(args)
|
507 |
+
return {
|
508 |
+
config_dd: {
|
509 |
+
'choices': parameters.Parameters().list_config(),
|
510 |
+
'value': name,
|
511 |
+
'__type__': 'update'
|
512 |
+
}
|
513 |
+
}
|
514 |
+
|
515 |
+
def reset_config(*args):
|
516 |
+
return parameters.Parameters().get_default()
|
517 |
+
|
518 |
+
def refresh_preset(*args):
|
519 |
+
return {
|
520 |
+
preset_dd: {
|
521 |
+
'choices': parameters.Parameters().list_preset(),
|
522 |
+
'value': 'None',
|
523 |
+
'__type__': 'update'
|
524 |
+
}
|
525 |
+
}
|
526 |
+
|
527 |
+
def hit_refiner_model(value, *args):
|
528 |
+
checkpoints = [constants.checkpoint_default]
|
529 |
+
checkpoints.extend([str(x) for x in sd_models.checkpoints_list.keys()])
|
530 |
+
if value not in checkpoints:
|
531 |
+
value = checkpoints[0]
|
532 |
+
return {
|
533 |
+
refiner_models: {
|
534 |
+
'choices': checkpoints,
|
535 |
+
'value': value,
|
536 |
+
'__type__': 'update'
|
537 |
+
}
|
538 |
+
}
|
539 |
+
|
540 |
+
def hit_pretraining_model(value, *args):
|
541 |
+
models = ['Select Model']
|
542 |
+
models.extend(util.list_pretraining_models())
|
543 |
+
if value not in models:
|
544 |
+
value = models[0]
|
545 |
+
return {
|
546 |
+
pretraining_models: {
|
547 |
+
'choices': models,
|
548 |
+
'value': value,
|
549 |
+
'__type__': 'update'
|
550 |
+
}
|
551 |
+
}
|
552 |
+
|
553 |
+
def hit_resample_model(value, *args):
|
554 |
+
checkpoints = [constants.checkpoint_default]
|
555 |
+
checkpoints.extend([str(x) for x in sd_models.checkpoints_list.keys()])
|
556 |
+
if value not in checkpoints:
|
557 |
+
value = checkpoints[0]
|
558 |
+
return {
|
559 |
+
resample_models: {
|
560 |
+
'choices': checkpoints,
|
561 |
+
'value': value,
|
562 |
+
'__type__': 'update'
|
563 |
+
}
|
564 |
+
}
|
565 |
+
|
566 |
+
def hit_resample_vae(value, *args):
|
567 |
+
vaes = [constants.vae_default]
|
568 |
+
vaes.extend([str(x) for x in sd_vae.vae_dict.keys()])
|
569 |
+
if value not in vaes:
|
570 |
+
value = vaes[0]
|
571 |
+
return {
|
572 |
+
resample_vaes: {
|
573 |
+
'choices': vaes,
|
574 |
+
'value': value,
|
575 |
+
'__type__': 'update'
|
576 |
+
}
|
577 |
+
}
|
578 |
+
|
579 |
+
def hit_checkpoint_model(value, *args):
|
580 |
+
checkpoints = [constants.checkpoint_default]
|
581 |
+
checkpoints.extend([str(x) for x in sd_models.checkpoints_list.keys()])
|
582 |
+
if value not in checkpoints:
|
583 |
+
value = checkpoints[0]
|
584 |
+
return {
|
585 |
+
checkpoint_models: {
|
586 |
+
'choices': checkpoints,
|
587 |
+
'value': value,
|
588 |
+
'__type__': 'update'
|
589 |
+
}
|
590 |
+
}
|
591 |
+
|
592 |
+
def hit_vae_models(value, *args):
|
593 |
+
vaes = [constants.vae_default]
|
594 |
+
vaes.extend([str(x) for x in sd_vae.vae_dict.keys()])
|
595 |
+
if value not in vaes:
|
596 |
+
value = vaes[0]
|
597 |
+
return {
|
598 |
+
vaes_models: {
|
599 |
+
'choices': vaes,
|
600 |
+
'value': value,
|
601 |
+
'__type__': 'update'
|
602 |
+
}
|
603 |
+
}
|
604 |
+
|
605 |
+
def merge_random_checkpoint(*args):
|
606 |
+
def find_random(k, f):
|
607 |
+
for v in k:
|
608 |
+
if v.startswith(f):
|
609 |
+
return v
|
610 |
+
|
611 |
+
result = ''
|
612 |
+
checkpoints = [str(x) for x in sd_models.checkpoints_list.keys()]
|
613 |
+
target = random.choices(checkpoints, k=3)
|
614 |
+
multiplier = random.randrange(10, 90, 1) / 100
|
615 |
+
index = random.randrange(0x10000000, 0xFFFFFFFF, 1)
|
616 |
+
output = f'bmab_random_{format(index, "08X")}'
|
617 |
+
extras.run_modelmerger(None, target[0], target[1], target[2], 'Weighted sum', multiplier, False, output, 'safetensors', 0, None, '', True, True, True, '{}')
|
618 |
+
result += f'{output}.safetensors generated<br>'
|
619 |
+
for x in range(1, random.randrange(0, 5, 1)):
|
620 |
+
checkpoints = [str(x) for x in sd_models.checkpoints_list.keys()]
|
621 |
+
br = find_random(checkpoints, f'{output}.safetensors')
|
622 |
+
if br is None:
|
623 |
+
return
|
624 |
+
index = random.randrange(0x10000000, 0xFFFFFFFF, 1)
|
625 |
+
output = f'bmab_random_{format(index, "08X")}'
|
626 |
+
target = random.choices(checkpoints, k=2)
|
627 |
+
multiplier = random.randrange(10, 90, 1) / 100
|
628 |
+
extras.run_modelmerger(None, br, target[0], target[1], 'Weighted sum', multiplier, False, output, 'safetensors', 0, None, '', True, True, True, '{}')
|
629 |
+
result += f'{output}.safetensors generated<br>'
|
630 |
+
debug_print('done')
|
631 |
+
return {
|
632 |
+
merge_result: {
|
633 |
+
'value': result,
|
634 |
+
'__type__': 'update'
|
635 |
+
}
|
636 |
+
}
|
637 |
+
|
638 |
+
def fetch_images(*args):
|
639 |
+
global gallery_select_index
|
640 |
+
gallery_select_index = 0
|
641 |
+
return {
|
642 |
+
gallery: {
|
643 |
+
'value': final_images,
|
644 |
+
'__type__': 'update'
|
645 |
+
}
|
646 |
+
}
|
647 |
+
|
648 |
+
def process_pipeline(*args):
|
649 |
+
config, a = parameters.parse_args(args)
|
650 |
+
preview = final_images[gallery_select_index]
|
651 |
+
p = last_process
|
652 |
+
ctx = context.Context.newContext(bmab_script, p, a, gallery_select_index)
|
653 |
+
preview = pipeline.process(ctx, preview)
|
654 |
+
images.save_image(
|
655 |
+
preview, p.outpath_samples, '',
|
656 |
+
p.all_seeds[gallery_select_index], p.all_prompts[gallery_select_index],
|
657 |
+
shared.opts.samples_format, p=p, suffix="-testroom")
|
658 |
+
return {
|
659 |
+
result_image: {
|
660 |
+
'value': preview,
|
661 |
+
'__type__': 'update'
|
662 |
+
}
|
663 |
+
}
|
664 |
+
|
665 |
+
def reload_filter(f1, f2, f3, f4, f5, *args):
|
666 |
+
filter.reload_filters()
|
667 |
+
return {
|
668 |
+
dd_hiresfix_filter1: {
|
669 |
+
'choices': filter.filters,
|
670 |
+
'value': f1,
|
671 |
+
'__type__': 'update'
|
672 |
+
},
|
673 |
+
dd_hiresfix_filter2: {
|
674 |
+
'choices': filter.filters,
|
675 |
+
'value': f2,
|
676 |
+
'__type__': 'update'
|
677 |
+
},
|
678 |
+
dd_resample_filter: {
|
679 |
+
'choices': filter.filters,
|
680 |
+
'value': f3,
|
681 |
+
'__type__': 'update'
|
682 |
+
},
|
683 |
+
dd_resize_filter: {
|
684 |
+
'choices': filter.filters,
|
685 |
+
'value': f4,
|
686 |
+
'__type__': 'update'
|
687 |
+
},
|
688 |
+
dd_final_filter: {
|
689 |
+
'choices': filter.filters,
|
690 |
+
'value': f5,
|
691 |
+
'__type__': 'update'
|
692 |
+
}
|
693 |
+
}
|
694 |
+
|
695 |
+
def image_selected(data: gr.SelectData, *args):
|
696 |
+
debug_print(data.index)
|
697 |
+
global gallery_select_index
|
698 |
+
gallery_select_index = data.index
|
699 |
+
|
700 |
+
def hit_install(*args):
|
701 |
+
pkg_name = args[0]
|
702 |
+
if pkg_name == 'GroundingDINO':
|
703 |
+
installer.install_groudingdino()
|
704 |
+
msg = f'{pkg_name} installed'
|
705 |
+
else:
|
706 |
+
msg = 'Nothing installed.'
|
707 |
+
return {
|
708 |
+
markdown_install: {
|
709 |
+
'value': msg,
|
710 |
+
'__type__': 'update'
|
711 |
+
}
|
712 |
+
}
|
713 |
+
|
714 |
+
def stop_process(*args):
|
715 |
+
bscript.stop_generation = True
|
716 |
+
gr.Info('Waiting for processing done.')
|
717 |
+
|
718 |
+
load_btn.click(load_config, inputs=[config_dd], outputs=elem)
|
719 |
+
save_btn.click(save_config, inputs=elem, outputs=[config_dd])
|
720 |
+
reset_btn.click(reset_config, outputs=elem)
|
721 |
+
refresh_btn.click(refresh_preset, outputs=elem)
|
722 |
+
refresh_refiner_models.click(hit_refiner_model, inputs=[refiner_models], outputs=[refiner_models])
|
723 |
+
refresh_pretraining_models.click(hit_pretraining_model, inputs=[pretraining_models], outputs=[pretraining_models])
|
724 |
+
refresh_resample_models.click(hit_resample_model, inputs=[resample_models], outputs=[resample_models])
|
725 |
+
refresh_resample_vaes.click(hit_resample_vae, inputs=[resample_vaes], outputs=[resample_vaes])
|
726 |
+
refresh_checkpoint_models.click(hit_checkpoint_model, inputs=[checkpoint_models], outputs=[checkpoint_models])
|
727 |
+
refresh_vae_models.click(hit_vae_models, inputs=[vaes_models], outputs=[vaes_models])
|
728 |
+
random_checkpoint.click(merge_random_checkpoint, outputs=[merge_result])
|
729 |
+
btn_fetch_images.click(fetch_images, outputs=[gallery])
|
730 |
+
btn_reload_filter.click(reload_filter, inputs=[dd_hiresfix_filter1, dd_hiresfix_filter2, dd_resample_filter, dd_resize_filter, dd_final_filter], outputs=[dd_hiresfix_filter1, dd_hiresfix_filter2, dd_resample_filter, dd_resize_filter, dd_final_filter])
|
731 |
+
|
732 |
+
btn_process_pipeline.click(process_pipeline, inputs=elem, outputs=[result_image])
|
733 |
+
gallery.select(image_selected, inputs=[gallery])
|
734 |
+
|
735 |
+
btn_install.click(hit_install, inputs=[dd_pkg], outputs=[markdown_install])
|
736 |
+
btn_stop.click(stop_process)
|
737 |
+
|
738 |
+
return elem
|
739 |
+
|
740 |
+
|
741 |
+
def on_ui_settings():
|
742 |
+
shared.opts.add_option('bmab_debug_print', shared.OptionInfo(False, 'Print debug message.', section=('bmab', 'BMAB')))
|
743 |
+
shared.opts.add_option('bmab_debug_logging', shared.OptionInfo(False, 'Enable developer logging.', section=('bmab', 'BMAB')))
|
744 |
+
shared.opts.add_option('bmab_show_extends', shared.OptionInfo(False, 'Show before processing image. (DO NOT ENABLE IN CLOUD)', section=('bmab', 'BMAB')))
|
745 |
+
shared.opts.add_option('bmab_test_function', shared.OptionInfo(False, 'Show Test Function', section=('bmab', 'BMAB')))
|
746 |
+
shared.opts.add_option('bmab_keep_original_setting', shared.OptionInfo(False, 'Keep original setting', section=('bmab', 'BMAB')))
|
747 |
+
shared.opts.add_option('bmab_save_image_before_process', shared.OptionInfo(False, 'Save image that before processing', section=('bmab', 'BMAB')))
|
748 |
+
shared.opts.add_option('bmab_save_image_after_process', shared.OptionInfo(False, 'Save image that after processing (some bugs)', section=('bmab', 'BMAB')))
|
749 |
+
shared.opts.add_option('bmab_for_developer', shared.OptionInfo(False, 'Show developer hidden function.', section=('bmab', 'BMAB')))
|
750 |
+
shared.opts.add_option('bmab_use_dino_predict', shared.OptionInfo(False, 'Use GroudingDINO for detecting hand. GroudingDINO should be installed manually.', section=('bmab', 'BMAB')))
|
751 |
+
shared.opts.add_option('bmab_max_detailing_element', shared.OptionInfo(
|
752 |
+
default=0, label='Max Detailing Element', component=gr.Slider, component_args={'minimum': 0, 'maximum': 10, 'step': 1}, section=('bmab', 'BMAB')))
|
753 |
+
shared.opts.add_option('bmab_detail_full', shared.OptionInfo(True, 'Allways use FULL, VAE type for encode when detail anything. (v1.6.0)', section=('bmab', 'BMAB')))
|
754 |
+
shared.opts.add_option('bmab_optimize_vram', shared.OptionInfo(default='None', label='Checkpoint for Person, Face, Hand', component=gr.Radio, component_args={'choices': ['None', 'low vram', 'med vram']}, section=('bmab', 'BMAB')))
|
755 |
+
mask_names = masking.list_mask_names()
|
756 |
+
shared.opts.add_option('bmab_mask_model', shared.OptionInfo(default=mask_names[0], label='Masking model', component=gr.Radio, component_args={'choices': mask_names}, section=('bmab', 'BMAB')))
|
757 |
+
shared.opts.add_option('bmab_use_specific_model', shared.OptionInfo(False, 'Use specific model', section=('bmab', 'BMAB')))
|
758 |
+
shared.opts.add_option('bmab_model', shared.OptionInfo(default='', label='Checkpoint for Person, Face, Hand', component=gr.Textbox, component_args='', section=('bmab', 'BMAB')))
|
759 |
+
shared.opts.add_option('bmab_cn_openpose', shared.OptionInfo(default='control_v11p_sd15_openpose_fp16 [73c2b67d]', label='ControlNet openpose model', component=gr.Textbox, component_args='', section=('bmab', 'BMAB')))
|
760 |
+
shared.opts.add_option('bmab_cn_lineart', shared.OptionInfo(default='control_v11p_sd15_lineart [43d4be0d]', label='ControlNet lineart model', component=gr.Textbox, component_args='', section=('bmab', 'BMAB')))
|
761 |
+
shared.opts.add_option('bmab_cn_inpaint', shared.OptionInfo(default='control_v11p_sd15_inpaint_fp16 [be8bc0ed]', label='ControlNet inpaint model', component=gr.Textbox, component_args='', section=('bmab', 'BMAB')))
|
762 |
+
shared.opts.add_option('bmab_cn_tile_resample', shared.OptionInfo(default='control_v11f1e_sd15_tile_fp16 [3b860298]', label='ControlNet tile model', component=gr.Textbox, component_args='', section=('bmab', 'BMAB')))
|
763 |
+
|