| 441 | self.inputs = [None] |
| 442 | |
| 443 | def setup_ui(self, parent='unknown', accordion=True): |
| 444 | import modules.api.models as api_models |
| 445 | self.titles = [wrap_call(script.title, script.filename, "title") or f"{script.filename} [error]" for script in self.selectable_scripts] |
| 446 | self.alwayson_titles = [wrap_call(script.title, script.filename, "title") or f"{script.filename} [error]" for script in self.alwayson_scripts] |
| 447 | |
| 448 | inputs = [] |
| 449 | inputs_alwayson = [True] |
| 450 | |
| 451 | def create_script_ui(script: Script, inputs, inputs_alwayson): |
| 452 | script.parent = parent |
| 453 | script.args_from = len(inputs) |
| 454 | script.args_to = len(inputs) |
| 455 | controls = wrap_call(script.ui, script.filename, "ui", script.is_img2img) |
| 456 | if controls is None: |
| 457 | return |
| 458 | script.name = wrap_call(script.title, script.filename, "title", default=script.filename).lower() |
| 459 | api_args = [] |
| 460 | for control in controls: |
| 461 | if hasattr(gr.components, 'IOComponent'): |
| 462 | if not isinstance(control, gr.components.IOComponent): |
| 463 | log.error(f'Invalid script control: "{script.filename}" control={control}') |
| 464 | continue |
| 465 | else: |
| 466 | if not isinstance(control, gr.components.Component): |
| 467 | log.error(f'Invalid script control: "{script.filename}" control={control}') |
| 468 | continue |
| 469 | debug(f'Script control: parent={script.parent} script="{script.name}" label="{control.label}" type={control} id={control.elem_id}') |
| 470 | control.custom_script_source = os.path.basename(script.filename) |
| 471 | arg_info = api_models.ScriptArg(label=control.label or "") |
| 472 | for field in ("value", "minimum", "maximum", "step", "choices"): |
| 473 | v = getattr(control, field, None) |
| 474 | if v is not None: |
| 475 | setattr(arg_info, field, v) |
| 476 | api_args.append(arg_info) |
| 477 | |
| 478 | script.api_info = api_models.ItemScript( |
| 479 | name=script.name, |
| 480 | is_img2img=script.is_img2img, |
| 481 | is_alwayson=script.alwayson, |
| 482 | args=api_args, |
| 483 | ) |
| 484 | if script.infotext_fields is not None: |
| 485 | self.infotext_fields += script.infotext_fields |
| 486 | if script.paste_field_names is not None: |
| 487 | self.paste_field_names += script.paste_field_names |
| 488 | inputs += controls |
| 489 | inputs_alwayson += [script.alwayson for _ in controls] |
| 490 | script.args_to = len(inputs) |
| 491 | |
| 492 | with gr.Row(): |
| 493 | dropdown = gr.Dropdown(label="Script", elem_id=f'{parent}_script_list', choices=["None"] + self.titles, value="None", type="index") |
| 494 | inputs.insert(0, dropdown) |
| 495 | |
| 496 | # internal |
| 497 | with gr.Row(): |
| 498 | for script in self.alwayson_scripts: |
| 499 | if not script.standalone: |
| 500 | continue |