Skip to content

Commit 9ec8e72

Browse files
AUTOMATIC1111ruchej
authored andcommitted
put code that can cause an exception into its own function for AUTOMATIC1111#14120
1 parent 800f367 commit 9ec8e72

File tree

1 file changed

+33
-29
lines changed

1 file changed

+33
-29
lines changed

modules/scripts.py

+33-29
Original file line numberDiff line numberDiff line change
@@ -560,54 +560,58 @@ def apply_on_before_component_callbacks(self):
560560
on_after.clear()
561561

562562
def create_script_ui(self, script):
563-
import modules.api.models as api_models
564563

565564
script.args_from = len(self.inputs)
566565
script.args_to = len(self.inputs)
567566

567+
try:
568+
self.create_script_ui_inner(script)
569+
except Exception:
570+
errors.report(f"Error creating UI for {script.name}: ", exc_info=True)
571+
572+
def create_script_ui_inner(self, script):
573+
import modules.api.models as api_models
574+
568575
controls = wrap_call(script.ui, script.filename, "ui", script.is_img2img)
569576

570577
if controls is None:
571578
return
572579

573-
try:
574-
script.name = wrap_call(script.title, script.filename, "title", default=script.filename).lower()
575-
api_args = []
580+
script.name = wrap_call(script.title, script.filename, "title", default=script.filename).lower()
576581

577-
for control in controls:
578-
control.custom_script_source = os.path.basename(script.filename)
582+
api_args = []
579583

580-
arg_info = api_models.ScriptArg(label=control.label or "")
584+
for control in controls:
585+
control.custom_script_source = os.path.basename(script.filename)
581586

582-
for field in ("value", "minimum", "maximum", "step"):
583-
v = getattr(control, field, None)
584-
if v is not None:
585-
setattr(arg_info, field, v)
587+
arg_info = api_models.ScriptArg(label=control.label or "")
586588

587-
choices = getattr(control, 'choices', None) # as of gradio 3.41, some items in choices are strings, and some are tuples where the first elem is the string
588-
if choices is not None:
589-
arg_info.choices = [x[0] if isinstance(x, tuple) else x for x in choices]
589+
for field in ("value", "minimum", "maximum", "step"):
590+
v = getattr(control, field, None)
591+
if v is not None:
592+
setattr(arg_info, field, v)
590593

591-
api_args.append(arg_info)
594+
choices = getattr(control, 'choices', None) # as of gradio 3.41, some items in choices are strings, and some are tuples where the first elem is the string
595+
if choices is not None:
596+
arg_info.choices = [x[0] if isinstance(x, tuple) else x for x in choices]
592597

593-
script.api_info = api_models.ScriptInfo(
594-
name=script.name,
595-
is_img2img=script.is_img2img,
596-
is_alwayson=script.alwayson,
597-
args=api_args,
598-
)
598+
api_args.append(arg_info)
599599

600-
if script.infotext_fields is not None:
601-
self.infotext_fields += script.infotext_fields
600+
script.api_info = api_models.ScriptInfo(
601+
name=script.name,
602+
is_img2img=script.is_img2img,
603+
is_alwayson=script.alwayson,
604+
args=api_args,
605+
)
602606

603-
if script.paste_field_names is not None:
604-
self.paste_field_names += script.paste_field_names
607+
if script.infotext_fields is not None:
608+
self.infotext_fields += script.infotext_fields
605609

606-
self.inputs += controls
607-
script.args_to = len(self.inputs)
610+
if script.paste_field_names is not None:
611+
self.paste_field_names += script.paste_field_names
608612

609-
except Exception:
610-
errors.report(f"Error creating UI for {script.name}: ", exc_info=True)
613+
self.inputs += controls
614+
script.args_to = len(self.inputs)
611615

612616
def setup_ui_for_section(self, section, scriptlist=None):
613617
if scriptlist is None:

0 commit comments

Comments
 (0)