12 Commits
Author SHA1 Message Date
lilly 026ffb291b support wildcard file name 2023-04-13 23:05:35 +09:00
lilly 038ea91985 add VAELoaderText 2023-04-13 00:27:48 +09:00
lilly fe13add535 Update TextWildcards.py
fix
2023-04-12 22:44:26 +09:00
lilly 40ad60ab06 Update __init__.py 2023-04-12 21:44:20 +09:00
lilly 41be495672 Update CheckpointLoaderSimpleText.py 2023-04-06 21:29:47 +09:00
lilly 059d59455c Update LoraLoaderText.py
bug fix
2023-04-05 22:09:37 +09:00
lilly 99a74bee92 Merge branch 'main' of https://github.com/lilly1987/ComfyUI_node_Lilly 2023-04-05 21:52:32 +09:00
lilly 3247eaec7e Update SimpleSampler.py 2023-04-05 21:52:25 +09:00
lilly dd3420d15c Update README.md 2023-04-05 21:25:52 +09:00
lilly eb17b381a6 Update wildcards.py
is_card_Load
2023-04-05 21:24:14 +09:00
lilly 6feccddcba Merge branch 'test' 2023-04-05 20:21:30 +09:00
lilly 7bd85c9544 Update __init__.py 2023-04-05 20:21:21 +09:00
9 changed files with 138 additions and 54 deletions
+5 -16
View File
@@ -5,10 +5,10 @@ from folder_paths import *
import random
import os
if __name__ == os.path.splitext(os.path.basename(__file__))[0] :
from ConsoleColor import print, console
from ConsoleColor import print, console, ccolor
from mypath import *
else:
from .ConsoleColor import print, console
from .ConsoleColor import print, console, ccolor
from .mypath import *
#print(__file__)
@@ -35,24 +35,13 @@ class CheckpointLoaderSimpleText:
CATEGORY = "loaders"
def load_checkpoint(self, ckpt_name, output_vae=True, output_clip=True):
#ckpt_path =check_name_ckpt(name_split_choice(ckpt_name))
print(f"ckpt_name",ckpt_name)
ns=name_split_choice(ckpt_name)
print(f"ns",ns)
ckpt_path =get_full_path("checkpoints",ns)
print(f"ckpt_path",ckpt_path)
if ckpt_path is None:
print(f"{ckpt_name} is none")
(name,fullpath)=filenameget(os.path.join(models_dir, "checkpoints")+"/**/"+ckpt_name+"*.safetensors")
if fullpath is None:
print(f"{name} is none")
return
ckpt_path=fullpath
print(f"[{ccolor}]ckpt_name : [/{ccolor}]", ckpt_name)
ckpt_path=getFullPath(ckpt_name,"checkpoints")
try:
out = comfy.sd.load_checkpoint_guess_config(ckpt_path, output_vae=True, output_clip=True, embedding_directory=folder_paths.get_folder_paths("embeddings"))
return out
except Exception as e:
print("CheckpointLoaderSimpleText Exception : "+ e)
console.print_exception()
return
+11 -17
View File
@@ -4,9 +4,11 @@ from nodes import *
import folder_paths
if __name__ == os.path.splitext(os.path.basename(__file__))[0] :
from ConsoleColor import print, console
from ConsoleColor import print, console, ccolor
from mypath import *
else:
from .ConsoleColor import print, console
from .ConsoleColor import print, console, ccolor
from .mypath import *
class LoraLoaderText:
@classmethod
@@ -31,23 +33,15 @@ class LoraLoaderText:
def load_lora(self, model, clip, lora_name, strength_model, strength_clip):
if lora_name is None or lora_name =="":
print(f"[{ccolor}]lora_name : [/{ccolor}]", lora_name)
if lora_name is None or lora_name =="" :
print("[red]No lora_name[/red] : ", lora_name)
return (strength_model, strength_clip)
if lora_name.endswith('.safetensors') or lora_name.endswith('.ckpt') :
lora_path = folder_paths.get_full_path("loras", lora_name)
return (model, clip)
else:
lora_path = folder_paths.get_full_path("loras", lora_name+'.safetensors')
print("[green]lora_path : [/green]"+ lora_path)
if lora_path is None:
lora_path = folder_paths.get_full_path("loras", lora_name+'.ckpt')
print("[green]lora_path : [/green]"+ lora_path)
if lora_path is None:
print("[red]No lora_name[/red] : ", lora_name)
return (model, clip)
lora_path=getFullPath(lora_name,"lora")
if lora_path is None:
print("[red]No lora_path of lora_name [/red] : ", lora_name)
return (model, clip)
try:
model_lora, clip_lora = comfy.sd.load_lora_for_models(model, clip, lora_path, strength_model, strength_clip)
return (model_lora, clip_lora)
+6
View File
@@ -70,6 +70,12 @@ c
__anotherfile__
```
### reload card
call wildcards.card_load()
or
wildcards.run("{9$$-$$a|b|c}",True)
## for ComfyUI
+1 -1
View File
@@ -2,7 +2,7 @@ import comfy.samplers
import comfy.sd
import comfy.utils
import comfy_extras.clip_vision
#import comfy_extras.clip_vision
import model_management
import importlib
+1 -1
View File
@@ -30,4 +30,4 @@ class TextWildcards:
print(f"[green]text : [/green]",text)
r=wildcards.run(text)
print(f"[green]result : [/green]",r)
return ([r, r], )
return (r, r)
+35
View File
@@ -0,0 +1,35 @@
import folder_paths
import comfy.sd
import os
from folder_paths import *
if __name__ == os.path.splitext(os.path.basename(__file__))[0] :
from ConsoleColor import print, console, ccolor
from mypath import *
else:
from .ConsoleColor import print, console, ccolor
from .mypath import *
class VAELoaderText:
@classmethod
def INPUT_TYPES(s):
return {"required": {
"vae_name": ("STRING", {
"multiline": False, #True if you want the field to look like the one on the ClipTextEncode node
"default": random.choice(folder_paths.get_filename_list("vae"))
}),
}}
RETURN_TYPES = ("VAE",)
FUNCTION = "load_vae"
CATEGORY = "loaders"
#TODO: scale factor?
def load_vae(self, vae_name):
print(f"[{ccolor}]vae_name : [/{ccolor}]", vae_name)
vae_path=getFullPath(vae_name,"vae")
try:
vae = comfy.sd.VAE(ckpt_path=vae_path)
return (vae,)
except Exception as e:
console.print_exception()
return
+43 -17
View File
@@ -1,9 +1,24 @@
import sys
import os
if __name__ == os.path.splitext(os.path.basename(__file__))[0] :
print(f"__name__ : {__name__}")
print(f"__file__ : {__file__}")
print(f"os.path.basename(__file__) : {os.path.basename(__file__)}")
print(f"os.path.splitext(os.path.basename(__file__))[0] : {os.path.splitext(os.path.basename(__file__))[0]}")
#print(f"os.path.basename(__file__) : {os.path.basename('/ComfyUI_windows_portable/ComfyUI/custom_nodes/ComfyUI_node_Lilly/__init__.py')}")
#print(f"os.path.splitext(os.path.basename(__file__))[0] : {os.path.splitext(os.path.basename('/ComfyUI_windows_portable/ComfyUI/custom_nodes/ComfyUI_node_Lilly/__init__.py'))[0]}")
wd = os.getcwd()
print("working directory : ", wd)
if __name__ == os.path.splitext(os.path.basename(__file__))[0] or __name__ =='__main__':
from ConsoleColor import print, console
#md="custom_nodes.ComfyUI_node_Lilly."
else:
from .ConsoleColor import print, console
#md="custom_nodes.ComfyUI_node_Lilly."
md="custom_nodes.ComfyUI_node_Lilly."
#print(__file__)
#print(os.path.basename(__file__))
@@ -21,13 +36,14 @@ else:
#path, filename = os.path.split(absFilePath)
#print("Script file path is {}, filename is {}".format(path, filename))
wd = os.getcwd()
#print("working directory : ", wd)
nm=os.path.abspath(__name__)
#
#nm=os.path.abspath(__name__)
#nm=os.path.abspath(__name__)
#print("abspath __name__ : ", nm)
md=nm.replace(wd+"\\","")
#print("abspath __name__ : ", nm)
#
#md=nm.replace(wd+"\\","")
#print("import name", md)
"""
"""
@@ -35,32 +51,41 @@ md=nm.replace(wd+"\\","")
# print(f"{md!r} already in sys.modules")
#else:
# print(f"{md!r} not in sys.modules")
if not md.startswith("custom_nodes."):
import importlib
#from custom_nodes.ComfyUI_node_Lilly import eval(f"{name}")
#import importlib
#import ComfyUI_node_Lilly
#from custom_nodes.ComfyUI_node_Lilly import eval(f"{name}")
#print(dir(ComfyUI_node_Lilly))
#print(dir(ComfyUI_node_Lilly.ComfyUI_node_Lilly))
#print(__name__ == md)
#print(__name__ != md)
#print(__name__ == "ComfyUI_node_Lilly")
#print(__name__ != "ComfyUI_node_Lilly")
if __name__ == "ComfyUI_node_Lilly" :
NODE_CLASS_MAPPINGS = {
}
def add(name,clist=None):
#print(f"Load : {name}")
try:
pkg = importlib.import_module(f"{md}.{name}")
#pkg = importlib.import_module(f"{md}{name}")
#eval(f"{md}{name}")
exec(f"import {md}{name}")
if clist is None:
NODE_CLASS_MAPPINGS[name]=eval(f"pkg.{name}")
NODE_CLASS_MAPPINGS[name]=eval(f"{md}{name}.{name}")
elif type(clist) is str:
NODE_CLASS_MAPPINGS[clist]=eval(f"pkg.{clist}")
NODE_CLASS_MAPPINGS[clist]=eval(f"{md}{name}.{clist}")
elif type(clist) is list:
for c in clist:
NODE_CLASS_MAPPINGS[c]=eval(f"pkg.{c}")
NODE_CLASS_MAPPINGS[c]=eval(f"{md}{name}.{c}")
print(f"Load ok : {name}", style="bold green")
except Exception:
console.print_exception()
console.rule(f" init start ", style="bold green")
add("CheckpointLoaderRandom")
add("CheckpointLoaderSimpleText")
add("CLIPTextEncodeWildcards",["CLIPTextEncodeWildcards","CLIPTextEncodeWildcards2","CLIPTextEncodeWildcards3"])
@@ -68,9 +93,10 @@ if not md.startswith("custom_nodes."):
add("LoraLoaderTextRandom")
add("Random_Sampler")
add("VAELoaderDecode")
add("VAELoaderText")
add("SimpleSampler",["SimpleSampler","SimpleSamplerVAE"])
add("SaveImageSimple")
add("TextWildcards")
#add("test")
console.rule(" init end ", style="bold green")
+31
View File
@@ -3,6 +3,7 @@ import json
import ast
import os, glob
import random
from folder_paths import *
if __name__ == os.path.splitext(os.path.basename(__file__))[0] :
from ConsoleColor import print, console
else:
@@ -79,3 +80,33 @@ def filenameget(v_path):
name=os.path.basename(fullpath)
#r_path=[os.path.basename(fullpath) for fullpath in fullpaths]
return (name,fullpath)
# "test","vae",["pt","safetensors"]
def getFullPath(p,k,el=["safetensors","ckpt","pt"]):
if os.path.isabs(p):
path=p
else:
path=os.path.join(models_dir,k+"/**/",p)
#print(f"path : ", path)
t=False
for e in el:
if p.endswith('.'+e):
t=True
break
if t:
files=glob.glob(path, recursive=True)
else:
for e in el:
t=path+"."+e
#print(f"t : ", t)
files=glob.glob(t, recursive=True)
if len(files):
break
result=None
#print(f"files : ", files)
if len(files):
result=random.choice(files)
print(f"result : ", result)
else:
print("[red]No file in path[/red] : ", path)
return result
+5 -2
View File
@@ -25,6 +25,7 @@ class wildcards:
recard = re.compile(r"(__)(.*?)(__)")
# 카드 목록
is_card_Load = False
cards = {}
seperator=", "
loop_max=50
@@ -152,13 +153,15 @@ class wildcards:
wildcards.cards=cards
print(f"[cyan]cards file count : [/cyan]", len(wildcards.cards))
#print(f"cards : {cards.keys()}")
wildcards.is_card_Load=True
# 실행기
def run(text):
def run(text,load=False):
if text is None or type(text) is not str:
print("[red]text is not str : [/red]",text)
return None
wildcards.card_load()
if not wildcards.is_card_Load or load:
wildcards.card_load()
#print(f"text : {text}")
result=wildcards.card_loop(text)