2023-01-22 23:24:43 -07:00
import gradio as gr
2023-12-02 08:01:11 -07:00
from modules import scripts , shared , ui_common , postprocessing , call_queue , ui_toprow
2024-01-01 07:25:30 -07:00
import modules . infotext_utils as parameters_copypaste
2024-01-23 10:56:49 -07:00
from modules . ui_components import ResizeHandleRow
2023-01-22 23:24:43 -07:00
def create_ui ( ) :
2023-12-02 08:01:11 -07:00
dummy_component = gr . Label ( visible = False )
2024-01-20 00:49:05 -07:00
tab_index = gr . Number ( value = 0 , visible = False )
2023-01-22 23:24:43 -07:00
2024-01-23 10:56:49 -07:00
with ResizeHandleRow ( equal_height = False , variant = ' compact ' ) :
2023-01-22 23:24:43 -07:00
with gr . Column ( variant = ' compact ' ) :
with gr . Tabs ( elem_id = " mode_extras " ) :
2023-03-29 12:04:02 -06:00
with gr . TabItem ( ' Single Image ' , id = " single_image " , elem_id = " extras_single_tab " ) as tab_single :
2024-03-20 00:28:32 -06:00
extras_image = gr . Image ( label = " Source " , source = " upload " , interactive = True , type = " pil " , elem_id = " extras_image " , image_mode = " RGBA " )
2023-01-22 23:24:43 -07:00
2023-03-29 12:04:02 -06:00
with gr . TabItem ( ' Batch Process ' , id = " batch_process " , elem_id = " extras_batch_process_tab " ) as tab_batch :
2023-04-09 13:33:09 -06:00
image_batch = gr . Files ( label = " Batch Process " , interactive = True , elem_id = " extras_image_batch " )
2023-01-22 23:24:43 -07:00
2023-03-29 12:04:02 -06:00
with gr . TabItem ( ' Batch from Directory ' , id = " batch_from_directory " , elem_id = " extras_batch_directory_tab " ) as tab_batch_dir :
2023-01-22 23:24:43 -07:00
extras_batch_input_dir = gr . Textbox ( label = " Input directory " , * * shared . hide_dirs , placeholder = " A directory on the same machine where the server is running. " , elem_id = " extras_batch_input_dir " )
extras_batch_output_dir = gr . Textbox ( label = " Output directory " , * * shared . hide_dirs , placeholder = " Leave blank to save images to the default path. " , elem_id = " extras_batch_output_dir " )
show_extras_results = gr . Checkbox ( label = ' Show result images ' , value = True , elem_id = " extras_show_extras_results " )
script_inputs = scripts . scripts_postproc . setup_ui ( )
with gr . Column ( ) :
2023-12-02 08:01:11 -07:00
toprow = ui_toprow . Toprow ( is_compact = True , is_img2img = False , id_part = " extras " )
toprow . create_inline_toprow_image ( )
submit = toprow . submit
2024-01-01 09:31:06 -07:00
output_panel = ui_common . create_output_panel ( " extras " , shared . opts . outdir_extras_samples )
2023-01-22 23:24:43 -07:00
tab_single . select ( fn = lambda : 0 , inputs = [ ] , outputs = [ tab_index ] )
tab_batch . select ( fn = lambda : 1 , inputs = [ ] , outputs = [ tab_index ] )
tab_batch_dir . select ( fn = lambda : 2 , inputs = [ ] , outputs = [ tab_index ] )
submit . click (
2023-12-04 03:11:00 -07:00
fn = call_queue . wrap_gradio_gpu_call ( postprocessing . run_postprocessing_webui , extra_outputs = [ None , ' ' ] ) ,
2023-12-02 08:01:11 -07:00
_js = " submit_extras " ,
2023-01-22 23:24:43 -07:00
inputs = [
2023-12-02 08:01:11 -07:00
dummy_component ,
2023-01-22 23:24:43 -07:00
tab_index ,
extras_image ,
image_batch ,
extras_batch_input_dir ,
extras_batch_output_dir ,
show_extras_results ,
* script_inputs
] ,
outputs = [
2024-01-01 09:31:06 -07:00
output_panel . gallery ,
2024-01-04 09:47:00 -07:00
output_panel . generation_info ,
2024-01-01 09:31:06 -07:00
output_panel . html_log ,
2023-12-02 08:01:11 -07:00
] ,
show_progress = False ,
2023-01-22 23:24:43 -07:00
)
parameters_copypaste . add_paste_fields ( " extras " , extras_image , None )
extras_image . change (
fn = scripts . scripts_postproc . image_changed ,
inputs = [ ] , outputs = [ ]
)