o yf*6@sJddlZddlmZddlmZddlZddlmZm Z m Z m Z m Z ddl ZddlmZddlmZmZddlmZmZmZddlmZmZdd lmZddlmZddlmZdd lm Z ddl!Zd,d dZ"de#dej$de%de#de#de%de&de%de%de%de&de&de&de%de%de%de&d e%d!e'd"e%d#e%d$e#d%e#d&e#d'e'd(e(d)e#f6d*d+Z)dS)-N)closing)Path)ImageImageOps ImageFilter ImageEnhanceUnidentifiedImageError)images)create_override_settings_dictparse_generation_parameters) Processed StableDiffusionProcessingImg2Imgprocess_images)optsstate)get_closet_checkpoint_match)plaintext_to_htmlF?c ' sr|}t|ttj|dd} d} |r+t|} t| } | r+tdt | dtdt | d|j |j dt | |j t _ |j} |j}|j}|j}|j}|j}|j}t|d d}d}d}t| D]\}}|d d t | t _t jrdt _t jst jr|Szt|}Wnty}z t|WYd}~qid}~wwt |}|rt!|j"||_"t!|j#||_#|g|j |_$t%|}| rt | d kr| d }n%t%|}t|&|j'd }t |d krtd|d|dqi|d }t|}||_(|rz-|} | rt)j*+| t)j*,|}!t|!} t-| \}"}#t.|"}$fdd|$/D}$Wn t0y@i}$Ynw| d|$vrMd|$dnd|_|d|$vr]d|$dnd|_t!|$d||_t1|$d||_|$d||_t!|$d||_t|$dd}%|%dur|%j2|jd <n|r||jd <n|j3d d|r||_4d|jd<d|jd<|j d ks|j d kr|j'd|jd <n|j'|jd <t5j6j7j8|g|R}&|&dur|j3ddt9|}&|s6|&r6|r|j:|&j|j;:|&j;n|&}d tjds"z!process_batch..Prompt zNegative promptSeedz CFG scaleSamplerStepsz Model hash save_to_dirszAdd number suffixsave_images_replace_actionz-[generation_number]samples_filename_patternT)>strip processingfix_seedlistshared walk_files listfilesboolprintlenn_iter batch_sizer job_countpromptnegative_promptseed cfg_scale sampler_namestepsoverride_settingsrget enumeratejobskipped interruptedstopping_generationr readrrexif_transposeintwidthheight init_imagesrglobstem image_maskospathjoinbasenameread_info_from_imager items Exceptionfloatnamepopoutpath_samplesmodulesscriptsscripts_img2imgrunrextend infotextsr img2img_batch_show_results_limit)'p input_dir output_dirZinpaint_mask_dirargsto_scalescale_by use_png_infor png_info_dir batch_imagesZis_inpaint_batchZ inpaint_masksr5r6r7r8r9r:r;Zsd_model_checkpoint_overrideZ batch_resultsZdiscard_further_resultsiimageimge image_pathZmask_image_pathZmask_image_dirZ masks_foundZ mask_imageZinfo_imgZ info_img_pathgeninfo_Zparsed_parameters model_infoprocrrr process_batchs  " [               &roid_taskrequestmoder5r6 mask_blur mask_alphainpainting_fillr2r3r8image_cfg_scaledenoising_strengthselected_scale_tabrFrErb resize_modeinpaint_full_resinpaint_full_res_paddinginpainting_mask_invertimg2img_batch_input_dirimg2img_batch_output_dirimg2img_batch_inpaint_mask_dirimg2img_batch_use_png_infoimg2img_batch_png_info_propsimg2img_batch_png_info_dirc$/ Gs4t| }%|dk}&|dkr|}'d}(nm|dkr|}'d}(nd|dkr-|d|d}'}(t|(}(nQ|dkrq| }'| p6| })tjt|'t|)kdd }*t|*tj d d }(t |( d|d }(t | }+t|'|+|)|(|+}'n |d krz| }'| }(nd}'d}(t|'}'t|(}(|dkr|&s|'sJdt|'j|}t|'j|}d|krdksJdJdtd.idtjdtjptjdtjptjd|d|d|d|d|d|d|d|d|'gd|(d| d|d |d!|d"|d#|d$|d%|d&|%},tjj |,_|$|,_!|j"|,_#tjj$r t%d'|tj&d(t'|,F|&rOtj(j)r1Jd)t*|,||||$|dk||!|"|#d* }-|-durNt+|,g|,j,d+}-ntjj j-|,g|$R}-|-durct.|,}-Wdn 1snwYtj/0|-1}.tj2rt%|.tj3rg|-_|-j|.t4|-j5t4|-j6d,d-fS)/Nrrrgmask)axisLdz+Can't scale by because no image is selectedgrz)can only work with strength in [0.0, 1.0]sd_modelrU outpath_gridsr5r6stylesr3r2r8rErFrGrsruryrwrvrzr{r|r;z img2img: )filez:Launched with --hide-ui-dir-config, batch img2img disabled)rarbrcrrdr!comments) classnamer)7r r)create_binary_masknpanyarrayr fromarrayastypeuint8r Brightnessenhancer GaussianBlur compositefilterr fix_imagerDrErFr r,rroutdir_samplesoutdir_img2img_samples outdir_gridsoutdir_img2img_gridsrVrWrX script_argsusernameuserenable_console_promptsr0progress_print_outrcmd_optshide_ui_dir_configror r7rYr total_tqdmclearjssamples_log_stdoutdo_not_show_imagesrinfor)/rprqrrr5r6 prompt_stylesinit_imgsketchinit_img_with_maskinpaint_color_sketchinpaint_color_sketch_originit_img_inpaintinit_mask_inpaintrsrtrur2r3r8rvrwrxrFrErbryrzr{r|r}r~rZoverride_settings_textsrrrr`r;Zis_batchrgrorigpredblurr] processedZgeneration_info_jsrrrimg2imgs      $              r)FrFNN)*rK contextlibrpathlibrnumpyrPILrrrrrgradiogrrVr Zmodules.infotext_utilsr r modules.processingr r rmodules.sharedrrmodules.sd_modelsrr,r) modules.uirmodules.scriptsrostrRequestrDrRr/r+rrrrrs$        |