2023-08-07 00:42:13 -06:00
import math
2023-05-31 13:40:09 -06:00
import gradio as gr
2023-08-07 00:42:13 -06:00
from modules import scripts , shared , ui_components , ui_settings , generation_parameters_copypaste
2023-05-31 13:40:09 -06:00
from modules . ui_components import FormColumn
class ExtraOptionsSection ( scripts . Script ) :
section = " extra_options "
def __init__ ( self ) :
self . comps = None
self . setting_names = None
def title ( self ) :
return " Extra options "
def show ( self , is_img2img ) :
return scripts . AlwaysVisible
def ui ( self , is_img2img ) :
self . comps = [ ]
self . setting_names = [ ]
2023-08-07 00:42:13 -06:00
self . infotext_fields = [ ]
mapping = { k : v for v , k in generation_parameters_copypaste . infotext_to_setting_name_mapping }
2023-05-31 13:40:09 -06:00
with gr . Blocks ( ) as interface :
2023-08-07 00:42:13 -06:00
with gr . Accordion ( " Options " , open = False ) if shared . opts . extra_options_accordion and shared . opts . extra_options else gr . Group ( ) :
row_count = math . ceil ( len ( shared . opts . extra_options ) / shared . opts . extra_options_cols )
for row in range ( row_count ) :
with gr . Row ( ) :
for col in range ( shared . opts . extra_options_cols ) :
index = row * shared . opts . extra_options_cols + col
if index > = len ( shared . opts . extra_options ) :
break
setting_name = shared . opts . extra_options [ index ]
2023-05-31 13:40:09 -06:00
2023-08-07 00:42:13 -06:00
with FormColumn ( ) :
comp = ui_settings . create_setting_component ( setting_name )
self . comps . append ( comp )
self . setting_names . append ( setting_name )
setting_infotext_name = mapping . get ( setting_name )
if setting_infotext_name is not None :
self . infotext_fields . append ( ( comp , setting_infotext_name ) )
2023-05-31 13:40:09 -06:00
def get_settings_values ( ) :
2023-08-07 09:49:23 -06:00
res = [ ui_settings . get_value_for_setting ( key ) for key in self . setting_names ]
return res [ 0 ] if len ( res ) == 1 else res
2023-05-31 13:40:09 -06:00
interface . load ( fn = get_settings_values , inputs = [ ] , outputs = self . comps , queue = False , show_progress = False )
return self . comps
def before_process ( self , p , * args ) :
for name , value in zip ( self . setting_names , args ) :
if name not in p . override_settings :
p . override_settings [ name ] = value
shared . options_templates . update ( shared . options_section ( ( ' ui ' , " User interface " ) , {
2023-08-04 23:21:28 -06:00
" extra_options " : shared . OptionInfo ( [ ] , " Options in main UI " , ui_components . DropdownMulti , lambda : { " choices " : list ( shared . opts . data_labels . keys ( ) ) } ) . js ( " info " , " settingsHintsShowQuicksettings " ) . info ( " setting entries that also appear in txt2img/img2img interfaces " ) . needs_reload_ui ( ) ,
2023-08-07 00:42:13 -06:00
" extra_options_cols " : shared . OptionInfo ( 1 , " Options in main UI - number of columns " , gr . Number , { " precision " : 0 } ) . needs_reload_ui ( ) ,
" extra_options_accordion " : shared . OptionInfo ( False , " Options in main UI - place into an accordion " ) . needs_reload_ui ( )
2023-05-31 13:40:09 -06:00
} ) )
2023-08-07 00:42:13 -06:00