@@ -560,54 +560,58 @@ def apply_on_before_component_callbacks(self):
560
560
on_after .clear ()
561
561
562
562
def create_script_ui (self , script ):
563
- import modules .api .models as api_models
564
563
565
564
script .args_from = len (self .inputs )
566
565
script .args_to = len (self .inputs )
567
566
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
+
568
575
controls = wrap_call (script .ui , script .filename , "ui" , script .is_img2img )
569
576
570
577
if controls is None :
571
578
return
572
579
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 ()
576
581
577
- for control in controls :
578
- control .custom_script_source = os .path .basename (script .filename )
582
+ api_args = []
579
583
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 )
581
586
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 "" )
586
588
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 )
590
593
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 ]
592
597
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 )
599
599
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
+ )
602
606
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
605
609
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
608
612
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 )
611
615
612
616
def setup_ui_for_section (self , section , scriptlist = None ):
613
617
if scriptlist is None :
0 commit comments