From 4596db540cf0a3eab696cfac4062289f5cb94a24 Mon Sep 17 00:00:00 2001 From: lilly Date: Sat, 25 Mar 2023 02:53:15 +0900 Subject: [PATCH] seed wildcards --- CLIPTextEncodeWildcards.py | 27 ++++++++++++++++++++++++++- __init__.py | 8 +++++--- mypath.py | 24 +----------------------- wildcards.py | 6 +++--- 4 files changed, 35 insertions(+), 30 deletions(-) diff --git a/CLIPTextEncodeWildcards.py b/CLIPTextEncodeWildcards.py index e4296a7..d43468d 100644 --- a/CLIPTextEncodeWildcards.py +++ b/CLIPTextEncodeWildcards.py @@ -18,7 +18,11 @@ 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" @@ -28,3 +32,24 @@ class CLIPTextEncodeWildcards: r=wildcards.run(text) print(f"[green]encode : [/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) + r=wildcards.run(text) + print(f"[green]encode : [/green]",r) + return ([[clip.encode(r), {}]], ) diff --git a/__init__.py b/__init__.py index eae3064..9a47fed 100644 --- a/__init__.py +++ b/__init__.py @@ -44,11 +44,13 @@ if not md.startswith("custom_nodes."): NODE_CLASS_MAPPINGS = { } - def add(name): + def add(name,list=None): #print(f"Load : {name}") try: pkg = importlib.import_module(f"{md}.{name}") NODE_CLASS_MAPPINGS[name]=eval(f"pkg.{name}") + if type(list) is str: + NODE_CLASS_MAPPINGS[list]=eval(f"pkg.{list}") print(f"Load ok : {name}", style="bold green") except Exception: console.print_exception() @@ -57,7 +59,7 @@ if not md.startswith("custom_nodes."): add("CheckpointLoaderRandom") add("CheckpointLoaderSimpleText") - add("CLIPTextEncodeWildcards") + add("CLIPTextEncodeWildcards","CLIPTextEncodeWildcards2") add("LoraLoaderText") add("LoraLoaderTextRandom") add("Random_Sampler") @@ -66,4 +68,4 @@ if not md.startswith("custom_nodes."): add("SaveImageSimple") #add("test") - console.rule(" finit end ", style="bold green") \ No newline at end of file + console.rule(" init end ", style="bold green") \ No newline at end of file diff --git a/mypath.py b/mypath.py index dafa465..d43ef3f 100644 --- a/mypath.py +++ b/mypath.py @@ -1,13 +1,11 @@ import sys import json +import ast import os 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 @@ -47,23 +45,3 @@ mainFile = os.path.abspath(sys.modules['__main__'].__file__) 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") - -def jsondic(full,dic,update=False): - - 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) - - return path - \ No newline at end of file diff --git a/wildcards.py b/wildcards.py index 30a4d03..bcf4603 100644 --- a/wildcards.py +++ b/wildcards.py @@ -166,7 +166,7 @@ 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|}" +#print("[green]wildcards test : [/green]",wildcards.run(test)) #print("wildcards test : "+wildcards.run("{9$$a|b}")) -print("[green]wildcards test : [/green]",wildcards.run("__my__")) +#print("[green]wildcards test : [/green]",wildcards.run("__my__"))