Commit ef6b8123 authored by AUTOMATIC1111's avatar AUTOMATIC1111

put code that can cause an exception into its own function for #14120

parent 5ed7daa3
...@@ -560,54 +560,58 @@ class ScriptRunner: ...@@ -560,54 +560,58 @@ class ScriptRunner:
on_after.clear() on_after.clear()
def create_script_ui(self, script): def create_script_ui(self, script):
import modules.api.models as api_models
script.args_from = len(self.inputs) script.args_from = len(self.inputs)
script.args_to = len(self.inputs) script.args_to = len(self.inputs)
try:
self.create_script_ui_inner(script)
except Exception:
errors.report(f"Error creating UI for {script.name}: ", exc_info=True)
def create_script_ui_inner(self, script):
import modules.api.models as api_models
controls = wrap_call(script.ui, script.filename, "ui", script.is_img2img) controls = wrap_call(script.ui, script.filename, "ui", script.is_img2img)
if controls is None: if controls is None:
return return
try: script.name = wrap_call(script.title, script.filename, "title", default=script.filename).lower()
script.name = wrap_call(script.title, script.filename, "title", default=script.filename).lower()
api_args = []
for control in controls: api_args = []
control.custom_script_source = os.path.basename(script.filename)
arg_info = api_models.ScriptArg(label=control.label or "") for control in controls:
control.custom_script_source = os.path.basename(script.filename)
for field in ("value", "minimum", "maximum", "step"): arg_info = api_models.ScriptArg(label=control.label or "")
v = getattr(control, field, None)
if v is not None:
setattr(arg_info, field, v)
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 for field in ("value", "minimum", "maximum", "step"):
if choices is not None: v = getattr(control, field, None)
arg_info.choices = [x[0] if isinstance(x, tuple) else x for x in choices] if v is not None:
setattr(arg_info, field, v)
api_args.append(arg_info) 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
if choices is not None:
arg_info.choices = [x[0] if isinstance(x, tuple) else x for x in choices]
script.api_info = api_models.ScriptInfo( api_args.append(arg_info)
name=script.name,
is_img2img=script.is_img2img,
is_alwayson=script.alwayson,
args=api_args,
)
if script.infotext_fields is not None: script.api_info = api_models.ScriptInfo(
self.infotext_fields += script.infotext_fields name=script.name,
is_img2img=script.is_img2img,
is_alwayson=script.alwayson,
args=api_args,
)
if script.paste_field_names is not None: if script.infotext_fields is not None:
self.paste_field_names += script.paste_field_names self.infotext_fields += script.infotext_fields
self.inputs += controls if script.paste_field_names is not None:
script.args_to = len(self.inputs) self.paste_field_names += script.paste_field_names
except Exception: self.inputs += controls
errors.report(f"Error creating UI for {script.name}: ", exc_info=True) script.args_to = len(self.inputs)
def setup_ui_for_section(self, section, scriptlist=None): def setup_ui_for_section(self, section, scriptlist=None):
if scriptlist is None: if scriptlist is None:
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment