代码拉取完成,页面将自动刷新
同步操作将从 yanlang0123/ComfyUI_Lam 强制同步,此操作会覆盖自 Fork 仓库以来所做的任何修改,且无法恢复!!!
确定后同步将在后台操作,完成时将刷新页面,请耐心等待。
from server import PromptServer
from aiohttp import web
import json
import os
import yaml
#获取组节点
gdir = os.path.abspath(os.path.join(__file__, "../../groupNode"))
if not os.path.exists(gdir):
os.mkdir(gdir)
@PromptServer.instance.routes.get("/lam/groupNode")
async def get_groupNode(request):
file=os.path.join(gdir, "groupNodes.json")
if os.path.isfile(file):
f = open(file,'r', encoding='utf-8')
data = json.load(f)
return web.json_response(data)
return web.Response(status=404)
@PromptServer.instance.routes.post("/lam/groupNode")
async def save_groupNode(request):
json_data = await request.json()
file=os.path.join(gdir, "groupNodes.json")
if os.path.isfile(file):
f = open(file,'r', encoding='utf-8')
data = json.load(f)
for key in list(json_data.keys()):
data[key] = json_data[key]
with open(file, 'w', encoding='utf-8') as f:
json.dump(data, f, ensure_ascii=False, indent=4)
return web.Response(status=201)
@PromptServer.instance.routes.post("/lam/delGroupNode")
async def del_groupNode(request):
json_data = await request.json()
file=os.path.join(gdir, "groupNodes.json")
if os.path.isfile(file):
f = open(file,'r', encoding='utf-8')
data = json.load(f)
if 'name' in list(json_data.keys()):
if json_data['name'] in data:
del data[json_data['name']]
with open(file, 'w', encoding='utf-8') as f:
json.dump(data, f, ensure_ascii=False, indent=4)
return web.Response(status=201)
#获取提示词
dir = os.path.abspath(os.path.join(__file__, "../../tags"))
if not os.path.exists(dir):
os.mkdir(dir)
@PromptServer.instance.routes.get("/lam/getPrompt")
def getPrompt(request):
if "name" in request.rel_url.query:
name = request.rel_url.query["name"]
file = os.path.join(dir, name+'.yml')
if os.path.isfile(file):
f = open(file,'r', encoding='utf-8')
data = yaml.load(f, Loader=yaml.FullLoader)
f.close()
#转json
if data:
return web.json_response(data)
return web.Response(status=404)
class EasyPromptSelecto:
"""
提示词选择工具
"""
def __init__(self):
pass
@classmethod
def INPUT_TYPES(s):
dir = os.path.abspath(os.path.join(__file__, "../../tags"))
if not os.path.exists(dir):
os.mkdir(dir)
#获取目录全部yml文件名
files_name=[]
for root, dirs, files in os.walk(dir):
for file in files:
if file.endswith(".yml"):
files_name.append(file.split(".")[0])
return {
"required": {
"text": ("STRING",{"default": ""}),
"prompt_type":(files_name, ),
},
"hidden": {"unique_id": "UNIQUE_ID","wprompt":"PROMPT"},
}
RETURN_TYPES = ("STRING",)
RETURN_NAMES = ("提示词",)
FUNCTION = "translate"
#OUTPUT_NODE = False
CATEGORY = "lam"
def translate(self,prompt_type,unique_id,wprompt,text=''):
values = ''
if unique_id in wprompt:
if wprompt[unique_id]["inputs"]['tags']:
#分割字符串
values = wprompt[unique_id]["inputs"]['tags']
return (text+values,)
# A dictionary that contains all nodes you want to export with their names
# NOTE: names should be globally unique
NODE_CLASS_MAPPINGS = {
"EasyPromptSelecto": EasyPromptSelecto
}
# A dictionary that contains the friendly/humanly readable titles for the nodes
NODE_DISPLAY_NAME_MAPPINGS = {
"EasyPromptSelecto": "提示词选择工具"
}
此处可能存在不合适展示的内容,页面不予展示。您可通过相关编辑功能自查并修改。
如您确认内容无涉及 不当用语 / 纯广告导流 / 暴力 / 低俗色情 / 侵权 / 盗版 / 虚假 / 无价值内容或违法国家有关法律法规的内容,可点击提交进行申诉,我们将尽快为您处理。