代码拉取完成,页面将自动刷新
同步操作将从 yanlang0123/ComfyUI_Lam 强制同步,此操作会覆盖自 Fork 仓库以来所做的任何修改,且无法恢复!!!
确定后同步将在后台操作,完成时将刷新页面,请耐心等待。
import server
from aiohttp import web
import os
import json
dir = os.path.abspath(os.path.join(__file__, "../../styles"))
if not os.path.exists(dir):
os.mkdir(dir)
@server.PromptServer.instance.routes.get("/lam/getStyles")
def getStyles(request):
if "name" in request.rel_url.query:
name = request.rel_url.query["name"]
file = os.path.join(dir, name+'.json')
zhFile = os.path.join(dir, 'zh_CN.json')
if os.path.isfile(zhFile):
f = open(zhFile,'r', encoding='utf-8')
zhData = json.load(f)
f.close()
if os.path.isfile(file):
f = open(file,'r', encoding='utf-8')
data = json.load(f)
f.close()
if data:
ndata=[]
if zhData:
for d in data:
nd={}
name=d['name'].replace('-',' ')
words=name.split(' ')
key=' '.join(word.upper() if word.lower() in ['mre','sai','3d'] else word.capitalize() for word in words)
img_name='_'.join(words).lower()
nd['zhName']=zhData[key] if key in zhData else key
nd["name"]=d['name']
nd['imgName']=img_name
ndata.append(nd)
return web.json_response(ndata)
return web.Response(status=404)
class StyleSelecto:
"""
提示词选择工具
"""
def __init__(self):
dir = os.path.abspath(os.path.join(__file__, "../../styles"))
if not os.path.exists(dir):
os.mkdir(dir)
self.styleAll={}
for root, dirs, files in os.walk(dir):
for file in files:
if file.endswith(".json") and file.split(".")[0].find("styles")!=-1:
f = open(os.path.join(root, file), 'r', encoding='utf-8')
data = json.load(f)
f.close()
for d in data:
self.styleAll[d['name']] = d
@classmethod
def INPUT_TYPES(self):
dir = os.path.abspath(os.path.join(__file__, "../../styles"))
#获取目录全部yml文件名
files_name=[]
for root, dirs, files in os.walk(dir):
for file in files:
if file.endswith(".json") and file.split(".")[0].find("styles")!=-1:
files_name.append(file.split(".")[0])
return {
"required": {
"prompt": ("STRING", {"forceInput": True}),
"style_type":(files_name, ),
},
"optional": {
"negative_prompt":("STRING",{"forceInput": True}),
"i": ("INT",{"forceInput": True}),
},
"hidden": {"unique_id": "UNIQUE_ID","wprompt":"PROMPT"},
}
RETURN_TYPES = ("STRING","STRING","STRING",)
RETURN_NAMES = ("正向提示词","反向提示词","i项风格名称",)
FUNCTION = "get_style"
#OUTPUT_NODE = False
CATEGORY = "lam"
def get_style(self,prompt,style_type,unique_id,wprompt,negative_prompt="",i=None):
values = []
if unique_id in wprompt:
if wprompt[unique_id]["inputs"]['styles']:
#分割字符串
values = wprompt[unique_id]["inputs"]['styles'].split(',')
styleName=''
if i!=None:
if len(values)>0:
styleName=values[i]
if 'prompt' in self.styleAll[values[i]]:
prompt=self.styleAll[values[i]]['prompt'].format(prompt=prompt)
if 'negative_prompt' in self.styleAll[values[i]]:
negative_prompt+=','+self.styleAll[values[i]]['negative_prompt']
else:
keysl=list(self.styleAll.keys())
styleName=keysl[i]
if 'prompt' in self.styleAll[keysl[i]]:
prompt=self.styleAll[keysl[i]]['prompt'].format(prompt=prompt)
if 'negative_prompt' in self.styleAll[keysl[i]]:
negative_prompt+=','+self.styleAll[keysl[i]]['negative_prompt']
else:
for val in values:
if 'prompt' in self.styleAll[val]:
prompt=self.styleAll[val]['prompt'].format(prompt=prompt)
if 'negative_prompt' in self.styleAll[val]:
negative_prompt+=','+self.styleAll[val]['negative_prompt']
return (prompt,negative_prompt,styleName)
# A dictionary that contains all nodes you want to export with their names
# NOTE: names should be globally unique
NODE_CLASS_MAPPINGS = {
"StyleSelecto": StyleSelecto
}
# A dictionary that contains the friendly/humanly readable titles for the nodes
NODE_DISPLAY_NAME_MAPPINGS = {
"StyleSelecto": "风格选择器"
}
此处可能存在不合适展示的内容,页面不予展示。您可通过相关编辑功能自查并修改。
如您确认内容无涉及 不当用语 / 纯广告导流 / 暴力 / 低俗色情 / 侵权 / 盗版 / 虚假 / 无价值内容或违法国家有关法律法规的内容,可点击提交进行申诉,我们将尽快为您处理。