Skip to content

Commit

Permalink
Merge pull request #14120 from AUTOMATIC1111/protect-against-bad-ui-c…
Browse files Browse the repository at this point in the history
…reation-scripts

catch uncaught exception with ui creation scripts
  • Loading branch information
AUTOMATIC1111 authored Dec 2, 2023
2 parents ef1723e + 8a6e4bd commit 5ed7daa
Showing 1 changed file with 29 additions and 25 deletions.
54 changes: 29 additions & 25 deletions modules/scripts.py
Original file line number Diff line number Diff line change
Expand Up @@ -570,40 +570,44 @@ def create_script_ui(self, script):
if controls is None:
return

script.name = wrap_call(script.title, script.filename, "title", default=script.filename).lower()
api_args = []
try:
script.name = wrap_call(script.title, script.filename, "title", default=script.filename).lower()
api_args = []

for control in controls:
control.custom_script_source = os.path.basename(script.filename)
for control in controls:
control.custom_script_source = os.path.basename(script.filename)

arg_info = api_models.ScriptArg(label=control.label or "")
arg_info = api_models.ScriptArg(label=control.label or "")

for field in ("value", "minimum", "maximum", "step"):
v = getattr(control, field, None)
if v is not None:
setattr(arg_info, field, v)
for field in ("value", "minimum", "maximum", "step"):
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
if choices is not None:
arg_info.choices = [x[0] if isinstance(x, tuple) else x for x in choices]
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]

api_args.append(arg_info)
api_args.append(arg_info)

script.api_info = api_models.ScriptInfo(
name=script.name,
is_img2img=script.is_img2img,
is_alwayson=script.alwayson,
args=api_args,
)
script.api_info = api_models.ScriptInfo(
name=script.name,
is_img2img=script.is_img2img,
is_alwayson=script.alwayson,
args=api_args,
)

if script.infotext_fields is not None:
self.infotext_fields += script.infotext_fields
if script.infotext_fields is not None:
self.infotext_fields += script.infotext_fields

if script.paste_field_names is not None:
self.paste_field_names += script.paste_field_names
if script.paste_field_names is not None:
self.paste_field_names += script.paste_field_names

self.inputs += controls
script.args_to = len(self.inputs)
self.inputs += controls
script.args_to = len(self.inputs)

except Exception:
errors.report(f"Error creating UI for {script.name}: ", exc_info=True)

def setup_ui_for_section(self, section, scriptlist=None):
if scriptlist is None:
Expand Down

0 comments on commit 5ed7daa

Please sign in to comment.