Spaces:
Running on Zero
Running on Zero
Update app.py
Browse files4 unmodified lines56789108 unmodified lines192021222324258 unmodified lines34353637383920 unmodified lines60616263646566676869707172737433 unmodified lines10810911011111211334 unmodified lines14814915015115215315415515615715815945 unmodified lines2052062072082092102112122132142152162172182192202212 unmodified lines22422522622722822930 unmodified lines26026126226326426514 unmodified lines28028128228328428510 unmodified lines29629729829930030135 unmodified lines33733833934034134210 unmodified lines35335435535635735835996 unmodified lines4564574584594604614 unmodified lines46646746846947047135 unmodified lines5075085095105115121 unmodified line51451551651751851952052121 unmodified lines54354454554654754854925 unmodified lines5755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106117 unmodified lines61962062162262362462550 unmodified lines67667767867968068117 unmodified lines69970070170270370470527 unmodified lines733734735736737738739740741742121 unmodified lines8648658668678688698708718728738748758768778788795 unmodified lines8858868878888898902 unmodified lines89389489589689789889990090190290390490525 unmodified lines93193293393493593693793893994094194294394494594694794894995095195295395495595695795895970 unmodified lines10301031103210331034103558 unmodified lines10941095109610971098109911001101110211031104110511061107110843 unmodified lines11521153115411551156115711581159116011611162116318 unmodified lines11821183118411851186118714 unmodified lines12021203120412051206120710 unmodified lines12181219122012211222122335 unmodified lines12591260126112621263126420 unmodified lines12851286128712884 unmodified linesSCHEDULE_TYPE_OPTIONS,SCHEDULE_PREDICTION_TYPE_OPTIONS,check_scheduler_compatibility,)from constants import (DIRECTORY_MODELS,8 unmodified linesDOWNLOAD_EMBEDS,CIVITAI_API_KEY,HF_TOKEN,PREPROCESSOR_CONTROLNET,TASK_STABLEPY,TASK_MODEL_LIST,UPSCALER_DICT_GUI,8 unmodified linesEXAMPLES_GUI_HELP,EXAMPLES_GUI,RESOURCES,)from stablepy.diffusers_vanilla.style_prompt_config import STYLE_NAMESimport torch20 unmodified lineshtml_template_message,escape_html,)from datetime import datetimeimport gradio as grimport loggingimport diffusersimport warningsfrom stablepy import logger# import urllib.parseImageFile.LOAD_TRUNCATED_IMAGES = True# os.environ["PYTORCH_NO_CUDA_MEMORY_CACHING"] = "1"print(os.getenv("SPACES_ZERO_GPU"))33 unmodified linesprint('\033[33m🏁 Download and listing of valid models completed.\033[0m')######################## GUI#######################34 unmodified lines] + [model_name]print(self.inventory)def load_new_model(self, model_name, vae_model, task, progress=gr.Progress(track_tqdm=True)):self.update_storage_models()# download link model > model_namevae_model = vae_model if vae_model != "None" else Nonemodel_type = get_model_type(model_name)dtype_model = torch.bfloat16 if model_type == "FLUX" else torch.float1645 unmodified linesvae_model=vae_model,type_model_precision=dtype_model,retain_task_model_in_cache=False,device="cpu",)else:if self.model.base_model_id != model_name:load_now_time = datetime.now()elapsed_time = max((load_now_time - self.last_load).total_seconds(), 0)if elapsed_time <= 8:print("Waiting for the previous model's time ops...")time.sleep(8-elapsed_time)self.model.device = torch.device("cpu")self.model.load_pipe(2 unmodified linesvae_model=vae_model,type_model_precision=dtype_model,retain_task_model_in_cache=False,)end_time = time.time()30 unmodified lineslora_scale4,lora5,lora_scale5,sampler,schedule_type,schedule_prediction_type,14 unmodified lineshigh_threshold,value_threshold,distance_threshold,controlnet_output_scaling_in_unet,controlnet_start_threshold,controlnet_stop_threshold,10 unmodified lineshires_negative_prompt,hires_before_adetailer,hires_after_adetailer,loop_generation,leave_progress_bar,disable_progress_bar,35 unmodified linesmask_blur_b,mask_padding_b,retain_task_cache_gui,image_ip1,mask_ip1,model_ip1,10 unmodified linesyield info_state, gr.update(), gr.update()vae_model = vae_model if vae_model != "None" else Noneloras_list = [lora1, lora2, lora3, lora4, lora5]vae_msg = f"VAE: {vae_model}" if vae_model else ""msg_lora = ""96 unmodified lines"high_threshold": high_threshold,"value_threshold": value_threshold,"distance_threshold": distance_threshold,"lora_A": lora1 if lora1 != "None" else None,"lora_scale_A": lora_scale1,"lora_B": lora2 if lora2 != "None" else None,4 unmodified lines"lora_scale_D": lora_scale4,"lora_E": lora5 if lora5 != "None" else None,"lora_scale_E": lora_scale5,"textual_inversion": embed_list if textual_inversion else [],"syntax_weights": syntax_weights, # "Classic""sampler": sampler,35 unmodified lines"hires_sampler": hires_sampler,"hires_before_adetailer": hires_before_adetailer,"hires_after_adetailer": hires_after_adetailer,"ip_adapter_image": params_ip_img,"ip_adapter_mask": params_ip_msk,"ip_adapter_model": params_ip_model,1 unmodified line"ip_adapter_scale": params_ip_scale,}self.model.device = torch.device("cuda:0")if hasattr(self.model.pipe, "transformer") and loras_list != ["None"] * 5:self.model.pipe.transformer.to(self.model.device)print("transformer to cuda")21 unmodified linesif msg_lora:info_images += msg_lorainfo_images = info_images + "<br>" + "GENERATION DATA:<br>" + escape_html(metadata[0]) + "<br>-------<br>"download_links = "<br>".join([25 unmodified linesdef sd_gen_generate_pipeline(*args):gpu_duration_arg = int(args[-1]) if args[-1] else 59verbose_arg = int(args[-2])load_lora_cpu = args[-3]generation_args = args[:-3]lora_list = [None if item == "None" else itemfor item in [args[7], args[9], args[11], args[13], args[15]]]lora_status = [None] * 5msg_load_lora = "Updating LoRAs in GPU..."if load_lora_cpu:msg_load_lora = "Updating LoRAs in CPU (Slow but saves GPU usage)..."if lora_list != sd_gen.model.lora_memory and lora_list != [None] * 5:yield msg_load_lora, gr.update(), gr.update()# Load lora in CPUif load_lora_cpu:lora_status = sd_gen.model.lora_merge(lora_A=lora_list[0], lora_scale_A=args[8],lora_B=lora_list[1], lora_scale_B=args[10],lora_C=lora_list[2], lora_scale_C=args[12],lora_D=lora_list[3], lora_scale_D=args[14],lora_E=lora_list[4], lora_scale_E=args[16],)print(lora_status)sampler_name = args[17]schedule_type_name = args[18]_, _, msg_sampler = check_scheduler_compatibility(sd_gen.model.class_name, sampler_name, schedule_type_name)7 unmodified lineselif status is not None:gr.Warning(f"Failed to load LoRA: {lora}")if lora_status == [None] * 5 and sd_gen.model.lora_memory != [None] * 5 and load_lora_cpu:lora_cache_msg = ", ".join(str(x) for x in sd_gen.model.lora_memory if x is not None)50 unmodified linesreturn image_pathdynamic_gpu_duration.zerogpu = Truesd_gen_generate_pipeline.zerogpu = Truesd_gen = GuiSD()17 unmodified linestask_gui = gr.Dropdown(label="Task", choices=SDXL_TASK, value=TASK_MODEL_LIST[0])model_name_gui = gr.Dropdown(label="Model", choices=model_list, value=model_list[0], allow_custom_value=True)prompt_gui = gr.Textbox(lines=5, placeholder="Enter prompt", label="Prompt")neg_prompt_gui = gr.Textbox(lines=3, placeholder="Enter Neg prompt", label="Negative prompt")with gr.Row(equal_height=False):set_params_gui = gr.Button(value="↙️", variant="secondary", size="sm")clear_prompt_gui = gr.Button(value="🗑️", variant="secondary", size="sm")27 unmodified linesgpu_duration_gui = gr.Number(minimum=5, maximum=240, value=59, show_label=False, container=False, info="GPU time duration (seconds)")with gr.Column():verbose_info_gui = gr.Checkbox(value=False, container=False, label="Status info")load_lora_cpu_gui = gr.Checkbox(value=False, container=False, label="Load LoRAs on CPU (Save GPU time)")with gr.Column(scale=1):steps_gui = gr.Slider(minimum=1, maximum=100, step=1, value=30, label="Steps")cfg_gui = gr.Slider(minimum=0, maximum=30, step=0.5, value=7., label="CFG")sampler_gui = gr.Dropdown(label="Sampler", choices=scheduler_names, value="Euler")schedule_type_gui = gr.Dropdown(label="Schedule type", choices=SCHEDULE_TYPE_OPTIONS, value=SCHEDULE_TYPE_OPTIONS[0])121 unmodified lineshires_steps_gui = gr.Slider(minimum=0, value=30, maximum=100, step=1, label="Hires Steps")hires_denoising_strength_gui = gr.Slider(minimum=0.1, maximum=1.0, step=0.01, value=0.55, label="Hires Denoising Strength")hires_sampler_gui = gr.Dropdown(label="Hires Sampler", choices=POST_PROCESSING_SAMPLER, value=POST_PROCESSING_SAMPLER[0])hires_prompt_gui = gr.Textbox(label="Hires Prompt", placeholder="Main prompt will be use", lines=3)hires_negative_prompt_gui = gr.Textbox(label="Hires Negative Prompt", placeholder="Main negative prompt will be use", lines=3)with gr.Accordion("LoRA", open=False, visible=True):def lora_dropdown(label):return gr.Dropdown(label=label, choices=lora_model_list, value="None", allow_custom_value=True)def lora_scale_slider(label):return gr.Slider(minimum=-2, maximum=2, step=0.01, value=0.33, label=label)lora1_gui = lora_dropdown("Lora1")lora_scale_1_gui = lora_scale_slider("Lora Scale 1")5 unmodified lineslora_scale_4_gui = lora_scale_slider("Lora Scale 4")lora5_gui = lora_dropdown("Lora5")lora_scale_5_gui = lora_scale_slider("Lora Scale 5")with gr.Accordion("From URL", open=False, visible=True):text_lora = gr.Textbox(2 unmodified lineslines=1,info="It has to be .safetensors files, and you can also download them from Hugging Face.",)romanize_text = gr.Checkbox(value=False, label="Transliterate name")button_lora = gr.Button("Get and Refresh the LoRA Lists")new_lora_status = gr.HTML()button_lora.click(get_my_lora,[text_lora, romanize_text],[lora1_gui, lora2_gui, lora3_gui, lora4_gui, lora5_gui, new_lora_status])with gr.Accordion("IP-Adapter", open=False, visible=True):25 unmodified linesminimum=64, maximum=2048, step=64, value=1024, label="Image Resolution",info="The maximum proportional size of the generated image based on the uploaded image.")preprocessor_name_gui = gr.Dropdown(label="Preprocessor Name", choices=PREPROCESSOR_CONTROLNET["canny"])def change_preprocessor_choices(task):task = TASK_STABLEPY[task]if task in PREPROCESSOR_CONTROLNET.keys():choices_task = PREPROCESSOR_CONTROLNET[task]else:choices_task = PREPROCESSOR_CONTROLNET["canny"]return gr.update(choices=choices_task, value=choices_task[0])task_gui.change(change_preprocessor_choices,[task_gui],[preprocessor_name_gui],)preprocess_resolution_gui = gr.Slider(minimum=64, maximum=2048, step=64, value=512, label="Preprocess Resolution")low_threshold_gui = gr.Slider(minimum=1, maximum=255, step=1, value=100, label="Canny low threshold")high_threshold_gui = gr.Slider(minimum=1, maximum=255, step=1, value=200, label="Canny high threshold")value_threshold_gui = gr.Slider(minimum=1, maximum=2.0, step=0.01, value=0.1, label="Hough value threshold (MLSD)")distance_threshold_gui = gr.Slider(minimum=1, maximum=20.0, step=0.01, value=0.1, label="Hough distance threshold (MLSD)")control_net_output_scaling_gui = gr.Slider(minimum=0, maximum=5.0, step=0.1, value=1, label="ControlNet Output Scaling in UNet")control_net_start_threshold_gui = gr.Slider(minimum=0, maximum=1, step=0.01, value=0, label="ControlNet Start Threshold (%)")control_net_stop_threshold_gui = gr.Slider(minimum=0, maximum=1, step=0.01, value=1, label="ControlNet Stop Threshold (%)")with gr.Accordion("T2I adapter", open=False, visible=False):t2i_adapter_preprocessor_gui = gr.Checkbox(value=True, label="T2i Adapter Preprocessor")70 unmodified lineswith gr.Accordion("Other settings", open=False, visible=True):schedule_prediction_type_gui = gr.Dropdown(label="Discrete Sampling Type", choices=SCHEDULE_PREDICTION_TYPE_OPTIONS, value=SCHEDULE_PREDICTION_TYPE_OPTIONS[0])save_generated_images_gui = gr.Checkbox(value=True, label="Create a download link for the images")filename_pattern_gui = gr.Textbox(label="Filename pattern", value="model,seed", placeholder="model,seed,sampler,schedule_type,img_width,img_height,guidance_scale,num_steps,vae,prompt_section,neg_prompt_section", lines=1)hires_before_adetailer_gui = gr.Checkbox(value=False, label="Hires Before Adetailer")58 unmodified lines# enable crop (or disable it)# transforms=["crop"],brush=gr.Brush(default_size="16", # or leave it as 'auto'color_mode="fixed", # 'fixed' hides the user swatches and colorpicker, 'defaults' shows it# default_color="black", # html names are supportedcolors=["rgba(0, 0, 0, 1)", # rgb(a)"rgba(0, 0, 0, 0.1)","rgba(255, 255, 255, 0.1)",# "hsl(360, 120, 120)" # in fact any valid colorstring]),eraser=gr.Eraser(default_size="16"))43 unmodified linesoutputs=[result_up_tab],)generate_button.click(fn=sd_gen.load_new_model,inputs=[model_name_gui,vae_model_gui,task_gui],outputs=[load_model_gui],queue=True,18 unmodified lineslora_scale_4_gui,lora5_gui,lora_scale_5_gui,sampler_gui,schedule_type_gui,schedule_prediction_type_gui,14 unmodified lineshigh_threshold_gui,value_threshold_gui,distance_threshold_gui,control_net_output_scaling_gui,control_net_start_threshold_gui,control_net_stop_threshold_gui,10 unmodified lineshires_negative_prompt_gui,hires_before_adetailer_gui,hires_after_adetailer_gui,loop_generation_gui,leave_progress_bar_gui,disable_progress_bar_gui,35 unmodified linesmask_blur_b_gui,mask_padding_b_gui,retain_task_cache_gui,image_ip1,mask_ip1,model_ip1,20 unmodified linesshow_error=True,debug=True,allowed_paths=["./images/"],)4 unmodified lines5678910118 unmodified lines2021222324258 unmodified lines3435363738394020 unmodified lines61626364656667686970717273747576777833 unmodified lines11211311411511611711811912012112212312412512612734 unmodified lines16216316416516616716816917017117217345 unmodified lines2192202212222232242252262272282292302312322332342352362372 unmodified lines24024124224324424524630 unmodified lines27727827928028128228328428528614 unmodified lines30130230330430530630730810 unmodified lines31932032132232332432532632735 unmodified lines36336436536636736836910 unmodified lines38038138238338438538696 unmodified lines4834844854864874884894904 unmodified lines49549649749849950050150250350435 unmodified lines5405415425435445455465471 unmodified line54955055155255355455555655755855956021 unmodified lines58258358458558658758825 unmodified lines6146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506517 unmodified lines65966066166266366466550 unmodified lines71671771871972072172217 unmodified lines74074174274374474574627 unmodified lines774775776777778779780781782783121 unmodified lines9059069079089099109119129139149159169179189199209219229235 unmodified lines9299309319329339349359369379382 unmodified lines94194294394494594694794894995095195295325 unmodified lines9799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101070 unmodified lines108110821083108410851086108758 unmodified lines11461147114811491150115111521153115411551156115711581159116043 unmodified lines120412051206120712081209121012111212121312141215121612171218121918 unmodified lines123812391240124112421243124412451246124714 unmodified lines1262126312641265126612671268126910 unmodified lines12801281128212831284128512861287128835 unmodified lines132413251326132713281329133020 unmodified lines13511352135313544 unmodified linesSCHEDULE_TYPE_OPTIONS,SCHEDULE_PREDICTION_TYPE_OPTIONS,check_scheduler_compatibility,TASK_AND_PREPROCESSORS,)from constants import (DIRECTORY_MODELS,8 unmodified linesDOWNLOAD_EMBEDS,CIVITAI_API_KEY,HF_TOKEN,TASK_STABLEPY,TASK_MODEL_LIST,UPSCALER_DICT_GUI,8 unmodified linesEXAMPLES_GUI_HELP,EXAMPLES_GUI,RESOURCES,DIFFUSERS_CONTROLNET_MODEL,)from stablepy.diffusers_vanilla.style_prompt_config import STYLE_NAMESimport torch20 unmodified lineshtml_template_message,escape_html,)from image_processor import preprocessor_tabfrom datetime import datetimeimport gradio as grimport loggingimport diffusersimport warningsfrom stablepy import loggerfrom diffusers import FluxPipeline# import urllib.parseImageFile.LOAD_TRUNCATED_IMAGES = Truetorch.backends.cuda.matmul.allow_tf32 = True# os.environ["PYTORCH_NO_CUDA_MEMORY_CACHING"] = "1"print(os.getenv("SPACES_ZERO_GPU"))33 unmodified linesprint('\033[33m🏁 Download and listing of valid models completed.\033[0m')flux_repo = "camenduru/FLUX.1-dev-diffusers"flux_pipe = FluxPipeline.from_pretrained(flux_repo,transformer=None,torch_dtype=torch.bfloat16,).to("cuda")components = flux_pipe.componentscomponents.pop("transformer", None)delete_model(flux_repo)######################## GUI#######################34 unmodified lines] + [model_name]print(self.inventory)def load_new_model(self, model_name, vae_model, task, controlnet_model, progress=gr.Progress(track_tqdm=True)):# download link model > model_nameself.update_storage_models()vae_model = vae_model if vae_model != "None" else Nonemodel_type = get_model_type(model_name)dtype_model = torch.bfloat16 if model_type == "FLUX" else torch.float1645 unmodified linesvae_model=vae_model,type_model_precision=dtype_model,retain_task_model_in_cache=False,controlnet_model=controlnet_model,device="cpu",env_components=components,)self.model.advanced_params(image_preprocessor_cuda_active=True)else:if self.model.base_model_id != model_name:load_now_time = datetime.now()elapsed_time = max((load_now_time - self.last_load).total_seconds(), 0)if elapsed_time <= 9:print("Waiting for the previous model's time ops...")time.sleep(9 - elapsed_time)self.model.device = torch.device("cpu")self.model.load_pipe(2 unmodified linesvae_model=vae_model,type_model_precision=dtype_model,retain_task_model_in_cache=False,controlnet_model=controlnet_model,)end_time = time.time()30 unmodified lineslora_scale4,lora5,lora_scale5,lora6,lora_scale6,lora7,lora_scale7,sampler,schedule_type,schedule_prediction_type,14 unmodified lineshigh_threshold,value_threshold,distance_threshold,recolor_gamma_correction,tile_blur_sigma,controlnet_output_scaling_in_unet,controlnet_start_threshold,controlnet_stop_threshold,10 unmodified lineshires_negative_prompt,hires_before_adetailer,hires_after_adetailer,hires_schedule_type,hires_guidance_scale,controlnet_model,loop_generation,leave_progress_bar,disable_progress_bar,35 unmodified linesmask_blur_b,mask_padding_b,retain_task_cache_gui,guidance_rescale,image_ip1,mask_ip1,model_ip1,10 unmodified linesyield info_state, gr.update(), gr.update()vae_model = vae_model if vae_model != "None" else Noneloras_list = [lora1, lora2, lora3, lora4, lora5, lora6, lora7]vae_msg = f"VAE: {vae_model}" if vae_model else ""msg_lora = ""96 unmodified lines"high_threshold": high_threshold,"value_threshold": value_threshold,"distance_threshold": distance_threshold,"recolor_gamma_correction": float(recolor_gamma_correction),"tile_blur_sigma": int(tile_blur_sigma),"lora_A": lora1 if lora1 != "None" else None,"lora_scale_A": lora_scale1,"lora_B": lora2 if lora2 != "None" else None,4 unmodified lines"lora_scale_D": lora_scale4,"lora_E": lora5 if lora5 != "None" else None,"lora_scale_E": lora_scale5,"lora_F": lora6 if lora6 != "None" else None,"lora_scale_F": lora_scale6,"lora_G": lora7 if lora7 != "None" else None,"lora_scale_G": lora_scale7,"textual_inversion": embed_list if textual_inversion else [],"syntax_weights": syntax_weights, # "Classic""sampler": sampler,35 unmodified lines"hires_sampler": hires_sampler,"hires_before_adetailer": hires_before_adetailer,"hires_after_adetailer": hires_after_adetailer,"hires_schedule_type": hires_schedule_type,"hires_guidance_scale": hires_guidance_scale,"ip_adapter_image": params_ip_img,"ip_adapter_mask": params_ip_msk,"ip_adapter_model": params_ip_model,1 unmodified line"ip_adapter_scale": params_ip_scale,}# kwargs for diffusers pipelineif guidance_rescale:pipe_params["guidance_rescale"] = guidance_rescaleself.model.device = torch.device("cuda:0")if hasattr(self.model.pipe, "transformer") and loras_list != ["None"] * self.model.num_loras:self.model.pipe.transformer.to(self.model.device)print("transformer to cuda")21 unmodified linesif msg_lora:info_images += msg_lorainfo_images = info_images + "<br>" + "GENERATION DATA:<br>" + escape_html(metadata[-1]) + "<br>-------<br>"download_links = "<br>".join([25 unmodified linesdef sd_gen_generate_pipeline(*args):gpu_duration_arg = int(args[-1]) if args[-1] else 59verbose_arg = int(args[-2])load_lora_cpu = args[-3]generation_args = args[:-3]lora_list = [None if item == "None" else itemfor item in [args[7], args[9], args[11], args[13], args[15], args[17], args[19]]]lora_status = [None] * sd_gen.model.num_lorasmsg_load_lora = "Updating LoRAs in GPU..."if load_lora_cpu:msg_load_lora = "Updating LoRAs in CPU..."if lora_list != sd_gen.model.lora_memory and lora_list != [None] * sd_gen.model.num_loras:yield msg_load_lora, gr.update(), gr.update()# Load lora in CPUif load_lora_cpu:lora_status = sd_gen.model.load_lora_on_the_fly(lora_A=lora_list[0], lora_scale_A=args[8],lora_B=lora_list[1], lora_scale_B=args[10],lora_C=lora_list[2], lora_scale_C=args[12],lora_D=lora_list[3], lora_scale_D=args[14],lora_E=lora_list[4], lora_scale_E=args[16],lora_F=lora_list[5], lora_scale_F=args[18],lora_G=lora_list[6], lora_scale_G=args[20],)print(lora_status)sampler_name = args[21]schedule_type_name = args[22]_, _, msg_sampler = check_scheduler_compatibility(sd_gen.model.class_name, sampler_name, schedule_type_name)7 unmodified lineselif status is not None:gr.Warning(f"Failed to load LoRA: {lora}")if lora_status == [None] * sd_gen.model.num_loras and sd_gen.model.lora_memory != [None] * sd_gen.model.num_loras and load_lora_cpu:lora_cache_msg = ", ".join(str(x) for x in sd_gen.model.lora_memory if x is not None)50 unmodified linesreturn image_path# https://huggingface.co/spaces/BestWishYsh/ConsisID-preview-Space/discussions/1#674969a022b99c122af5d407dynamic_gpu_duration.zerogpu = Truesd_gen_generate_pipeline.zerogpu = Truesd_gen = GuiSD()17 unmodified linestask_gui = gr.Dropdown(label="Task", choices=SDXL_TASK, value=TASK_MODEL_LIST[0])model_name_gui = gr.Dropdown(label="Model", choices=model_list, value=model_list[0], allow_custom_value=True)prompt_gui = gr.Textbox(lines=5, placeholder="Enter prompt", label="Prompt")neg_prompt_gui = gr.Textbox(lines=3, placeholder="Enter Neg prompt", label="Negative prompt", value="lowres, bad anatomy, bad hands, missing fingers, extra digit, fewer digits, worst quality, low quality, very displeasing, (bad)")with gr.Row(equal_height=False):set_params_gui = gr.Button(value="↙️", variant="secondary", size="sm")clear_prompt_gui = gr.Button(value="🗑️", variant="secondary", size="sm")27 unmodified linesgpu_duration_gui = gr.Number(minimum=5, maximum=240, value=59, show_label=False, container=False, info="GPU time duration (seconds)")with gr.Column():verbose_info_gui = gr.Checkbox(value=False, container=False, label="Status info")load_lora_cpu_gui = gr.Checkbox(value=False, container=False, label="Load LoRAs on CPU")with gr.Column(scale=1):steps_gui = gr.Slider(minimum=1, maximum=100, step=1, value=28, label="Steps")cfg_gui = gr.Slider(minimum=0, maximum=30, step=0.5, value=7., label="CFG")sampler_gui = gr.Dropdown(label="Sampler", choices=scheduler_names, value="Euler")schedule_type_gui = gr.Dropdown(label="Schedule type", choices=SCHEDULE_TYPE_OPTIONS, value=SCHEDULE_TYPE_OPTIONS[0])121 unmodified lineshires_steps_gui = gr.Slider(minimum=0, value=30, maximum=100, step=1, label="Hires Steps")hires_denoising_strength_gui = gr.Slider(minimum=0.1, maximum=1.0, step=0.01, value=0.55, label="Hires Denoising Strength")hires_sampler_gui = gr.Dropdown(label="Hires Sampler", choices=POST_PROCESSING_SAMPLER, value=POST_PROCESSING_SAMPLER[0])hires_schedule_list = ["Use same schedule type"] + SCHEDULE_TYPE_OPTIONShires_schedule_type_gui = gr.Dropdown(label="Hires Schedule type", choices=hires_schedule_list, value=hires_schedule_list[0])hires_guidance_scale_gui = gr.Slider(minimum=-1., maximum=30., step=0.5, value=-1., label="Hires CFG", info="If the value is -1, the main CFG will be used")hires_prompt_gui = gr.Textbox(label="Hires Prompt", placeholder="Main prompt will be use", lines=3)hires_negative_prompt_gui = gr.Textbox(label="Hires Negative Prompt", placeholder="Main negative prompt will be use", lines=3)with gr.Accordion("LoRA", open=False, visible=True):def lora_dropdown(label, visible=True):return gr.Dropdown(label=label, choices=lora_model_list, value="None", allow_custom_value=True, visible=visible)def lora_scale_slider(label, visible=True):return gr.Slider(minimum=-2, maximum=2, step=0.01, value=0.33, label=label, visible=visible)lora1_gui = lora_dropdown("Lora1")lora_scale_1_gui = lora_scale_slider("Lora Scale 1")5 unmodified lineslora_scale_4_gui = lora_scale_slider("Lora Scale 4")lora5_gui = lora_dropdown("Lora5")lora_scale_5_gui = lora_scale_slider("Lora Scale 5")lora6_gui = lora_dropdown("Lora6", visible=False)lora_scale_6_gui = lora_scale_slider("Lora Scale 6", visible=False)lora7_gui = lora_dropdown("Lora7", visible=False)lora_scale_7_gui = lora_scale_slider("Lora Scale 7", visible=False)with gr.Accordion("From URL", open=False, visible=True):text_lora = gr.Textbox(2 unmodified lineslines=1,info="It has to be .safetensors files, and you can also download them from Hugging Face.",)romanize_text = gr.Checkbox(value=False, label="Transliterate name", visible=False)button_lora = gr.Button("Get and Refresh the LoRA Lists")new_lora_status = gr.HTML()button_lora.click(get_my_lora,[text_lora, romanize_text],[lora1_gui, lora2_gui, lora3_gui, lora4_gui, lora5_gui, lora6_gui, lora7_gui, new_lora_status])with gr.Accordion("IP-Adapter", open=False, visible=True):25 unmodified linesminimum=64, maximum=2048, step=64, value=1024, label="Image Resolution",info="The maximum proportional size of the generated image based on the uploaded image.")controlnet_model_gui = gr.Dropdown(label="ControlNet model", choices=DIFFUSERS_CONTROLNET_MODEL, value=DIFFUSERS_CONTROLNET_MODEL[0])control_net_output_scaling_gui = gr.Slider(minimum=0, maximum=5.0, step=0.1, value=1, label="ControlNet Output Scaling in UNet")control_net_start_threshold_gui = gr.Slider(minimum=0, maximum=1, step=0.01, value=0, label="ControlNet Start Threshold (%)")control_net_stop_threshold_gui = gr.Slider(minimum=0, maximum=1, step=0.01, value=1, label="ControlNet Stop Threshold (%)")preprocessor_name_gui = gr.Dropdown(label="Preprocessor Name", choices=TASK_AND_PREPROCESSORS["canny"])def change_preprocessor_choices(task):task = TASK_STABLEPY[task]if task in TASK_AND_PREPROCESSORS.keys():choices_task = TASK_AND_PREPROCESSORS[task]else:choices_task = TASK_AND_PREPROCESSORS["canny"]return gr.update(choices=choices_task, value=choices_task[0])task_gui.change(change_preprocessor_choices,[task_gui],[preprocessor_name_gui],)preprocess_resolution_gui = gr.Slider(minimum=64, maximum=2048, step=64, value=512, label="Preprocessor Resolution")low_threshold_gui = gr.Slider(minimum=1, maximum=255, step=1, value=100, label="'CANNY' low threshold")high_threshold_gui = gr.Slider(minimum=1, maximum=255, step=1, value=200, label="'CANNY' high threshold")value_threshold_gui = gr.Slider(minimum=1, maximum=2.0, step=0.01, value=0.1, label="'MLSD' Hough value threshold")distance_threshold_gui = gr.Slider(minimum=1, maximum=20.0, step=0.01, value=0.1, label="'MLSD' Hough distance threshold")recolor_gamma_correction_gui = gr.Number(minimum=0., maximum=25., value=1., step=0.001, label="'RECOLOR' gamma correction")tile_blur_sigma_gui = gr.Number(minimum=0, maximum=100, value=9, step=1, label="'TILE' blur sigma")with gr.Accordion("T2I adapter", open=False, visible=False):t2i_adapter_preprocessor_gui = gr.Checkbox(value=True, label="T2i Adapter Preprocessor")70 unmodified lineswith gr.Accordion("Other settings", open=False, visible=True):schedule_prediction_type_gui = gr.Dropdown(label="Discrete Sampling Type", choices=SCHEDULE_PREDICTION_TYPE_OPTIONS, value=SCHEDULE_PREDICTION_TYPE_OPTIONS[0])guidance_rescale_gui = gr.Number(label="CFG rescale:", value=0., step=0.01, minimum=0., maximum=1.5)save_generated_images_gui = gr.Checkbox(value=True, label="Create a download link for the images")filename_pattern_gui = gr.Textbox(label="Filename pattern", value="model,seed", placeholder="model,seed,sampler,schedule_type,img_width,img_height,guidance_scale,num_steps,vae,prompt_section,neg_prompt_section", lines=1)hires_before_adetailer_gui = gr.Checkbox(value=False, label="Hires Before Adetailer")58 unmodified lines# enable crop (or disable it)# transforms=["crop"],brush=gr.Brush(default_size="16", # or leave it as 'auto'color_mode="fixed", # 'fixed' hides the user swatches and colorpicker, 'defaults' shows it# default_color="black", # html names are supportedcolors=["rgba(0, 0, 0, 1)", # rgb(a)"rgba(0, 0, 0, 0.1)","rgba(255, 255, 255, 0.1)",# "hsl(360, 120, 120)" # in fact any valid colorstring]),eraser=gr.Eraser(default_size="16"))43 unmodified linesoutputs=[result_up_tab],)with gr.Tab("Preprocessor", render=True):preprocessor_tab()generate_button.click(fn=sd_gen.load_new_model,inputs=[model_name_gui,vae_model_gui,task_gui,controlnet_model_gui,],outputs=[load_model_gui],queue=True,18 unmodified lineslora_scale_4_gui,lora5_gui,lora_scale_5_gui,lora6_gui,lora_scale_6_gui,lora7_gui,lora_scale_7_gui,sampler_gui,schedule_type_gui,schedule_prediction_type_gui,14 unmodified lineshigh_threshold_gui,value_threshold_gui,distance_threshold_gui,recolor_gamma_correction_gui,tile_blur_sigma_gui,control_net_output_scaling_gui,control_net_start_threshold_gui,control_net_stop_threshold_gui,10 unmodified lineshires_negative_prompt_gui,hires_before_adetailer_gui,hires_after_adetailer_gui,hires_schedule_type_gui,hires_guidance_scale_gui,controlnet_model_gui,loop_generation_gui,leave_progress_bar_gui,disable_progress_bar_gui,35 unmodified linesmask_blur_b_gui,mask_padding_b_gui,retain_task_cache_gui,guidance_rescale_gui,image_ip1,mask_ip1,model_ip1,20 unmodified linesshow_error=True,debug=True,allowed_paths=["./images/"],)
app.py+118-52