16 Commits
Author SHA1 Message Date
lilly 01590a7839 Merge branch 'pr/5' 2023-04-05 20:05:02 +09:00
lilly cf91e6a57a msg 2023-04-05 19:53:40 +09:00
Filipe 1e7442625b Add suport for WAS text utils nodes 2023-04-04 19:26:02 -03:00
Filipe f8863c5cb2 Add TextWildcards 2023-04-04 19:06:33 -03:00
lilly 222c0b2c65 Update README.md 2023-04-02 17:22:27 +09:00
lilly 9c8ecab6fc Update README.md 2023-04-02 17:21:58 +09:00
lilly a5e946261e SimpleSamplerVAE add 2023-04-02 17:16:26 +09:00
lilly 37851ff4ce Update mypath.py 2023-03-30 17:11:11 +09:00
lilly 3472043e28 CLIPTextEncodeWildcards3 2023-03-30 15:22:18 +09:00
lilly f7d40d0b2d filenameget 2023-03-30 13:57:08 +09:00
lilly 98ae062bc0 clean 2023-03-28 21:21:32 +09:00
lilly f4d889bc74 Update ConsoleColor.py 2023-03-27 23:28:38 +09:00
lilly 61c0536251 Update wildcards.py 2023-03-27 22:31:55 +09:00
lilly fabcf37fb3 seperator support
{9$$ {and|or} $$a|b|c}
2023-03-27 21:56:58 +09:00
lilly 67dce2659e Update README.md 2023-03-25 03:03:17 +09:00
lilly 4596db540c seed wildcards 2023-03-25 02:53:15 +09:00
11 changed files with 331 additions and 98 deletions
+60 -2
View File
@@ -18,13 +18,71 @@ else:
class CLIPTextEncodeWildcards:
@classmethod
def INPUT_TYPES(s):
return {"required": {"text": ("STRING", {"multiline": True}), "clip": ("CLIP", )}}
return {
"required": {
"text": ("STRING", {"multiline": True}), "clip": ("CLIP", )
}
}
RETURN_TYPES = ("CONDITIONING",)
FUNCTION = "encode"
CATEGORY = "conditioning"
def encode(self, clip, text):
print(f"[green]text : [/green]",text)
r=wildcards.run(text)
print(f"[green]encode : [/green]",r)
print(f"[green]result : [/green]",r)
return ([[clip.encode(r), {}]], )
class CLIPTextEncodeWildcards2:
@classmethod
def INPUT_TYPES(s):
return {
"required": {
"text": ("STRING", {"multiline": True}), "clip": ("CLIP", ),
"seed": ("INT", {"default": 0, "min": 0, "max": 0xffffffffffffffff}),
}
}
RETURN_TYPES = ("CONDITIONING",)
FUNCTION = "encode"
CATEGORY = "conditioning"
def encode(self, seed, clip, text):
random.seed(seed)
print(f"[green]text : [/green]",text)
r=wildcards.run(text)
print(f"[green]result : [/green]",r)
return ([[clip.encode(r), {}]], )
class CLIPTextEncodeWildcards3:
@classmethod
def INPUT_TYPES(s):
return {
"required": {
"clip": ("CLIP", ),
"positive": ("STRING", {"multiline": True}),
"negative": ("STRING", {"multiline": True}),
"seed": ("INT", {"default": 0, "min": 0, "max": 0xffffffffffffffff}),
}
}
RETURN_TYPES = ("CONDITIONING","CONDITIONING")
FUNCTION = "encode"
CATEGORY = "conditioning"
def encode(self, seed, clip, positive, negative):
random.seed(seed)
print(f"[green]positive : [/green]",positive)
positive=wildcards.run(positive)
print(f"[green]result : [/green]",positive)
print(f"[green]negative : [/green]",negative)
negative=wildcards.run(negative)
print(f"[green]result : [/green]",negative)
return ([[clip.encode(positive), {}]], [[clip.encode(negative), {}]], )
+14 -4
View File
@@ -1,14 +1,15 @@
import os
import comfy.sd
from nodes import *
import folder_paths
from folder_paths import *
import random
from .check_name import *
import os
if __name__ == os.path.splitext(os.path.basename(__file__))[0] :
from ConsoleColor import print, console
from mypath import *
else:
from .ConsoleColor import print, console
from .mypath import *
#print(__file__)
#print(os.path.basename(__file__))
@@ -34,10 +35,19 @@ 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))
#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")
return
(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
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
+10 -1
View File
@@ -12,8 +12,17 @@ if missing:
subprocess.check_call([python, '-m', 'pip', 'install', *missing], stdout=subprocess.DEVNULL)
from rich.console import Console
console=Console()
from rich.theme import Theme
#console=Console(style="reset")
custom_theme = Theme({
"repr.path": "bright_blue",
"progress.percentage": "bright_blue",
"markdown.block_quote": "bright_blue",
"iso8601.time": "bright_blue"
})
console = Console(theme=custom_theme)
print=console.log
ccolor="bright_yellow"
"""
print("test", style="bold white on blue")
print("test", style="bold green")
+6 -1
View File
@@ -3,7 +3,12 @@ import comfy.sd
from nodes import *
import folder_paths
import random
from .check_name import *
if __name__ == os.path.splitext(os.path.basename(__file__))[0] :
from ConsoleColor import print, console
from mypath import *
else:
from .ConsoleColor import print, console
from .mypath import *
class LoraLoaderTextRandom:
@classmethod
+25 -2
View File
@@ -72,18 +72,41 @@ __anotherfile__
## for ComfyUI
### CLIPTextEncodeWildcards
- CLIPTextEncodeWildcards : no seed
- CLIPTextEncodeWildcards : seed
![2023-03-20 02 13 50](https://user-images.githubusercontent.com/20321215/226194627-b560c9e1-5dfa-49d9-8503-939693a8b119.png)
### SimpleSampler+modelVAE
- include wildcards
![SimpleSampler+modelVAE](https://user-images.githubusercontent.com/20321215/229340970-19c5c0f7-6281-430d-87ce-c2e512ead277.png)
### SimpleSampler
- include wildcards
![SimpleSampler](https://user-images.githubusercontent.com/20321215/229341019-0cea9dd8-0b03-4f4a-8f49-aff068b58faf.png)
### SimpleSamplerVAE
## random_sampler_node.py
- include wildcards
![SimpleSamplerVAE](https://user-images.githubusercontent.com/20321215/229341040-72d422d5-7904-41c3-a0e7-ac256ea40d0e.png)
### random_sampler_node.py
![2023-03-18 20 53 37](https://user-images.githubusercontent.com/20321215/226104447-eadd1d15-437f-4a41-b989-511390236d13.png)
## VAELoaderDecode.py
### VAELoaderDecode.py
![2023-03-18 20 52 27](https://user-images.githubusercontent.com/20321215/226104441-a13f49c6-c5be-4c70-b93e-f4ad984e9ff1.png)
+113 -20
View File
@@ -17,7 +17,9 @@ import hashlib
import copy
import traceback
from PIL import Image
from nodes import common_ksampler
from PIL.PngImagePlugin import PngInfo
import numpy as np
@@ -25,10 +27,12 @@ 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] :
if __name__ == os.path.splitext(os.path.basename(__file__))[0] or __name__ =='__main__':
from ConsoleColor import print, console
from wildcards import wildcards
else:
from .ConsoleColor import print, console
from .wildcards import wildcards
#print(__file__)
#print(os.path.basename(__file__))
@@ -46,6 +50,46 @@ except:
err_msg = traceback.format_exc()
print(err_msg)
def encode(clip, text):
if wildcardsOn:
text=wildcards.run(text)
return [[clip.encode(text), {}]]
def generate(width, height, batch_size=1):
latent = torch.zeros([batch_size, 4, height // 8, width // 8])
return {"samples":latent}
# RETURN_TYPES = ("LATENT",)
def decode(vae, samples):
return vae.decode(samples["samples"])
# RETURN_TYPES = ("IMAGE",)
def sample(
model, seed, steps, cfg, sampler_name, scheduler,
clip,
vae,
positive, negative,
#latent_image,
width, height, denoise=1.0, batch_size=1
):
samples=common_ksampler(
model, seed, steps, cfg, sampler_name, scheduler,
#positive,
encode(clip, positive),
#negative,
encode(clip, negative),
#latent_image,
generate( width, height, batch_size=1),
denoise=denoise)[0]
return (decode(vae,samples),)
def load_vae(vae_name):
vae_path = folder_paths.get_full_path("vae", vae_name)
vae = comfy.sd.VAE(ckpt_path=vae_path)
return vae
#----------------------------
class SimpleSampler:
@classmethod
@@ -54,39 +98,88 @@ class SimpleSampler:
{
"model": ("MODEL",),
#"positive": ("CONDITIONING", ),
"positive": ("STRING", {"multiline": True}), "clip": ("CLIP", ),
"clip": ("CLIP", ),
"vae": ("VAE", ),
"positive": ("STRING", {"multiline": True}),
#"negative": ("CONDITIONING", ),
"negative": ("STRING", {"multiline": True}), "clip": ("CLIP", ),
"negative": ("STRING", {"multiline": True}),
"width": ("INT", {"default": 512, "min": 64, "max": 4096, "step": 64}),
"height": ("INT", {"default": 512, "min": 64, "max": 4096, "step": 64}),
"batch_size": ("INT", {"default": 1, "min": 1, "max": 64}),
"seed": ("INT", {"default": 0, "min": 0, "max": 0xffffffffffffffff}),
"steps": ("INT", {"default": 20, "min": 1, "max": 10000}),
"cfg": ("FLOAT", {"default": 8.0, "min": 0.0, "max": 100.0}),
"cfg": ("FLOAT", {"default": 3.0, "min": 0.0, "max": 100.0}),
"sampler_name": (comfy.samplers.KSampler.SAMPLERS, ),
"scheduler": (comfy.samplers.KSampler.SCHEDULERS, ),
"latent_image": ("LATENT", ),
#"latent_image": ("LATENT", ),
"denoise": ("FLOAT", {"default": 1.0, "min": 0.0, "max": 1.0, "step": 0.01}),
}}
RETURN_TYPES = ("LATENT",)
FUNCTION = "sample"
RETURN_TYPES = ("IMAGE",)
#RETURN_TYPES = ("LATENT",)
FUNCTION = "simple"
CATEGORY = "sampling"
def encode(self, clip, text):
if wildcardsOn:
text=wildcards.run(text)
return ([[clip.encode(text), {}]], )
def generate(self, width, height, batch_size=1):
latent = torch.zeros([batch_size, 4, height // 8, width // 8])
return ({"samples":latent}, )
def sample(self,
model, seed, steps, cfg, sampler_name, scheduler, positive, negative, latent_image,
def simple(self,
model, seed, steps, cfg, sampler_name, scheduler,
clip,
vae,
positive, negative,
width, height, denoise=1.0, batch_size=1
):
return common_ksampler(model, seed, steps, cfg, sampler_name, scheduler, self.encode(clip, positive), elf.encode(clip, negative), self.generate( width, height, batch_size=1), denoise=denoise)
return sample(
model, seed, steps, cfg, sampler_name, scheduler,
clip,
vae,
positive, negative,
width, height, denoise, batch_size
)
#----------------------------
class SimpleSamplerVAE:
@classmethod
def INPUT_TYPES(s):
return {"required":
{
"model": ("MODEL",),
#"positive": ("CONDITIONING", ),
"clip": ("CLIP", ),
#"vae": ("VAE", ),
"vae_name": (folder_paths.get_filename_list("vae"), ),
"positive": ("STRING", {"multiline": True}),
#"negative": ("CONDITIONING", ),
"negative": ("STRING", {"multiline": True}),
"width": ("INT", {"default": 512, "min": 64, "max": 4096, "step": 64}),
"height": ("INT", {"default": 512, "min": 64, "max": 4096, "step": 64}),
"batch_size": ("INT", {"default": 1, "min": 1, "max": 64}),
"seed": ("INT", {"default": 0, "min": 0, "max": 0xffffffffffffffff}),
"steps": ("INT", {"default": 20, "min": 1, "max": 10000}),
"cfg": ("FLOAT", {"default": 3.0, "min": 0.0, "max": 100.0}),
"sampler_name": (comfy.samplers.KSampler.SAMPLERS, ),
"scheduler": (comfy.samplers.KSampler.SCHEDULERS, ),
#"latent_image": ("LATENT", ),
"denoise": ("FLOAT", {"default": 1.0, "min": 0.0, "max": 1.0, "step": 0.01}),
}}
RETURN_TYPES = ("IMAGE",)
#RETURN_TYPES = ("LATENT",)
FUNCTION = "simple"
CATEGORY = "sampling"
def simple(self,
model, seed, steps, cfg, sampler_name, scheduler,
clip,
vae_name,
positive, negative,
width, height, denoise=1.0, batch_size=1
):
return sample(
model, seed, steps, cfg, sampler_name, scheduler,
clip,
load_vae(vae_name),
positive, negative,
width, height, denoise, batch_size
)
+33
View File
@@ -0,0 +1,33 @@
import os, glob, sys
import random
import re
import os
if __name__ == os.path.splitext(os.path.basename(__file__))[0] or __name__ =='__main__':
from ConsoleColor import print, console
from wildcards import wildcards
else:
from .ConsoleColor import print, console
from .wildcards import wildcards
class TextWildcards:
@classmethod
def INPUT_TYPES(s):
return {
"required": {
"text": ("STRING", {"multiline": True}),
"seed": ("INT", {"default": 0, "min": 0, "max": 0xffffffffffffffff}),
}
}
RETURN_TYPES = ("STRING","ASCII")
FUNCTION = "encode"
CATEGORY = "utils"
def encode(self, seed, text):
random.seed(seed)
print(f"[green]text : [/green]",text)
r=wildcards.run(text)
print(f"[green]result : [/green]",r)
return ([r, r], )
+12 -5
View File
@@ -44,11 +44,17 @@ if not md.startswith("custom_nodes."):
NODE_CLASS_MAPPINGS = {
}
def add(name):
def add(name,clist=None):
#print(f"Load : {name}")
try:
pkg = importlib.import_module(f"{md}.{name}")
NODE_CLASS_MAPPINGS[name]=eval(f"pkg.{name}")
if clist is None:
NODE_CLASS_MAPPINGS[name]=eval(f"pkg.{name}")
elif type(clist) is str:
NODE_CLASS_MAPPINGS[clist]=eval(f"pkg.{clist}")
elif type(clist) is list:
for c in clist:
NODE_CLASS_MAPPINGS[c]=eval(f"pkg.{c}")
print(f"Load ok : {name}", style="bold green")
except Exception:
console.print_exception()
@@ -57,13 +63,14 @@ if not md.startswith("custom_nodes."):
add("CheckpointLoaderRandom")
add("CheckpointLoaderSimpleText")
add("CLIPTextEncodeWildcards")
add("CLIPTextEncodeWildcards",["CLIPTextEncodeWildcards","CLIPTextEncodeWildcards2","CLIPTextEncodeWildcards3"])
add("LoraLoaderText")
add("LoraLoaderTextRandom")
add("Random_Sampler")
add("VAELoaderDecode")
add("SimpleSampler")
add("SimpleSampler",["SimpleSampler","SimpleSamplerVAE"])
add("SaveImageSimple")
add("TextWildcards")
#add("test")
console.rule(" finit end ", style="bold green")
console.rule(" init end ", style="bold green")
-25
View File
@@ -1,25 +0,0 @@
import os
from folder_paths import supported_ckpt_extensions,supported_pt_extensions
import folder_paths
import random
def check_name(kind,name,supported_extensions):
for ext in supported_extensions:
if name.lower().endswith(ext):
path = folder_paths.get_full_path(kind, name)
if path is not None:
return path
for ext in supported_extensions:
path = folder_paths.get_full_path(kind, name+ext)
if path is not None:
return path
def check_name_ckpt(name):
return check_name("checkpoints",name,supported_ckpt_extensions)
def check_name_pt(kind,name):
return check_name(kind,name,supported_pt_extensions)
def name_split_choice(name):
return random.choice(name.split('|'))
+32 -20
View File
@@ -1,13 +1,12 @@
import sys
import json
import os
import ast
import os, glob
import random
if __name__ == os.path.splitext(os.path.basename(__file__))[0] :
from ConsoleColor import print, console
else:
from .ConsoleColor import print, console
#print(__file__)
#print(os.path.basename(__file__))
"""
import psutil
@@ -48,22 +47,35 @@ print("os.path.abspath(sys.modules\['__main__'].__file__) : " + mainFile ,style=
mainfolder = os.path.dirname(mainFile)
print("os.path.dirname(mainFile) : " + mainfolder , style="bold CYAN")
def jsondic(full,dic,update=False):
def check_name(kind,name,supported_extensions):
for ext in supported_extensions:
if name.lower().endswith(ext):
path = folder_paths.get_full_path(kind, name)
if path is not None:
return path
path=os.path.split(full)[0]
if not os.path.exists(path):
os.makedirs(path)
#with open(f"./RandomLoop/chars-{time.strftime('_%Y%m%d_%H%M%S')}.json", 'w', encoding='utf-8') as file:
if os.path.exists(full):
with open(full, 'r', encoding='utf-8') as file:
tmp=json.load(file)
if update:
dic.update(tmp)
else:
dic=(tmp)
else:
with open(full, 'w', encoding='utf-8') as file:
json.dump(dic, file, sort_keys=False, indent=4)
for ext in supported_extensions:
path = folder_paths.get_full_path(kind, name+ext)
if path is not None:
return path
return path
def check_name_ckpt(name):
return check_name("checkpoints",name,supported_ckpt_extensions)
def check_name_pt(kind,name):
return check_name(kind,name,supported_pt_extensions)
def name_split_choice(name):
return random.choice(name.split('|'))
#----------------------
def filenameget(v_path):
t_path=os.path.join(os.path.dirname(__file__),v_path)
print(t_path)
fullpaths=glob.glob(t_path, recursive=True)
print(fullpaths)
fullpath=random.choice(fullpaths)
name=os.path.basename(fullpath)
#r_path=[os.path.basename(fullpath) for fullpath in fullpaths]
return (name,fullpath)
+21 -13
View File
@@ -2,10 +2,10 @@ import glob, sys
import random
import re
import os
if __name__ == os.path.splitext(os.path.basename(__file__))[0] :
from ConsoleColor import print, console
if __name__ == os.path.splitext(os.path.basename(__file__))[0] or __name__ =='__main__':
from ConsoleColor import print, console, ccolor
else:
from .ConsoleColor import print, console
from .ConsoleColor import print, console , ccolor
#print(__file__)
#print(os.path.basename(__file__))
#print(os.getcwd())
@@ -20,7 +20,8 @@ class wildcards:
# 정규식
#resub = re.compile(r"(\{)([^\{\}]*)(\})")
resub = re.compile(r"(\{)(((\d+)|(\d+)?-(\d+)?)?\$\$)?([^\{\}]*)(\})")
#resub = re.compile(r"(\{)(((\d+)|(\d+)?-(\d+)?)?\$\$((.*)?\$\$)?)?([^\{\}]*)(\})")
resub = re.compile(r"(\{)(((\d+)|(\d+)?-(\d+)?)?\$\$(([^\{\}]*?)\$\$)?)?([^\{\}]*)(\})")
recard = re.compile(r"(__)(.*?)(__)")
# 카드 목록
@@ -33,17 +34,20 @@ class wildcards:
#print(f"sub : {(match.groups())}")
try:
#m=match.group(2)
seperator=wildcards.seperator
s=match.group(3)
m=match.group(7).split("|")
m=match.group(9).split("|")
p=match.group(8)
if p:
seperator=p
#print(f"m : {m}")
if s is None:
return random.choice(m)
c=len(m)
n=int(match.group(4)) if match.group(4) else None
if n:
r=wildcards.seperator.join(random.sample(m,min(n,c)))
r=seperator.join(random.sample(m,min(n,c)))
#print(f"n : {n} ; {r}")
return r
@@ -54,7 +58,7 @@ class wildcards:
a=min(int(n1 if n1 else c), int(n2 if n2 else c),c)
b=min(max(int(n1 if n1 else 0), int(n2 if n2 else 0)),c)
#print(f"ab : {a} ; {b}")
r=wildcards.seperator.join(
r=seperator.join(
random.sample(
m,
random.randint(
@@ -65,7 +69,7 @@ class wildcards:
#n1=int(match.group(5)) if not match.group(5) is None
#n2=int(match.group(6)) if not match.group(6) is None
else:
r=wildcards.seperator.join(
r=seperator.join(
random.sample(
m,
random.randint(
@@ -151,7 +155,9 @@ class wildcards:
# 실행기
def run(text):
if text is None or type(text) is not str:
print("[red]text is not str : [/red]",text)
return None
wildcards.card_load()
#print(f"text : {text}")
@@ -166,7 +172,9 @@ 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|}"
print("[green]wildcards test : [/green]",wildcards.run(test))
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("[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}"))