Skip to content

Commit 1e9ac30

Browse files
author
legionfu
committed
设置页面增加保存flow的默认路径选项
1 parent 92b1f24 commit 1e9ac30

File tree

5 files changed

+71
-38
lines changed

5 files changed

+71
-38
lines changed

ChangeLog.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
* 增加本地保存Flow配置功能,可直接下拉列表选择已保存的Flow文件。(导入或使用新flow之前,建议先刷新页面,目前插件暂时没有重置参数的功能)
55
* 增加记录额外LoRA模型数据,以便导入时从Civitai搜索缺失的lora模型。
66
* 模型模糊匹配优化,增加匹配子文件夹下的模型。
7+
* 设置页面增加保存flow的默认路径选项,以及相同作用的命令行选项"--local-flows-path"。
78

89
### Bug Fixes:
910
* 修复了部分已知的参数设置失败的问题,如ControlNet在Canny模式下的"Canny Low/Hight Threshold"等参数。

preload.py

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
import argparse
2+
3+
def preload(parser: argparse.ArgumentParser):
4+
parser.add_argument("--local-flows-path", type=str, default="models/LightDiffusionFlow", help="Path to save flow files.")

scripts/lightdiffusionflow_config.py

Lines changed: 39 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,13 @@
1-
import json
1+
import json,os
2+
from modules.paths_internal import data_path
23

34
PNGINFO_2_LIGHTDIFFUSIONFLOW = {}
45
PNGINFO_CN_2_LIGHTDIFFUSIONFLOW = {}
56
Image_Components_Key = {}
67
LoRAs_In_Use = "loras_in_use"
78
Flow_Save_mode = "All"
89
Auto_Fix_Params = True
10+
Local_Flows_Path = "models/LightDiffusionFlow"
911

1012
class OutputPrompt_English:
1113

@@ -145,10 +147,35 @@ def note_for_save_mode():
145147

146148
OutputPrompt = OutputPrompt_English
147149

150+
def create_local_flow_path():
151+
global Local_Flows_Path
152+
153+
if os.path.isabs(Local_Flows_Path):
154+
flows_path = Local_Flows_Path
155+
else:
156+
flows_path = os.path.join(data_path, Local_Flows_Path)
157+
flows_path = flows_path.replace("\\","/") # linux下反斜杠有问题
158+
#print(flows_path)
159+
try:
160+
if(not os.path.exists(flows_path)):
161+
os.makedirs(flows_path)
162+
if(os.path.exists(flows_path)):
163+
print(f"本地文件夹'{flows_path}'创建成功!")
164+
else:
165+
print(f"本地文件夹'{flows_path}'创建失败!")
166+
except BaseException as e:
167+
pass
168+
if(not os.path.exists(flows_path)):
169+
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.")
170+
print(f"创建文件夹'{Local_Flows_Path}'失败!请手动创建该文件夹,以保证插件功能正常运行。")
171+
172+
Local_Flows_Path = flows_path
173+
174+
148175
# 改成函数调用,修改配置之后能及时刷新
149176
def init():
150177
global PNGINFO_2_LIGHTDIFFUSIONFLOW,PNGINFO_CN_2_LIGHTDIFFUSIONFLOW
151-
global OutputPrompt,Flow_Save_mode,Auto_Fix_Params,Image_Components_Key
178+
global OutputPrompt,Flow_Save_mode,Auto_Fix_Params,Local_Flows_Path,Image_Components_Key
152179
# PNG Info的功能除了主要的选项以外其他的都靠第三方插件的主动支持,后续再考虑能否有优化的办法
153180
#print(parameters_copypaste.paste_fields)
154181
PNGINFO_2_LIGHTDIFFUSIONFLOW = {
@@ -206,6 +233,16 @@ def init():
206233
except:
207234
pass
208235

236+
# 本地flow保存位置,先读本地设置,再读命令行设置
237+
try:
238+
Local_Flows_Path = webui_settings["lightdiffusionflow-local-flows-path"]
239+
except:
240+
pass
241+
if shared.cmd_opts.local_flows_path:
242+
Local_Flows_Path = shared.cmd_opts.local_flows_path
243+
create_local_flow_path()
244+
245+
209246
language_successed = False
210247
auto_language = False
211248
try:

scripts/state_api.py

Lines changed: 16 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,7 @@
3131
Auto_Fix_Params = lf_config.Auto_Fix_Params
3232
LoRAs_In_Use = lf_config.LoRAs_In_Use
3333
OutputPrompt = lf_config.OutputPrompt
34+
Local_Flows_Path = lf_config.Local_Flows_Path #"models/LightDiffusionFlow"
3435

3536
# current_path = os.path.abspath(os.path.dirname(__file__))
3637
# sys.path.append(os.path.join(current_path,"lib"))
@@ -50,25 +51,6 @@
5051
txt2img_script_container = None
5152
img2img_script_container = None
5253

53-
local_flows_path = "models/LightDiffusionFlow"
54-
if True:
55-
flows_path = os.path.join(data_path, local_flows_path)
56-
flows_path = flows_path.replace("\\","/") # linux下反斜杠有问题
57-
print(flows_path)
58-
try:
59-
if(not os.path.exists(flows_path)):
60-
os.makedirs(flows_path)
61-
if(os.path.exists(flows_path)):
62-
print(f"本地文件夹'{flows_path}'创建成功!")
63-
else:
64-
print(f"本地文件夹'{flows_path}'创建失败!")
65-
except BaseException as e:
66-
pass
67-
68-
if(not os.path.exists(flows_path)):
69-
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.")
70-
print(f"创建文件夹'{local_flows_path}'失败!请手动创建该文件夹,以保证插件功能正常运行。")
71-
7254
local_flow_list = []
7355
Need_Preload = False
7456
Preload_File = r""
@@ -211,11 +193,11 @@ def SearchingCheckPointByHashFromCivitai(hash:str):
211193

212194
def refresh_local_flows(*inputs):
213195
print("refresh_local_flows")
214-
global local_flow_list,local_flows_path
196+
global local_flow_list,Local_Flows_Path
215197
try:
216-
flows_path = os.path.join(data_path, local_flows_path)
217-
local_flow_list = [f for f in os.listdir(flows_path) if os.path.isfile(
218-
os.path.join(flows_path, f)) and os.path.splitext(f)[-1] == '.flow']
198+
#flows_path = os.path.join(data_path, Local_Flows_Path)
199+
local_flow_list = [f for f in os.listdir(Local_Flows_Path) if os.path.isfile(
200+
os.path.join(Local_Flows_Path, f)) and os.path.splitext(f)[-1] == '.flow']
219201
except:
220202
local_flow_list = []
221203
# print(inputs)
@@ -231,11 +213,11 @@ def refresh_local_flows(*inputs):
231213
return ret
232214

233215
def apply_local_flow(selected):
234-
global local_flow_list,local_flows_path
216+
global local_flow_list,Local_Flows_Path
235217
global Need_Preload,Preload_File
236218

237219
if(selected != "" and selected != None):
238-
flow_path = os.path.join(data_path, local_flows_path, selected)
220+
flow_path = os.path.join(Local_Flows_Path, selected)
239221
if(os.path.exists(flow_path)):
240222
print("OK,Local File!")
241223
print(flow_path)
@@ -244,9 +226,9 @@ def apply_local_flow(selected):
244226
gr.Info(clear_markup(OutputPrompt.startimport()))
245227

246228
def delete_local_flow(selected):
247-
global local_flow_list,local_flows_path
229+
global local_flow_list,Local_Flows_Path
248230
if(selected != "" and selected != None):
249-
flow_path = os.path.join(data_path, local_flows_path, selected)
231+
flow_path = os.path.join(Local_Flows_Path, selected)
250232
if(os.path.exists(flow_path)):
251233
os.remove(flow_path)
252234
print("Local File Deleted!")
@@ -1014,7 +996,7 @@ def read_file(self, params:file_params):
1014996
def file_exist(self, params:file_params):
1015997
print("file_exist")
1016998
if(not os.path.exists(params.file_path)):
1017-
flow_path = os.path.join(data_path, local_flows_path, params.file_path)
999+
flow_path = os.path.join(Local_Flows_Path, params.file_path)
10181000
if(os.path.exists(flow_path)):
10191001
return True
10201002
else:
@@ -1084,7 +1066,7 @@ def need_preload(self):
10841066
return ""
10851067

10861068
def saveFlowToLocal(self, data_to_save:savefile_params):
1087-
global local_flows_path
1069+
global Local_Flows_Path
10881070
global add_output_log
10891071

10901072
overall_data = {}
@@ -1107,7 +1089,7 @@ def saveFlowToLocal(self, data_to_save:savefile_params):
11071089
# 过滤掉一些没用的默认值的信息
11081090
overall_data = config_filter(overall_data)
11091091

1110-
flow_path = os.path.join(data_path, local_flows_path, data_to_save.file_name)
1092+
flow_path = os.path.join(Local_Flows_Path, data_to_save.file_name)
11111093
print(flow_path)
11121094
if(not os.path.exists(flow_path) or (data_to_save.overwrite)):
11131095
with open(flow_path,"w") as f:
@@ -1353,11 +1335,11 @@ def custom_ui(self):
13531335
if(Flow_Save_mode == "Core"):
13541336
save_mode = " (only ControlNet)"
13551337

1356-
global local_flow_list,local_flows_path
1338+
global local_flow_list,Local_Flows_Path
13571339
try:
1358-
flows_path = os.path.join(data_path, local_flows_path)
1359-
local_flow_list = [f for f in os.listdir(flows_path) if os.path.isfile(
1360-
os.path.join(flows_path, f)) and os.path.splitext(f)[-1] == '.flow']
1340+
#flows_path = os.path.join(data_path, Local_Flows_Path)
1341+
local_flow_list = [f for f in os.listdir(Local_Flows_Path) if os.path.isfile(
1342+
os.path.join(Local_Flows_Path, f)) and os.path.splitext(f)[-1] == '.flow']
13611343
except:
13621344
local_flow_list = []
13631345

scripts/state_settings.py

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ def on_ui_settings():
1414
shared.opts.add_option("lightdiffusionflow-language",
1515
shared.OptionInfo(
1616
"default",
17-
"显示语言/language",
17+
"显示语言/Language",
1818
gr.Dropdown,
1919
lambda: {
2020
"choices": ["default","中文","english"]
@@ -24,13 +24,21 @@ def on_ui_settings():
2424
shared.opts.add_option("lightdiffusionflow-mode",
2525
shared.OptionInfo(
2626
"All",
27-
f"模式/mode: ({OutputPrompt.note_for_save_mode()})",
27+
f"模式/Mode: ({OutputPrompt.note_for_save_mode()})",
2828
gr.Dropdown,
2929
lambda: {
3030
"choices": ["Core","All"]
3131
}, section=section)
3232
)
3333

34+
shared.opts.add_option("lightdiffusionflow-local-flows-path",
35+
shared.OptionInfo(
36+
default="models/LightDiffusionFlow",
37+
label=f"本地保存的flow文件路径/Local path to save flow files",
38+
#component=gr.TextBox,
39+
section=section)
40+
)
41+
3442
shared.opts.add_option("lightdiffusionflow-auto-fix-params",
3543
shared.OptionInfo(
3644
True,
@@ -40,4 +48,5 @@ def on_ui_settings():
4048
section=section)
4149
)
4250

51+
4352
scripts.script_callbacks.on_ui_settings(on_ui_settings)

0 commit comments

Comments
 (0)