Compare commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
222c0b2c65 | ||
|
|
9c8ecab6fc | ||
|
|
a5e946261e | ||
|
|
37851ff4ce | ||
|
|
3472043e28 | ||
|
|
f7d40d0b2d | ||
|
|
98ae062bc0 | ||
|
|
f4d889bc74 | ||
|
|
61c0536251 | ||
|
|
fabcf37fb3 | ||
|
|
67dce2659e | ||
|
|
4596db540c |
@@ -18,13 +18,71 @@ else:
|
|||||||
class CLIPTextEncodeWildcards:
|
class CLIPTextEncodeWildcards:
|
||||||
@classmethod
|
@classmethod
|
||||||
def INPUT_TYPES(s):
|
def INPUT_TYPES(s):
|
||||||
return {"required": {"text": ("STRING", {"multiline": True}), "clip": ("CLIP", )}}
|
return {
|
||||||
|
"required": {
|
||||||
|
"text": ("STRING", {"multiline": True}), "clip": ("CLIP", )
|
||||||
|
}
|
||||||
|
}
|
||||||
RETURN_TYPES = ("CONDITIONING",)
|
RETURN_TYPES = ("CONDITIONING",)
|
||||||
FUNCTION = "encode"
|
FUNCTION = "encode"
|
||||||
|
|
||||||
CATEGORY = "conditioning"
|
CATEGORY = "conditioning"
|
||||||
|
|
||||||
def encode(self, clip, text):
|
def encode(self, clip, text):
|
||||||
|
print(f"[green]text : [/green]",text)
|
||||||
r=wildcards.run(text)
|
r=wildcards.run(text)
|
||||||
print(f"[green]encode : [/green]",r)
|
print(f"[green]result : [/green]",r)
|
||||||
return ([[clip.encode(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), {}]], )
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
@@ -1,14 +1,15 @@
|
|||||||
import os
|
import os
|
||||||
import comfy.sd
|
import comfy.sd
|
||||||
from nodes import *
|
from nodes import *
|
||||||
import folder_paths
|
from folder_paths import *
|
||||||
import random
|
import random
|
||||||
from .check_name import *
|
|
||||||
import os
|
import os
|
||||||
if __name__ == os.path.splitext(os.path.basename(__file__))[0] :
|
if __name__ == os.path.splitext(os.path.basename(__file__))[0] :
|
||||||
from ConsoleColor import print, console
|
from ConsoleColor import print, console
|
||||||
|
from mypath import *
|
||||||
else:
|
else:
|
||||||
from .ConsoleColor import print, console
|
from .ConsoleColor import print, console
|
||||||
|
from .mypath import *
|
||||||
|
|
||||||
#print(__file__)
|
#print(__file__)
|
||||||
#print(os.path.basename(__file__))
|
#print(os.path.basename(__file__))
|
||||||
@@ -34,10 +35,19 @@ class CheckpointLoaderSimpleText:
|
|||||||
CATEGORY = "loaders"
|
CATEGORY = "loaders"
|
||||||
|
|
||||||
def load_checkpoint(self, ckpt_name, output_vae=True, output_clip=True):
|
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:
|
if ckpt_path is None:
|
||||||
print(f"{ckpt_name} 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:
|
try:
|
||||||
out = comfy.sd.load_checkpoint_guess_config(ckpt_path, output_vae=True, output_clip=True, embedding_directory=folder_paths.get_folder_paths("embeddings"))
|
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
|
return out
|
||||||
|
|||||||
+9
-1
@@ -12,7 +12,15 @@ if missing:
|
|||||||
subprocess.check_call([python, '-m', 'pip', 'install', *missing], stdout=subprocess.DEVNULL)
|
subprocess.check_call([python, '-m', 'pip', 'install', *missing], stdout=subprocess.DEVNULL)
|
||||||
|
|
||||||
from rich.console import Console
|
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
|
print=console.log
|
||||||
"""
|
"""
|
||||||
print("test", style="bold white on blue")
|
print("test", style="bold white on blue")
|
||||||
|
|||||||
@@ -3,7 +3,12 @@ import comfy.sd
|
|||||||
from nodes import *
|
from nodes import *
|
||||||
import folder_paths
|
import folder_paths
|
||||||
import random
|
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:
|
class LoraLoaderTextRandom:
|
||||||
@classmethod
|
@classmethod
|
||||||
|
|||||||
@@ -72,18 +72,41 @@ __anotherfile__
|
|||||||
|
|
||||||
## for ComfyUI
|
## for ComfyUI
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
### CLIPTextEncodeWildcards
|
||||||
|
|
||||||
|
- CLIPTextEncodeWildcards : no seed
|
||||||
|
- CLIPTextEncodeWildcards : seed
|
||||||
|
|
||||||

|

|
||||||
|
|
||||||
|
|
||||||
|
### SimpleSampler+modelVAE
|
||||||
|
|
||||||
|
- include wildcards
|
||||||
|
|
||||||
|

|
||||||
|
|
||||||
|
|
||||||
|
### SimpleSampler
|
||||||
|
|
||||||
|
- include wildcards
|
||||||
|
|
||||||
|

|
||||||
|
|
||||||
|
|
||||||
|
### SimpleSamplerVAE
|
||||||
|
|
||||||
## random_sampler_node.py
|
- include wildcards
|
||||||
|
|
||||||
|

|
||||||
|
|
||||||
|
|
||||||
|
### random_sampler_node.py
|
||||||
|
|
||||||

|

|
||||||
|
|
||||||
## VAELoaderDecode.py
|
### VAELoaderDecode.py
|
||||||
|
|
||||||

|

|
||||||
|
|||||||
+113
-20
@@ -17,7 +17,9 @@ import hashlib
|
|||||||
import copy
|
import copy
|
||||||
import traceback
|
import traceback
|
||||||
|
|
||||||
|
|
||||||
from PIL import Image
|
from PIL import Image
|
||||||
|
from nodes import common_ksampler
|
||||||
from PIL.PngImagePlugin import PngInfo
|
from PIL.PngImagePlugin import PngInfo
|
||||||
import numpy as np
|
import numpy as np
|
||||||
|
|
||||||
@@ -25,10 +27,12 @@ import numpy as np
|
|||||||
#print(f"SimpleSampler __file__ {os.path.splitext(os.path.basename(__file__))[0]}")
|
#print(f"SimpleSampler __file__ {os.path.splitext(os.path.basename(__file__))[0]}")
|
||||||
|
|
||||||
import os
|
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 ConsoleColor import print, console
|
||||||
|
from wildcards import wildcards
|
||||||
else:
|
else:
|
||||||
from .ConsoleColor import print, console
|
from .ConsoleColor import print, console
|
||||||
|
from .wildcards import wildcards
|
||||||
#print(__file__)
|
#print(__file__)
|
||||||
#print(os.path.basename(__file__))
|
#print(os.path.basename(__file__))
|
||||||
|
|
||||||
@@ -46,6 +50,46 @@ except:
|
|||||||
err_msg = traceback.format_exc()
|
err_msg = traceback.format_exc()
|
||||||
print(err_msg)
|
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:
|
class SimpleSampler:
|
||||||
@classmethod
|
@classmethod
|
||||||
@@ -54,39 +98,88 @@ class SimpleSampler:
|
|||||||
{
|
{
|
||||||
"model": ("MODEL",),
|
"model": ("MODEL",),
|
||||||
#"positive": ("CONDITIONING", ),
|
#"positive": ("CONDITIONING", ),
|
||||||
"positive": ("STRING", {"multiline": True}), "clip": ("CLIP", ),
|
"clip": ("CLIP", ),
|
||||||
|
"vae": ("VAE", ),
|
||||||
|
"positive": ("STRING", {"multiline": True}),
|
||||||
#"negative": ("CONDITIONING", ),
|
#"negative": ("CONDITIONING", ),
|
||||||
"negative": ("STRING", {"multiline": True}), "clip": ("CLIP", ),
|
"negative": ("STRING", {"multiline": True}),
|
||||||
"width": ("INT", {"default": 512, "min": 64, "max": 4096, "step": 64}),
|
"width": ("INT", {"default": 512, "min": 64, "max": 4096, "step": 64}),
|
||||||
"height": ("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}),
|
"batch_size": ("INT", {"default": 1, "min": 1, "max": 64}),
|
||||||
"seed": ("INT", {"default": 0, "min": 0, "max": 0xffffffffffffffff}),
|
"seed": ("INT", {"default": 0, "min": 0, "max": 0xffffffffffffffff}),
|
||||||
"steps": ("INT", {"default": 20, "min": 1, "max": 10000}),
|
"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, ),
|
"sampler_name": (comfy.samplers.KSampler.SAMPLERS, ),
|
||||||
"scheduler": (comfy.samplers.KSampler.SCHEDULERS, ),
|
"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}),
|
"denoise": ("FLOAT", {"default": 1.0, "min": 0.0, "max": 1.0, "step": 0.01}),
|
||||||
}}
|
}}
|
||||||
|
RETURN_TYPES = ("IMAGE",)
|
||||||
RETURN_TYPES = ("LATENT",)
|
#RETURN_TYPES = ("LATENT",)
|
||||||
FUNCTION = "sample"
|
FUNCTION = "simple"
|
||||||
|
|
||||||
CATEGORY = "sampling"
|
CATEGORY = "sampling"
|
||||||
|
|
||||||
def encode(self, clip, text):
|
def simple(self,
|
||||||
if wildcardsOn:
|
model, seed, steps, cfg, sampler_name, scheduler,
|
||||||
text=wildcards.run(text)
|
clip,
|
||||||
return ([[clip.encode(text), {}]], )
|
vae,
|
||||||
|
positive, negative,
|
||||||
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,
|
|
||||||
width, height, denoise=1.0, batch_size=1
|
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
|
||||||
|
)
|
||||||
|
|
||||||
|
|||||||
+11
-5
@@ -44,11 +44,17 @@ if not md.startswith("custom_nodes."):
|
|||||||
NODE_CLASS_MAPPINGS = {
|
NODE_CLASS_MAPPINGS = {
|
||||||
}
|
}
|
||||||
|
|
||||||
def add(name):
|
def add(name,clist=None):
|
||||||
#print(f"Load : {name}")
|
#print(f"Load : {name}")
|
||||||
try:
|
try:
|
||||||
pkg = importlib.import_module(f"{md}.{name}")
|
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")
|
print(f"Load ok : {name}", style="bold green")
|
||||||
except Exception:
|
except Exception:
|
||||||
console.print_exception()
|
console.print_exception()
|
||||||
@@ -57,13 +63,13 @@ if not md.startswith("custom_nodes."):
|
|||||||
|
|
||||||
add("CheckpointLoaderRandom")
|
add("CheckpointLoaderRandom")
|
||||||
add("CheckpointLoaderSimpleText")
|
add("CheckpointLoaderSimpleText")
|
||||||
add("CLIPTextEncodeWildcards")
|
add("CLIPTextEncodeWildcards",["CLIPTextEncodeWildcards","CLIPTextEncodeWildcards2","CLIPTextEncodeWildcards3"])
|
||||||
add("LoraLoaderText")
|
add("LoraLoaderText")
|
||||||
add("LoraLoaderTextRandom")
|
add("LoraLoaderTextRandom")
|
||||||
add("Random_Sampler")
|
add("Random_Sampler")
|
||||||
add("VAELoaderDecode")
|
add("VAELoaderDecode")
|
||||||
add("SimpleSampler")
|
add("SimpleSampler",["SimpleSampler","SimpleSamplerVAE"])
|
||||||
add("SaveImageSimple")
|
add("SaveImageSimple")
|
||||||
#add("test")
|
#add("test")
|
||||||
|
|
||||||
console.rule(" finit end ", style="bold green")
|
console.rule(" init end ", style="bold green")
|
||||||
@@ -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('|'))
|
|
||||||
@@ -1,13 +1,12 @@
|
|||||||
import sys
|
import sys
|
||||||
import json
|
import json
|
||||||
import os
|
import ast
|
||||||
|
import os, glob
|
||||||
|
import random
|
||||||
if __name__ == os.path.splitext(os.path.basename(__file__))[0] :
|
if __name__ == os.path.splitext(os.path.basename(__file__))[0] :
|
||||||
from ConsoleColor import print, console
|
from ConsoleColor import print, console
|
||||||
else:
|
else:
|
||||||
from .ConsoleColor import print, console
|
from .ConsoleColor import print, console
|
||||||
#print(__file__)
|
|
||||||
#print(os.path.basename(__file__))
|
|
||||||
|
|
||||||
|
|
||||||
"""
|
"""
|
||||||
import psutil
|
import psutil
|
||||||
@@ -48,22 +47,35 @@ print("os.path.abspath(sys.modules\['__main__'].__file__) : " + mainFile ,style=
|
|||||||
mainfolder = os.path.dirname(mainFile)
|
mainfolder = os.path.dirname(mainFile)
|
||||||
print("os.path.dirname(mainFile) : " + mainfolder , style="bold CYAN")
|
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]
|
for ext in supported_extensions:
|
||||||
if not os.path.exists(path):
|
path = folder_paths.get_full_path(kind, name+ext)
|
||||||
os.makedirs(path)
|
if path is not None:
|
||||||
#with open(f"./RandomLoop/chars-{time.strftime('_%Y%m%d_%H%M%S')}.json", 'w', encoding='utf-8') as file:
|
return path
|
||||||
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
|
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)
|
||||||
|
|||||||
+16
-10
@@ -2,7 +2,7 @@ import glob, sys
|
|||||||
import random
|
import random
|
||||||
import re
|
import re
|
||||||
import os
|
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 ConsoleColor import print, console
|
||||||
else:
|
else:
|
||||||
from .ConsoleColor import print, console
|
from .ConsoleColor import print, console
|
||||||
@@ -20,7 +20,8 @@ class wildcards:
|
|||||||
|
|
||||||
# 정규식
|
# 정규식
|
||||||
#resub = re.compile(r"(\{)([^\{\}]*)(\})")
|
#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"(__)(.*?)(__)")
|
recard = re.compile(r"(__)(.*?)(__)")
|
||||||
|
|
||||||
# 카드 목록
|
# 카드 목록
|
||||||
@@ -33,17 +34,20 @@ class wildcards:
|
|||||||
#print(f"sub : {(match.groups())}")
|
#print(f"sub : {(match.groups())}")
|
||||||
try:
|
try:
|
||||||
#m=match.group(2)
|
#m=match.group(2)
|
||||||
|
seperator=wildcards.seperator
|
||||||
s=match.group(3)
|
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:
|
if s is None:
|
||||||
return random.choice(m)
|
return random.choice(m)
|
||||||
c=len(m)
|
c=len(m)
|
||||||
n=int(match.group(4)) if match.group(4) else None
|
n=int(match.group(4)) if match.group(4) else None
|
||||||
if n:
|
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}")
|
#print(f"n : {n} ; {r}")
|
||||||
return r
|
return r
|
||||||
|
|
||||||
@@ -54,7 +58,7 @@ class wildcards:
|
|||||||
a=min(int(n1 if n1 else c), int(n2 if n2 else c),c)
|
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)
|
b=min(max(int(n1 if n1 else 0), int(n2 if n2 else 0)),c)
|
||||||
#print(f"ab : {a} ; {b}")
|
#print(f"ab : {a} ; {b}")
|
||||||
r=wildcards.seperator.join(
|
r=seperator.join(
|
||||||
random.sample(
|
random.sample(
|
||||||
m,
|
m,
|
||||||
random.randint(
|
random.randint(
|
||||||
@@ -65,7 +69,7 @@ class wildcards:
|
|||||||
#n1=int(match.group(5)) if not match.group(5) is None
|
#n1=int(match.group(5)) if not match.group(5) is None
|
||||||
#n2=int(match.group(6)) if not match.group(6) is None
|
#n2=int(match.group(6)) if not match.group(6) is None
|
||||||
else:
|
else:
|
||||||
r=wildcards.seperator.join(
|
r=seperator.join(
|
||||||
random.sample(
|
random.sample(
|
||||||
m,
|
m,
|
||||||
random.randint(
|
random.randint(
|
||||||
@@ -166,7 +170,9 @@ class wildcards:
|
|||||||
#print(__name__)
|
#print(__name__)
|
||||||
#if __name__ == '__main__' :
|
#if __name__ == '__main__' :
|
||||||
# 테스트용
|
# 테스트용
|
||||||
test="{3$$a1|{b2|c3|}|d4|{-$$|f|g}|{-2$$h||i}|{1-$$j|k|}}/{$$l|m|}/{0$$n|}"
|
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))
|
print("[green]wildcards test : [/green]",wildcards.run(test),style="reset")
|
||||||
#print("wildcards test : "+wildcards.run("{9$$a|b}"))
|
#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}"))
|
||||||
|
|||||||
Reference in New Issue
Block a user