Skip to content

Commit dc6b512

Browse files
committed
版本更新V0.0.57
版本更新V0.0.57
1 parent d54999d commit dc6b512

File tree

21 files changed

+481
-163
lines changed

21 files changed

+481
-163
lines changed

README.md

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@
3030

3131
> 最新更新:2025-05-07
3232
33-
> 0.0.56 公测版本介绍 如果你要使用本插件请务必进我们的官方 QQ 群(1018231382)!
33+
> 0.0.57 公测版本介绍 如果你要使用本插件请务必进我们的官方 QQ 群(1018231382)!
3434
>
3535
> 1. 修复了已知BUG
3636
>
@@ -52,6 +52,10 @@
5252
>
5353
> 10. 插件有新版本时窗口左下角会提示更新
5454
>
55+
> 11. 节点新增功能:自动随机Tag,设置好了模板即可使用,每个节点的随机模板都是不同的可以自定义化
56+
>
57+
> 12. 修改了Lora管理器,新增了二级目录显示全部的功能,修改了目录栏的高度问题
58+
>
5559
5660
<details>
5761
<summary>点击查看往期更多更新内容</summary>

README_EN.md

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ Due to limited personal time, the frequency of updating plug-ins will not be ver
2626

2727
> Last updated: 2025-05-07
2828
29-
> 0.0.56 Public Beta Version Introduction: If you want to use this plugin, please be sure to join our official QQ group (1018231382)!
29+
> 0.0.57 Public Beta Version Introduction: If you want to use this plugin, please be sure to join our official QQ group (1018231382)!
3030
>
3131
> 1. Fixed known bugs
3232
>
@@ -48,6 +48,10 @@ Due to limited personal time, the frequency of updating plug-ins will not be ver
4848
>
4949
> 10. The lower left corner of the window will prompt for updates when a new version of the plugin is available
5050
>
51+
> 11. New node function: automatic random Tag, set the template can be used, each node's random template is different and can be customized
52+
>
53+
> 12. Modified the Lora manager, added the function of displaying all secondary directories, and changed the height problem of the directory bar
54+
>
5155
5256
<details>
5357
<summary>Click here for more updates from the past</summary>

__init__.py

Lines changed: 64 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -65,15 +65,21 @@ class WeiLinPromptUI:
6565
def __init__(self):
6666
self.loaded_loraA = None
6767

68+
def IS_CHANGED(self, auto_random, **kwargs):
69+
if auto_random:
70+
return float("nan")
71+
return auto_random
72+
6873
@classmethod
69-
def INPUT_TYPES(s):
74+
def INPUT_TYPES(self):
7075
return {
7176
"required": {
7277
"positive": ("STRING", {
7378
"multiline": True,
7479
"default": "",
7580
"placeholder": placeholder_text,
7681
}),
82+
"auto_random": ("BOOLEAN", {"default": False}),
7783
},
7884
"optional": {
7985
"lora_str": ("STRING", {
@@ -91,6 +97,11 @@ def INPUT_TYPES(s):
9197
"default": "",
9298
"placeholder": "temp prompt words",
9399
}),
100+
"random_template": ("STRING", {
101+
"multiline": True,
102+
"default": "",
103+
"placeholder": "random template path name",
104+
}),
94105
"opt_text": (ANY, {"default": ""}),
95106
"opt_clip": ("CLIP", ),
96107
"opt_model": ("MODEL",),
@@ -105,12 +116,12 @@ def INPUT_TYPES(s):
105116
# FUNCTION = "encode"
106117
FUNCTION = "load_lora_ing"
107118

108-
# OUTPUT_NODE = False
119+
OUTPUT_NODE = True
109120

110121
CATEGORY = node_name_text
111122

112123
# 加载Lora
113-
def load_lora_ing(self, positive="",lora_str="",temp_str="",temp_lora_str="", opt_text="", opt_clip=None, opt_model=None):
124+
def load_lora_ing(self, positive="", auto_random=False, lora_str="", temp_str="", temp_lora_str="",random_template="", opt_text="", opt_clip=None, opt_model=None):
114125
model_lora_secondA = opt_model
115126
clip_lora_secondA = opt_clip
116127

@@ -132,6 +143,19 @@ def load_lora_ing(self, positive="",lora_str="",temp_str="",temp_lora_str="", op
132143
if len(lora_str) > 0:
133144
json_object = json.loads(lora_str)
134145
lora_list = json_object
146+
147+
if auto_random:
148+
if len(random_template) > 0:
149+
# 随机Tag获取
150+
random_tag = go_run_node_auto_random_tag(random_template)
151+
if len(random_tag["random_tags"]) > 0:
152+
positive = random_tag["random_tags"]
153+
self.positive = positive
154+
if len(opt_text) > 0:
155+
text_dec = opt_text +", "+positive
156+
else:
157+
text_dec = positive
158+
135159

136160
# 当模型不为空时
137161
if opt_model != None and lora_list != None:
@@ -163,8 +187,9 @@ def load_lora_ing(self, positive="",lora_str="",temp_str="",temp_lora_str="", op
163187
tokensA = clip_lora_secondA.tokenize(text_dec)
164188
outputA = clip_lora_secondA.encode_from_tokens(tokensA, return_pooled=True, return_dict=True)
165189
condA = outputA.pop("cond")
166-
return (text_dec,[[condA, outputA]], clip_lora_secondA, model_lora_secondA)
167-
return (text_dec, clip_lora_secondA, clip_lora_secondA, model_lora_secondA)
190+
return {"ui": {"positive": [str(positive)]}, "result": (text_dec,[[condA, outputA]], clip_lora_secondA, model_lora_secondA,)}
191+
192+
return {"ui": {"positive": [str(positive)]}, "result": (text_dec, clip_lora_secondA, clip_lora_secondA, model_lora_secondA,)}
168193
# return (model_lora_second, clip_lora_second)
169194

170195

@@ -175,7 +200,7 @@ def __init__(self):
175200
self.loaded_loraA = None
176201

177202
@classmethod
178-
def INPUT_TYPES(s):
203+
def INPUT_TYPES(self):
179204
return {
180205
"required": {
181206
"clip": ("CLIP", ),
@@ -252,35 +277,51 @@ class WeiLinPromptUIWithoutLora:
252277
def __init__(self):
253278
pass
254279

280+
def IS_CHANGED(self, auto_random, **kwargs):
281+
if auto_random:
282+
return float("nan")
283+
return auto_random
284+
255285
@classmethod
256-
def INPUT_TYPES(s):
286+
def INPUT_TYPES(self):
257287
return {
258288
"required": {
259289
"positive": ("STRING", {
260290
"multiline": True,
261291
"default": "",
262292
"placeholder": placeholder_text,
263293
}),
294+
"auto_random": ("BOOLEAN", {"default": False}),
264295
},
265296
"optional": {
266297
"temp_str": ("STRING", {
267298
"multiline": True,
268299
"default": "",
269300
"placeholder": "temp prompt words",
270301
}),
302+
"random_template": ("STRING", {
303+
"multiline": True,
304+
"default": "",
305+
"placeholder": "random template path name",
306+
}),
271307
"opt_text": (ANY, {"default": ""}),
272308
"opt_clip": ("CLIP", ),
273-
}
309+
},
310+
"hidden": {
311+
"unique_id": "UNIQUE_ID",
312+
"extra_pnginfo": "EXTRA_PNGINFO",
313+
},
274314
}
275315

276316
RETURN_TYPES = ("STRING", "CONDITIONING", "CLIP", )
277317
RETURN_NAMES = ("STRING", "CONDITIONING", "CLIP", )
278-
279318
FUNCTION = "encode"
319+
OUTPUT_NODE = True
280320

281321
CATEGORY = node_name_text
282322

283-
def encode(self, positive="", temp_str="", opt_text="", opt_clip=None):
323+
def encode(self, positive="", auto_random=False, temp_str="", random_template="",
324+
opt_text="", opt_clip=None, unique_id=None, extra_pnginfo=None):
284325
text_dec = ""
285326
if is_json(positive):
286327
json_object = json.loads(positive)
@@ -293,12 +334,23 @@ def encode(self, positive="", temp_str="", opt_text="", opt_clip=None):
293334
text_dec = opt_text +", "+positive
294335
else:
295336
text_dec = positive
337+
338+
if auto_random:
339+
if len(random_template) > 0:
340+
# 随机Tag获取
341+
random_tag = go_run_node_auto_random_tag(random_template)
342+
if len(random_tag["random_tags"]) > 0:
343+
positive = random_tag["random_tags"]
344+
if len(opt_text) > 0:
345+
text_dec = opt_text +", "+positive
346+
else:
347+
text_dec = positive
296348

297349
if opt_clip is not None:
298350
tokens = opt_clip.tokenize(text_dec)
299-
return (text_dec, opt_clip.encode_from_tokens_scheduled(tokens), opt_clip)
351+
return {"ui": {"positive": [str(positive)]}, "result": (text_dec, opt_clip.encode_from_tokens_scheduled(tokens), opt_clip,)}
300352

301-
return (text_dec, opt_clip, opt_clip)
353+
return {"ui": {"positive": [str(positive)]}, "result": (text_dec, opt_clip, opt_clip,)}
302354

303355

304356

app/server/prompt_api/lora_networks.py

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -71,14 +71,16 @@ def get_lora_folder():
7171
- "一级目录名": 该一级目录下的子目录和文件
7272
- "/": 该目录下的文件列表
7373
- "子目录名": 子目录下的文件列表
74+
- "all": 该目录下所有文件的列表
7475
"""
7576
all_files = folder_paths.get_filename_list("loras")
7677

7778
# 初始化结果字典
7879
result = {
7980
"all": all_files,
8081
"/": {
81-
"/": {} # 根目录下的文件
82+
"/": {}, # 根目录下的文件
83+
"all": [] # 根目录下所有文件
8284
}
8385
}
8486

@@ -89,29 +91,37 @@ def get_lora_folder():
8991
if len(parts) == 1:
9092
# 根目录文件
9193
result["/"]["/"][parts[0]] = file_path
94+
result["/"]["all"].append(file_path)
9295
else:
9396
# 一级目录
9497
level1_dir = parts[0]
9598

9699
# 确保一级目录在结果字典中
97100
if level1_dir not in result:
98101
result[level1_dir] = {
102+
"all": [], # 该目录下所有文件
99103
"/": {} # 该目录下的文件
100104
}
101105

102106
if len(parts) == 2:
103107
# 一级目录下的文件
104108
result[level1_dir]["/"][parts[1]] = file_path
109+
result[level1_dir]["all"].append(file_path)
105110
else:
106111
# 二级及以下目录
107112
subdir = "\\".join(parts[1:-1]) # 排除文件名
108113

109114
# 确保子目录在一级目录下
110115
if subdir not in result[level1_dir]:
111-
result[level1_dir][subdir] = {} # 子目录下的文件直接存储
116+
result[level1_dir][subdir] = {
117+
"all": [], # 子目录下所有文件
118+
"/": {} # 子目录下的文件
119+
}
112120

113121
# 添加文件到子目录,使用完整路径
114122
result[level1_dir][subdir][parts[-1]] = file_path
123+
result[level1_dir][subdir]["all"].append(file_path)
124+
result[level1_dir]["all"].append(file_path)
115125

116126
return result
117127

app/server/prompt_api/random_tag_template.py

Lines changed: 17 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,8 @@
33
import datetime
44
import random
55
from typing import List
6-
from ..dao.dao import _get_connection
6+
from ..dao.dao import tags_db_path
7+
import sqlite3
78

89
current_dir = os.path.dirname(os.path.abspath(__file__))
910
init_file_path = os.path.join(current_dir, '../../../random_tag')
@@ -152,34 +153,34 @@ def get_template_data(name: str):
152153
raise Exception(str(e))
153154

154155

155-
async def get_random_tags_by_group(p_uuid: str) -> List[str]:
156+
def get_random_tags_by_group(p_uuid: str) -> List[str]:
156157
"""根据group的p_uuid获取随机标签"""
157-
conn = await _get_connection('tags')
158-
cursor = await conn.cursor()
159-
await cursor.execute('''
158+
conn = sqlite3.connect(tags_db_path)
159+
cursor = conn.cursor()
160+
cursor.execute('''
160161
SELECT t.text FROM tag_tags t
161162
JOIN tag_subgroups sg ON t.subgroup_id = sg.id_index
162163
WHERE sg.p_uuid = ?
163164
''', (p_uuid,))
164-
results = await cursor.fetchall()
165+
results = cursor.fetchall()
165166
return [row[0] for row in results]
166167

167-
async def get_random_tags_by_subgroup(g_uuid: str) -> List[str]:
168+
def get_random_tags_by_subgroup(g_uuid: str) -> List[str]:
168169
"""根据subgroup的g_uuid获取随机标签"""
169-
conn = await _get_connection('tags')
170-
cursor = await conn.cursor()
171-
await cursor.execute('''
170+
conn = sqlite3.connect(tags_db_path)
171+
cursor = conn.cursor()
172+
cursor.execute('''
172173
SELECT text FROM tag_tags WHERE g_uuid = ?
173174
''', (g_uuid,))
174-
results = await cursor.fetchall()
175+
results = cursor.fetchall()
175176
return [row[0] for row in results]
176177

177178
def shuffle_and_select(tags: List[str], count: int) -> List[str]:
178179
"""随机打乱并选择指定数量的标签"""
179180
random.shuffle(tags)
180181
return tags[:count]
181182

182-
async def generate_random_tags(data: dict) -> str:
183+
def generate_random_tags(data: dict) -> str:
183184
"""生成随机标签字符串"""
184185
result = []
185186

@@ -192,9 +193,9 @@ async def generate_random_tags(data: dict) -> str:
192193
tags = []
193194
for group in rule['tagGroupList']:
194195
if group['sub']:
195-
tags.extend(await get_random_tags_by_subgroup(group['sub']['g_uuid']))
196+
tags.extend(get_random_tags_by_subgroup(group['sub']['g_uuid']))
196197
else:
197-
tags.extend(await get_random_tags_by_group(group['group']['p_uuid']))
198+
tags.extend(get_random_tags_by_group(group['group']['p_uuid']))
198199
selected_tags = shuffle_and_select(tags, count)
199200
result.extend(selected_tags)
200201

@@ -206,7 +207,7 @@ async def generate_random_tags(data: dict) -> str:
206207
return ','.join(result) + ','
207208

208209

209-
async def go_radom_template(name: str):
210+
def go_radom_template(name: str):
210211
try:
211212
# 构建完整文件路径
212213
file_path = os.path.join(init_file_path, f"{name}.json")
@@ -220,7 +221,7 @@ async def go_radom_template(name: str):
220221
data = json.load(f)
221222

222223
# 生成随机标签
223-
random_tags = await generate_random_tags(data)
224+
random_tags = generate_random_tags(data)
224225

225226
return {"code": 200, "random_tags": random_tags, "path_name": str(name)}
226227

app/server/prompt_server.py

Lines changed: 20 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -905,11 +905,30 @@ async def _go_random_template(request):
905905
setting = get_random_template_setting() # 获取设置的参数信息
906906
if setting == "":
907907
return web.json_response({"code": 300, "info": '请先应用一个模板'})
908-
return web.json_response(await go_radom_template(setting))
908+
return web.json_response(go_radom_template(setting))
909+
except Exception as e:
910+
print(f"Error: {e}")
911+
return web.Response(status=500)
912+
913+
@PromptServer.instance.routes.post(baseUrl+"random_template/go_random_template_path")
914+
async def _go_random_template_path(request):
915+
data = await request.json()
916+
try:
917+
if data.get('name') == "":
918+
return web.json_response({"code": 300, "info": '请先应用一个模板'})
919+
return web.json_response(go_radom_template(data.get('name')))
909920
except Exception as e:
910921
print(f"Error: {e}")
911922
return web.Response(status=500)
912923

913924
# =====================================================================================================
914925
print("======== WeiLin插件服务已启动 ========")
915926
print("======== WeiLin Server Init ========")
927+
928+
929+
def go_run_node_auto_random_tag(name):
930+
try:
931+
return go_radom_template(name)
932+
except Exception as e:
933+
print(f"Error: {e}")
934+
return ""

dist/javascript/main.entry.js

Lines changed: 61 additions & 61 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

dist/javascript/main.entry.js.map

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

dist/style.css

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)