Compare commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
396256c084 | ||
|
|
87d6fd0c35 | ||
|
|
70ed2501bb | ||
|
|
4e57039166 | ||
|
|
4bc3e21500 | ||
|
|
c34ebf1940 | ||
|
|
b4191ce40f | ||
|
|
ca5e193b7e | ||
|
|
4b5f62e141 | ||
|
|
35f66f5712 | ||
|
|
1300e6f958 | ||
|
|
7186f2c895 | ||
|
|
4c50ca066b | ||
|
|
0c4fe0b7f5 | ||
|
|
46d6e4e111 | ||
|
|
bdb80a3c85 | ||
|
|
d3667dc022 | ||
|
|
8cadb8a284 | ||
|
|
ed401cb9b8 | ||
|
|
ab31903931 | ||
|
|
2148bbd6df | ||
|
|
c94162bfcd | ||
|
|
60ff0e5b57 | ||
|
|
9ffde08e4d |
@@ -1,2 +1,3 @@
|
||||
|
||||
*.pyc
|
||||
**/nppBackup/
|
||||
|
||||
@@ -36,7 +36,10 @@ class CheckpointLoaderSimpleText:
|
||||
|
||||
def load_checkpoint(self, ckpt_name, output_vae=True, output_clip=True):
|
||||
print(f"[{ccolor}]ckpt_name : [/{ccolor}]", ckpt_name)
|
||||
ckpt_path=getFullPath(ckpt_name,"checkpoints")
|
||||
ckpt_path=folder_paths.get_full_path("checkpoints", ckpt_name)
|
||||
if ckpt_path is None:
|
||||
ckpt_path=getFullPath(ckpt_name,"checkpoints")
|
||||
print(f"[{ccolor}]ckpt_path : [/{ccolor}]", ckpt_path)
|
||||
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
|
||||
|
||||
+28
-4
@@ -11,6 +11,9 @@ else:
|
||||
from .mypath import *
|
||||
|
||||
class LoraLoaderText:
|
||||
def __init__(self):
|
||||
self.loaded_lora = None
|
||||
|
||||
@classmethod
|
||||
def INPUT_TYPES(s):
|
||||
return {
|
||||
@@ -34,16 +37,37 @@ class LoraLoaderText:
|
||||
def load_lora(self, model, clip, lora_name, strength_model, strength_clip):
|
||||
|
||||
print(f"[{ccolor}]lora_name : [/{ccolor}]", lora_name)
|
||||
if strength_model == 0 and strength_clip == 0:
|
||||
print("[red]strength_model,strength_clip 0[/red] : ", lora_name)
|
||||
return (model, clip)
|
||||
|
||||
if lora_name is None or lora_name =="" :
|
||||
print("[red]No lora_name[/red] : ", lora_name)
|
||||
return (model, clip)
|
||||
|
||||
lora_path=getFullPath(lora_name,"lora")
|
||||
lora_path = folder_paths.get_full_path("loras", lora_name)
|
||||
if lora_path is None:
|
||||
print("[red]No lora_path of lora_name [/red] : ", lora_name)
|
||||
return (model, clip)
|
||||
print("[yellow]No lora_path of lora_name [/yellow] : ", lora_name)
|
||||
lora_path=getFullPath(lora_name,"loras")
|
||||
if lora_path is None:
|
||||
print("[red]No lora_path of lora_name [/red] : ", lora_name)
|
||||
return (model, clip)
|
||||
|
||||
lora = None
|
||||
if self.loaded_lora is not None:
|
||||
if self.loaded_lora[0] == lora_path:
|
||||
lora = self.loaded_lora[1]
|
||||
else:
|
||||
del self.loaded_lora
|
||||
|
||||
if lora is None:
|
||||
lora = comfy.utils.load_torch_file(lora_path, safe_load=True)
|
||||
self.loaded_lora = (lora_path, lora)
|
||||
|
||||
# =========================================
|
||||
|
||||
try:
|
||||
model_lora, clip_lora = comfy.sd.load_lora_for_models(model, clip, lora_path, strength_model, strength_clip)
|
||||
model_lora, clip_lora = comfy.sd.load_lora_for_models(model, clip, lora, strength_model, strength_clip)
|
||||
return (model_lora, clip_lora)
|
||||
except Exception as e:
|
||||
console.print_exception()
|
||||
|
||||
+30
-7
@@ -48,18 +48,41 @@ class LoraLoaderTextRandom:
|
||||
strength_model=random.uniform(min(strength_model_min,strength_model_max),max(strength_model_min,strength_model_max))
|
||||
strength_clip=random.uniform(min(strength_clip_min,strength_clip_max),max(strength_clip_min,strength_clip_max))
|
||||
|
||||
lora_path =check_name_pt("loras",name_split_choice(lora_name))
|
||||
if lora_path is None:
|
||||
print(f"LoraLoaderTextRandom : {lora_name} is none")
|
||||
print(f"[{ccolor}]lora_name : [/{ccolor}]", lora_name)
|
||||
if strength_model == 0 and strength_clip == 0:
|
||||
print("[red]strength_model,strength_clip 0[/red] : ", lora_name)
|
||||
return (model, clip)
|
||||
print(f"LoraLoaderTextRandom : {lora_path} ")
|
||||
|
||||
if lora_name is None or lora_name =="" :
|
||||
print("[red]No lora_name[/red] : ", lora_name)
|
||||
return (model, clip)
|
||||
|
||||
lora_path = folder_paths.get_full_path("loras", lora_name)
|
||||
if lora_path is None:
|
||||
#print("[red]No lora_path of lora_name [/red] : ", lora_name)
|
||||
lora_path=getFullPath(lora_name,"loras")
|
||||
if lora_path is None:
|
||||
print("[red]No lora_path of lora_name [/red] : ", lora_name)
|
||||
return (model, clip)
|
||||
|
||||
lora = None
|
||||
if self.loaded_lora is not None:
|
||||
if self.loaded_lora[0] == lora_path:
|
||||
lora = self.loaded_lora[1]
|
||||
else:
|
||||
del self.loaded_lora
|
||||
|
||||
if lora is None:
|
||||
lora = comfy.utils.load_torch_file(lora_path, safe_load=True)
|
||||
self.loaded_lora = (lora_path, lora)
|
||||
|
||||
# =========================================
|
||||
|
||||
try:
|
||||
model_lora, clip_lora = comfy.sd.load_lora_for_models(model, clip, lora_path, strength_model, strength_clip)
|
||||
return (model_lora, clip_lora)
|
||||
except Exception as e:
|
||||
print(f"LoraLoaderTextRandom Exception : {e}" )
|
||||
err_msg = traceback.format_exc()
|
||||
print(err_msg)
|
||||
console.print_exception()
|
||||
return (model, clip)
|
||||
|
||||
#NODE_CLASS_MAPPINGS = {
|
||||
|
||||
@@ -1,20 +1,30 @@
|
||||
# ComfyUI-node-Lilly
|
||||
|
||||
## No longer maintained.
|
||||
|
||||
i use https://github.com/ltdrdata/ComfyUI-extension-tutorials/blob/Main/ComfyUI-Impact-Pack/tutorial/ImpactWildcard.md
|
||||
|
||||
## install
|
||||
|
||||
ComfyUI_windows_portable\ComfyUI\custom_nodes\ComfyUI_node_Lilly
|
||||
Go to ./custom_nodes and clone git repo:
|
||||
|
||||
```
|
||||
cd ./custom_nodes
|
||||
git clone https://github.com/kuriot/ComfyUI_node_Lilly.git
|
||||
```
|
||||
or https://github.com/lilly1987/ComfyUI_node_Lilly/archive/refs/heads/main.zip install this like
|
||||
|
||||

|
||||
|
||||
|
||||
## wildcards
|
||||
|
||||
### ex
|
||||
### ex - wildcard
|
||||
|
||||
- form
|
||||
- form :
|
||||
a{__b__|{c|}|{__d__|e|}|f|}g____ __my__
|
||||
|
||||
- to
|
||||
- to :
|
||||
aeg __quality_my__, __breasts__, { |__character_dress__|__dress_my__}, __shoulder__, {high heels,| } {choker,| } {<lora:__lora_lst__:__rora_num__>,| } NSFW, __NSFW_my__, { |__style_my__,}
|
||||
|
||||
```
|
||||
@@ -28,6 +38,30 @@ ex : {3$$a1|{b2|c3|}|d4|{-$$|f|g}|{-2$$h||i}|{1-$$j|k|}}/{$$l|m|}/{0$$n|}
|
||||
{-$$a|b|c} -> {0-3$$a|b|c} 0-max
|
||||
```
|
||||
|
||||
### ex - wildcard text file use
|
||||
|
||||
- ~/a/b.txt
|
||||
```
|
||||
1
|
||||
```
|
||||
- ~/b.txt
|
||||
```
|
||||
2
|
||||
```
|
||||
|
||||
- __b__ to 1 or 2
|
||||
- __/b__ to 2
|
||||
- __/a/b__ to 1
|
||||
- __?b__ to 2
|
||||
- __*__ to 1 or 2
|
||||
|
||||
### filename pattern matching
|
||||
- \* is matches everything
|
||||
- ? is matches any single character
|
||||
- \[seq\] is matches any character in seq
|
||||
- \[!seq\] is matches any character not in seq
|
||||
- reference https://docs.python.org/3/library/fnmatch.html
|
||||
|
||||
### run sample
|
||||
|
||||
```
|
||||
@@ -46,18 +80,12 @@ w.card_path=os.path.dirname(__file__)+"\\wildcards\\**\\*.txt"
|
||||
print(w.run("a{__b__|{c|}|{__d__|e|}|f|}g____ __my__"))
|
||||
```
|
||||
|
||||
###
|
||||
|
||||
```
|
||||
wildcards.py # modul file
|
||||
wildcards/*.txt # wildcards file
|
||||
wildcards/**/*.txt # wildcards file
|
||||
```
|
||||
|
||||
### txt file (UTF8)
|
||||
|
||||
### txt file (supports .txt files in different encodings.)
|
||||
from
|
||||
```
|
||||
# 주석
|
||||
# 주석 comment
|
||||
a,b
|
||||
{b|c|__anotherfile__}
|
||||
__anotherfile__
|
||||
@@ -108,6 +136,13 @@ wildcards.run("{9$$-$$a|b|c}",True)
|
||||
|
||||

|
||||
|
||||
### VAELoaderText , LoraLoaderText , CheckpointLoaderSimpleText
|
||||
|
||||
- support file name Wildcard(?*)
|
||||
|
||||

|
||||

|
||||
|
||||
|
||||
### random_sampler_node.py
|
||||
|
||||
|
||||
+3
-1
@@ -2,6 +2,7 @@ from PIL import Image
|
||||
from PIL.PngImagePlugin import PngInfo
|
||||
import numpy as np
|
||||
import json
|
||||
import re
|
||||
|
||||
import time
|
||||
|
||||
@@ -44,6 +45,7 @@ class SaveImageSimple:
|
||||
#print("outputdir : " + outputdir , Colors.CYAN)
|
||||
|
||||
#print("len(images) : " + str(len(images)) , Colors.CYAN)
|
||||
filename_prefix=re.sub(r"[*]", "",filename_prefix)
|
||||
filename_prefix+=time.strftime('_%Y%m%d_%H%M%S')
|
||||
results = list()
|
||||
cnt=1
|
||||
@@ -58,7 +60,7 @@ class SaveImageSimple:
|
||||
for x in extra_pnginfo:
|
||||
metadata.add_text(x, json.dumps(extra_pnginfo[x]))
|
||||
if not os.path.exists(outputdir):
|
||||
print("makedirs : " + outputdir , Colors.CYAN)
|
||||
print("makedirs : " + outputdir )
|
||||
os.makedirs(outputdir)
|
||||
filename=filename_prefix+f"_{cnt:05}_.png"
|
||||
filename=os.path.join(outputdir, filename)
|
||||
|
||||
+13
-11
@@ -27,6 +27,8 @@ import numpy as np
|
||||
#print(f"SimpleSampler __file__ {os.path.splitext(os.path.basename(__file__))[0]}")
|
||||
|
||||
import os
|
||||
|
||||
|
||||
if __name__ == os.path.splitext(os.path.basename(__file__))[0] or __name__ =='__main__':
|
||||
from ConsoleColor import print, console
|
||||
from wildcards import wildcards
|
||||
@@ -37,18 +39,18 @@ else:
|
||||
#print(os.path.basename(__file__))
|
||||
|
||||
#----------------------------
|
||||
wildcardsOn=True
|
||||
# wildcards support check
|
||||
wildcardsOn=False
|
||||
try:
|
||||
from wildcards import *
|
||||
wildcardsOn=True
|
||||
#wildcards.card_path=os.path.dirname(__file__)+"\\..\\wildcards\\**\\*.txt"
|
||||
print(f"import wildcards succ", style="bold GREEN" )
|
||||
except:
|
||||
print(f"import wildcards fail", style="bold RED")
|
||||
wildcardsOn=False
|
||||
err_msg = traceback.format_exc()
|
||||
print(err_msg)
|
||||
#wildcardsOn=False
|
||||
#try:
|
||||
# wildcardsOn=True
|
||||
# #wildcards.card_path=os.path.dirname(__file__)+"\\..\\wildcards\\**\\*.txt"
|
||||
# print(f"import wildcards succ", style="bold GREEN" )
|
||||
#except:
|
||||
# print(f"import wildcards fail", style="bold RED")
|
||||
# wildcardsOn=False
|
||||
# err_msg = traceback.format_exc()
|
||||
# print(err_msg)
|
||||
|
||||
|
||||
def encode(clip, text):
|
||||
|
||||
+4
-1
@@ -27,8 +27,11 @@ class VAELoaderText:
|
||||
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)
|
||||
sd = comfy.utils.load_torch_file(vae_path)
|
||||
vae = comfy.sd.VAE(sd=sd)
|
||||
return (vae,)
|
||||
except Exception as e:
|
||||
console.print_exception()
|
||||
|
||||
@@ -26,27 +26,27 @@ print()
|
||||
"""
|
||||
|
||||
py_name=os.path.basename(__file__)
|
||||
print("os.path.basename(__file__) : ",py_name, style="bold CYAN")
|
||||
#print("os.path.basename(__file__) : ",py_name, style="bold CYAN")
|
||||
|
||||
absFilePath = os.path.abspath(__file__)
|
||||
print("os.path.abspath(__file__) : " , absFilePath , style="bold CYAN")
|
||||
#print("os.path.abspath(__file__) : " , absFilePath , style="bold CYAN")
|
||||
|
||||
realFilePath = os.path.realpath(__file__)
|
||||
print("os.path.abspath(__file__) : " + realFilePath , style="bold CYAN")
|
||||
#print("os.path.abspath(__file__) : " + realFilePath , style="bold CYAN")
|
||||
|
||||
normpath=os.path.normpath(__file__)
|
||||
print("os.path.normpath(__file__) : " + normpath , style="bold CYAN")
|
||||
#print("os.path.normpath(__file__) : " + normpath , style="bold CYAN")
|
||||
|
||||
subfolder = os.path.dirname(normpath)
|
||||
print("os.path.dirname(normpath) : " + subfolder , style="bold CYAN")
|
||||
#print("os.path.dirname(normpath) : " + subfolder , style="bold CYAN")
|
||||
|
||||
filename = os.path.basename(normpath)
|
||||
print("os.path.basename(normpath) : " + filename , style="bold CYAN")
|
||||
#print("os.path.basename(normpath) : " + filename , style="bold CYAN")
|
||||
|
||||
mainFile = os.path.abspath(sys.modules['__main__'].__file__)
|
||||
print("os.path.abspath(sys.modules\['__main__'].__file__) : " + mainFile ,style="bold CYAN")
|
||||
#print("os.path.abspath(sys.modules\['__main__'].__file__) : " + mainFile ,style="bold CYAN")
|
||||
mainfolder = os.path.dirname(mainFile)
|
||||
print("os.path.dirname(mainFile) : " + mainfolder , style="bold CYAN")
|
||||
#print("os.path.dirname(mainFile) : " + mainfolder , style="bold CYAN")
|
||||
|
||||
def check_name(kind,name,supported_extensions):
|
||||
for ext in supported_extensions:
|
||||
@@ -86,7 +86,7 @@ def getFullPath(p,k,el=["safetensors","ckpt","pt"]):
|
||||
if os.path.isabs(p):
|
||||
path=p
|
||||
else:
|
||||
path=os.path.join(models_dir,k+"/**/",p)
|
||||
path=os.path.join(models_dir,k,"**",p)
|
||||
#print(f"path : ", path)
|
||||
t=False
|
||||
for e in el:
|
||||
|
||||
+63
-23
@@ -1,7 +1,10 @@
|
||||
import glob, sys
|
||||
import os
|
||||
import glob
|
||||
import sys
|
||||
import random
|
||||
import re
|
||||
import os
|
||||
import fnmatch
|
||||
|
||||
if __name__ == os.path.splitext(os.path.basename(__file__))[0] or __name__ =='__main__':
|
||||
from ConsoleColor import print, console, ccolor
|
||||
else:
|
||||
@@ -10,11 +13,25 @@ else:
|
||||
#print(os.path.basename(__file__))
|
||||
#print(os.getcwd())
|
||||
|
||||
import subprocess
|
||||
import pkg_resources
|
||||
|
||||
required = {'chardet'}
|
||||
installed = {pkg.key for pkg in pkg_resources.working_set}
|
||||
missing = required - installed
|
||||
|
||||
if missing:
|
||||
python = sys.executable
|
||||
subprocess.check_call([python, '-m', 'pip', 'install', *missing], stdout=subprocess.DEVNULL)
|
||||
|
||||
import chardet
|
||||
|
||||
|
||||
# ============================================================
|
||||
class wildcards:
|
||||
|
||||
# 가져올 파일 목록
|
||||
card_path=os.path.dirname(__file__)+"\\..\\..\\wildcards\\**\\*.txt"
|
||||
card_path = os.path.join(os.path.dirname(__file__), "..", "..", "wildcards", "**", "*.txt")
|
||||
#card_path=f"{os.getcwd()}\\wildcards\\**\\*.txt"
|
||||
print(f"wildcards card_path : ", card_path , style="bold CYAN")
|
||||
|
||||
@@ -101,12 +118,16 @@ class wildcards:
|
||||
|
||||
# 카드 중에서 가져오기
|
||||
def card(match):
|
||||
#print(f"card i : {match.group(2)}")
|
||||
if match.group(2) in wildcards.cards :
|
||||
r=random.choice(wildcards.cards[match.group(2)])
|
||||
#print(f"card in : {match.group(2)}")
|
||||
lst=fnmatch.filter(wildcards.cards, match.group(2))
|
||||
if len(lst)>0:
|
||||
#print(f"card lst : {lst}")
|
||||
cd=random.choice(lst)
|
||||
#print(f"card get : {cd}")
|
||||
r=random.choice(wildcards.cards[cd])
|
||||
else :
|
||||
r= match.group(2)
|
||||
#print(f"card r : {r}")
|
||||
#print(f"card out : {r}")
|
||||
return r
|
||||
|
||||
|
||||
@@ -136,20 +157,32 @@ class wildcards:
|
||||
#print(f"files : {files}")
|
||||
|
||||
for file in files:
|
||||
basename = os.path.basename(file)
|
||||
file_name = os.path.splitext(basename)[0]
|
||||
basenameAll = os.path.basename(file)
|
||||
basename = os.path.relpath(file, os.path.dirname(__file__)).replace("\\", "/").replace("../../wildcards/", "")
|
||||
#print(f"basenameAll : {basenameAll}")
|
||||
#print(f"basename : {basename}")
|
||||
file_nameAll = os.path.splitext(basenameAll)[0]
|
||||
file_name = "/"+os.path.splitext(basename)[0]
|
||||
#print(f"file_nameAll : {file_nameAll}")
|
||||
#print(f"file_name : {file_name}")
|
||||
if not file_nameAll in cards:
|
||||
cards[file_nameAll]=[]
|
||||
if not file_name in cards:
|
||||
cards[file_name]=[]
|
||||
#print(f"file_name : {file_name}")
|
||||
f = open(file, 'r', encoding='UTF8')
|
||||
lines = f.readlines()
|
||||
for line in lines:
|
||||
line=line.strip()
|
||||
# 주석 빈줄 제외
|
||||
if line.startswith("#") or len(line)==0:
|
||||
continue
|
||||
cards[file_name]+=[line]
|
||||
#print(f"line : {line}")
|
||||
with open(file, "rb") as f:
|
||||
raw_data = f.read()
|
||||
encoding = chardet.detect(raw_data)["encoding"]
|
||||
with open(file, "r", encoding=encoding) as f:
|
||||
lines = f.readlines()
|
||||
for line in lines:
|
||||
line=line.strip()
|
||||
# 주석 빈줄 제외
|
||||
if line.startswith("#") or len(line)==0:
|
||||
continue
|
||||
cards[file_nameAll]+=[line]
|
||||
cards[file_name]+=[line]
|
||||
#print(f"line : {line}")
|
||||
wildcards.cards=cards
|
||||
print(f"[cyan]cards file count : [/cyan]", len(wildcards.cards))
|
||||
#print(f"cards : {cards.keys()}")
|
||||
@@ -157,7 +190,7 @@ class wildcards:
|
||||
|
||||
# 실행기
|
||||
def run(text,load=False):
|
||||
if text is None or type(text) is not str:
|
||||
if text is None or not isinstance(text, str):
|
||||
print("[red]text is not str : [/red]",text)
|
||||
return None
|
||||
if not wildcards.is_card_Load or load:
|
||||
@@ -175,9 +208,16 @@ class wildcards:
|
||||
#print(__name__)
|
||||
#if __name__ == '__main__' :
|
||||
# 테스트용
|
||||
test="{3$$a1|{b2|c3|}|d4|{-$$|f|g}|{-2$$h||i}|{1-$$j|k|}}/{$$l|m|}/{0$$n|}/{9$$-$$a|b|c}/{9$$ {and|or} $$a|b|c}"
|
||||
print("[green]wildcards test : [/green]",wildcards.run(test),style="reset")
|
||||
#test="{3$$a1|{b2|c3|}|d4|{-$$|f|g}|{-2$$h||i}|{1-$$j|k|}}/{$$l|m|}/{0$$n|}/{9$$-$$a|b|c}/{9$$ {and|or} $$a|b|c}"
|
||||
#print("[green]wildcards test : [/green]",wildcards.run(test),style="reset")
|
||||
#print("wildcards test : "+wildcards.run("{9$$a|b}"))
|
||||
#print("[green]wildcards test : [/green]",wildcards.run("__my__"))
|
||||
print("wildcards test : "+wildcards.run("{9$$-$$a|b|c}"))
|
||||
print("wildcards test : "+wildcards.run("{9$$ {and|or} $$a|b|c}"))
|
||||
#print("wildcards test : "+wildcards.run("{9$$-$$a|b|c}"))
|
||||
#print("wildcards test : "+wildcards.run("{9$$ {and|or} $$a|b|c}"))
|
||||
#print("wildcards test : "+wildcards.run("{{slender,|} {nature,|} {curvy,|} {thin,|} {narrow,|} {slim,|} {mini,|} {little,|}| {|very }{-$$ $$thin|slender|narrow|slim|little|skinny|mini} body, }"))
|
||||
print("wildcards test : "+wildcards.run("__aest__"))
|
||||
print("wildcards test : "+wildcards.run("__*test__"))
|
||||
print("wildcards test : "+wildcards.run("__?est__"))
|
||||
print("wildcards test : "+wildcards.run("__test__"))
|
||||
print("wildcards test : "+wildcards.run("__/test__"))
|
||||
print("wildcards test : "+wildcards.run("__/0/test__"))
|
||||
|
||||
Reference in New Issue
Block a user