o yf@s|ddlZddlmZddlmZmZmZmZmZm Z m Z ddl m Z ddde fdd Zd d Zdd e de d efddZdS)N)Image)sharedimagesdevicesscriptsscripts_postprocessing ui_commoninfotext_utils)optsT) save_outputr cGsJttjjddg}dd} |dkr|dkr|} ntjp!tj} d} t| ||||} t | tj_ | D]]\} }tj |tj_ dtj_ tjjrNnFt| trdzt| }Wn tycYq5w| }t|\}}|rs||d<t|jd vr||n|d }tj||tjj rq5i}|g|jD]}||}tjr|durtj !tj "|d }||}nd}d}d #d d|j$%D} tj&r||j'_$| |j'j$d<tj(|j'|rtj)|j'| |tj*| dddd|||d \}}|j+rtj !|d d}d}zt,|dd}|-}Wdn 1swYWn t.y+Ynwtjj/}|dkrA|rA|d|j+}n|dkrR|rR|j+d|}n|dkr]|r]|}n|j+}|-}|rt,|ddd }|0|Wdn 1swY|dks|r|1|j'qq5ttj2|t34| dfS)Nextras)jobcss|dkr2|D](}t|tjrt|}d}nttj|j}tj |j d}||fVqdS|dkrUt j j r>Jd|sDJdt |}|D]}||fVqKdS|s[Jd|dfVdS)Nrz,--hide-ui-dir-config option must be disabledzinput directory not selectedzimage not selected) isinstancerr fix_imagereadospathabspathnamesplitext orig_namercmd_optshide_ui_dir_config listfiles) extras_modeimage image_folder input_dirimgfn image_listfilenamer%gC:\Users\Luke\Documents\Stable diffusion\Automatic1111\stable-diffusion-webui\modules\postprocessing.py get_imagess&       z&run_postprocessing..get_imagesrrF parameters)RGBARGBr*rz, cSs8g|]\}}|dur||kr|n |dt|qS)Nz: )r quote).0kvr%r%r& Ws8z&run_postprocessing..postprocessingT) rbasename extensioninfoshort_filename no_promptgridpnginfo_section_name existing_infoforced_filenamesuffixz.txtutf8)encodingPrepend AppendKeepw)5rtorch_gcrstatebeginr outdir_samplesoutdir_extras_sampleslistlen job_countnextjobtextinfoskipped interruptedrstrrr Exceptionread_info_from_imagerPostprocessedImagemodeconvertrscripts_postprocrun extra_images get_suffixuse_original_name_batchrrrr1joinr3itemsenable_pnginforassign_current_image save_imagesamples_formatcaptionopenstripFileNotFoundError&postprocessing_existing_caption_actionwriteappendendrplaintext_to_html)rrrr output_dirshow_extras_resultsr argsoutputsr'ZoutpathinfotextZdata_to_processZimage_placeholderr image_datar(existing_pnginfoZ initial_pp used_suffixesppr:r1r9fullfn_Zcaption_filenameZexisting_captionfileactionr_r%r%r&run_postprocessing s        *  0 rucOst|i|S)N)ru)id_taskrjkwargsr%r%r&run_postprocessing_webuisrx upscale_firstmax_side_lengthc CsXtjd|| || | | |||d d|dd|| dd}t||||||g|Rd|iS)zold handler for APIT) Zupscale_enabledZ upscale_modeZ upscale_byrzZupscale_to_widthZupscale_to_heightZ upscale_cropZupscaler_1_nameZupscaler_2_nameZupscaler_2_visibility)enablegfpgan_visibility)r{codeformer_visibilitycodeformer_weight)ZUpscaleZGFPGAN CodeFormerr )rrTcreate_args_for_runru)r resize_moderrr rhrir|r}r~Zupscaling_resizeZupscaling_resize_wZupscaling_resize_hZupscaling_cropZextras_upscaler_1Zextras_upscaler_2Zextras_upscaler_2_visibilityryr rzrjr%r%r& run_extrass*  r)Tr)rPILrmodulesrrrrrrr modules.sharedr boolrurxintrr%r%r%r&s $ y