import json,os from modules.paths_internal import data_path PNGINFO_2_LIGHTDIFFUSIONFLOW = {} PNGINFO_CN_2_LIGHTDIFFUSIONFLOW = {} Image_Components_Key = {} LoRAs_In_Use = "loras_in_use" Flow_Save_mode = "All" Auto_Fix_Params = True Local_Flows_Path = "models/LightDiffusionFlow" class OutputPrompt_English: def startimport(): return "
- "+ext+"
" error_str+="You can switch to 'ALL' mode to load more parameters. (This prompt is for reference only, please choose the plugin mode according to the actual situation.) " else: error_str = "Note: Found missing extensions." for ext in ext_list: error_str+="- "+ext+"
" error_str+="The above Extension Missing Reminder is for reference only. Please determine the necessary plugins based on your actual needs and specific conditions. " return error_str def missing_loras(loras_list:[]): error_str = "Note: Found missing LoRAs." for lora in loras_list: error_str+="- "+lora+"
" return error_str def click_to_download(file_name, file_url): return f'''Click to download \ {file_name} ''' def download_link(file_name, file_url): return f''' {file_name} ''' def note_for_save_mode(): return "Core mode only supports basic parameters for Text-to-Image and Image-to-Image, along with ControlNet parameters. \ The All mode, on the other hand, aims to support as many parameters as possible on the page, \ but the downside is that it may occasionally cause the UI to freeze with an infinite loading circle." class OutputPrompt_Chinese: def startimport(): return "
- "+ext+"
" error_str+="可切换至'ALL'模式加载更多参数。(提示仅供参考,请根据实际情况选择插件模式。) " else: error_str = "注意, 发现缺失的插件:" for ext in ext_list: error_str+="- "+ext+"
" error_str+="以上插件缺失提示仅供参考,请注意辨别实际情况下您所需要安装的插件。 " return error_str def missing_loras(loras_list:[]): error_str = "注意, 发现缺失的LoRA模型:" for lora in loras_list: error_str+="- "+lora+"
" return error_str def click_to_download(file_name, file_url): name = file_name if(name == "ControlNet Models"): name = "常用ControlNet模型" return f'''点击下载 \ 常用ControlNet模型 ''' return f'''
点击下载 \ {name} ''' def download_link(file_name, file_url): return f''' {file_name} ''' def note_for_save_mode(): return "Core模式仅支持文生图和图生图的基本参数+ControlNet参数。All模式则会尽可能多的支持页面上的参数,但是缺点是有概率导致UI卡住,无限转圈。" OutputPrompt = OutputPrompt_English def create_local_flow_path(): global Local_Flows_Path if os.path.isabs(Local_Flows_Path): flows_path = Local_Flows_Path else: flows_path = os.path.join(data_path, Local_Flows_Path) flows_path = flows_path.replace("\\","/") # linux下反斜杠有问题 #print(flows_path) try: if(not os.path.exists(flows_path)): os.makedirs(flows_path) if(os.path.exists(flows_path)): print(f"本地文件夹'{flows_path}'创建成功!") else: print(f"本地文件夹'{flows_path}'创建失败!") except BaseException as e: pass if(not os.path.exists(flows_path)): print(f"The creation of the folder '{Local_Flows_Path}' has failed! Please create this folder manually to ensure the proper functioning of the extension.") print(f"创建文件夹'{Local_Flows_Path}'失败!请手动创建该文件夹,以保证插件功能正常运行。") Local_Flows_Path = flows_path # 改成函数调用,修改配置之后能及时刷新 def init(): global PNGINFO_2_LIGHTDIFFUSIONFLOW,PNGINFO_CN_2_LIGHTDIFFUSIONFLOW global OutputPrompt,Flow_Save_mode,Auto_Fix_Params,Local_Flows_Path,Image_Components_Key # PNG Info的功能除了主要的选项以外其他的都靠第三方插件的主动支持,后续再考虑能否有优化的办法 #print(parameters_copypaste.paste_fields) PNGINFO_2_LIGHTDIFFUSIONFLOW = { "Prompt": "state-txt2img_prompt", "Negative prompt": "state-txt2img_neg_prompt", "Steps": "state-txt2img_steps", "Sampler": "state-txt2img_sampling", "CFG scale": "state-txt2img_cfg_scale", "Seed": "state-txt2img_seed", "Face restoration": "state-txt2img_restore_faces", "Size-1": "state-txt2img_width", "Size-2": "state-txt2img_height", "Model hash": "state-setting_sd_model_checkpoint", "Denoising strength": "state-txt2img_denoising_strength", "Hires upscale": "state-txt2img_hr_scale", "Hires steps": "state-txt2img_hires_steps", "Hires upscaler": "state-txt2img_hr_upscaler", "Hires resize-1": "state-txt2img_hr_resize_x", "Hires resize-2": "state-txt2img_hr_resize_y", "Clip skip": "setting_CLIP_stop_at_last_layers", "ENSD": "setting_eta_noise_seed_delta" } PNGINFO_CN_2_LIGHTDIFFUSIONFLOW = { "Module": "state-ext-control-net-txt2img_0-preprocessor", "preprocessor": "state-ext-control-net-txt2img_0-preprocessor", "model": "state-ext-control-net-txt2img_0-model", "weight": "state-ext-control-net-txt2img_0-control-weight", "starting": "state-ext-control-net-txt2img_0-starting-control-step", "ending": "state-ext-control-net-txt2img_0-guidance-end-(t)", "guidance start": "state-ext-control-net-txt2img_0-starting-control-step", "guidance end": "state-ext-control-net-txt2img_0-ending-control-step", "resize mode": "state-ext-control-net-txt2img_0-resize-mode", "pixel perfect": "state-ext-control-net-txt2img_0-pixel-perfect", "control mode": "state-ext-control-net-txt2img_0-control-mode", "preprocessor params": "" } try: import modules.shared as shared webui_settings = {} with open(shared.cmd_opts.ui_settings_file, mode='r') as f: json_str = f.read() webui_settings = json.loads(json_str) # 保存模式 try: Flow_Save_mode = webui_settings["lightdiffusionflow-mode"] except: pass # 自动纠正错误的参数 try: Auto_Fix_Params = webui_settings["lightdiffusionflow-auto-fix-params"] except: pass # 本地flow保存位置,先读本地设置,再读命令行设置 try: Local_Flows_Path = webui_settings["lightdiffusionflow-local-flows-path"] except: pass if shared.cmd_opts.local_flows_path: Local_Flows_Path = shared.cmd_opts.local_flows_path create_local_flow_path() language_successed = False auto_language = False try: # 优先读取自己的设置 if(webui_settings['lightdiffusionflow-language'] == "default"): auto_language = True elif(webui_settings['lightdiffusionflow-language'] == "english"): OutputPrompt = OutputPrompt_English language_successed = True else: OutputPrompt = OutputPrompt_Chinese language_successed = True except: OutputPrompt = OutputPrompt_English # 如果是default就读取其他设置配合 if(auto_language and not language_successed): # 自带的本地化文件 localization_files = ["zh_CN", "zh-Hans (Stable) [vladmandic]", "zh-Hans (Stable)", "zh-Hans (Testing) [vladmandic]", "zh-Hans (Testing)","chinese-all-1024","chinese-english-1024"] try: # 如果用户使用了中文汉化文件,插件也默认显示中文 localization_files.index(webui_settings["localization"]) OutputPrompt = OutputPrompt_Chinese language_successed = True except: pass # 第三方翻译插件bilingual-localization if(not language_successed): try: if(webui_settings["bilingual_localization_enabled"] and webui_settings["bilingual_localization_file"] != "None"): OutputPrompt = OutputPrompt_Chinese language_successed = True except: OutputPrompt = OutputPrompt_English except: pass Image_Components_Key = [ # 第一个组件是用来预计算第一张有效图的索引 防止出现有没用的页面跳转 "useless_Textbox", # 每个图片组件的elem_id "img2img_image","img2img_sketch","img2maskimg","inpaint_sketch","img_inpaint_base","img_inpaint_mask", ] # 只保存图片组件id,其他参数js里搞定 # # init number of controlnet # try: # webui_settings = {} # with open(shared.cmd_opts.ui_settings_file, mode='r') as f: # json_str = f.read() # webui_settings = json.loads(json_str) # Multi_ControlNet = webui_settings.get("control_net_unit_count", None) # controlnet数量,新版名字 # if(Multi_ControlNet == None): # Multi_ControlNet = webui_settings.get("control_net_max_models_num", 0) # print(f"Multi_ControlNet = {Multi_ControlNet}") # if(Multi_ControlNet == 1): # Image_Components_Key.append(f"txt2img_controlnet_ControlNet_input_image") # Image_Components_Key.append(f"img2img_controlnet_ControlNet_input_image") # else: # for i in range(Multi_ControlNet): # Image_Components_Key.append(f"txt2img_controlnet_ControlNet-{i}_input_image") # Image_Components_Key.append(f"img2img_controlnet_ControlNet-{i}_input_image") # except: # pass # # Segment Anything images # Image_Components_Key.extend(["txt2img_sam_input_image","img2img_sam_input_image"]) init()