added Readme + some updates

This commit is contained in:
MariusKM
2024-06-21 10:13:26 +02:00
parent d3ed002cf1
commit 8f96b916af
9 changed files with 114 additions and 2 deletions
+78
View File
@@ -0,0 +1,78 @@
class BadmanCLIPTextEncodeSDXLRegion:
def __init__(self):
pass
@classmethod
def INPUT_TYPES(s):
return {"required": {
"width": ("INT", {"default": 1024.0, "min": 0, "max": 4096}),
"height": ("INT", {"default": 1024.0, "min": 0, "max": 4096}),
"crop_w": ("INT", {"default": 0, "min": 0, "max": 4096}),
"crop_h": ("INT", {"default": 0, "min": 0, "max": 4096}),
"target_width": ("INT", {"default": 1024.0, "min": 0, "max": 4096}),
"target_height": ("INT", {"default": 1024.0, "min": 0, "max": 4096}),
"text_g": ("STRING", {"multiline": True, "dynamicPrompts": True}), "clip": ("CLIP", ),
"text_l": ("STRING", {"multiline": True, "dynamicPrompts": True}), "clip": ("CLIP", ),
}}
RETURN_TYPES = ("CLIPREGION",)
FUNCTION = "encode"
CATEGORY = "Badman"
def init_prompt(self, clip, text_g):
tokens = clip.tokenize(text_g, return_word_ids=True)
return ({
"clip" : clip,
"base_tokens" : tokens,
"regions" : [],
"targets" : [],
"weights" : [],
},)
def encode(self, clip, width, height, crop_w, crop_h, target_width, target_height, text_g, text_l):
# Tokenize the global text and store in the "g" key of tokens
tokens_g = clip.tokenize(text_g, return_word_ids=True)
tokens_l = clip.tokenize(text_l, return_word_ids=True)
# Initialize the tokens dictionary with proper keys
tokens = {
"g": tokens_g.get("g", tokens_g), # Fallback to tokens_g if "g" key is not present
"l": tokens_l.get("l", tokens_l) # Fallback to tokens_l if "l" key is not present
}
# Ensure the length of tokens["l"] matches the length of tokens["g"]
if len(tokens["l"]) != len(tokens["g"]):
empty = clip.tokenize("")
empty_l = empty.get("l", empty) # Fallback to empty if "l" key is not present
empty_g = empty.get("g", empty) # Fallback to empty if "g" key is not present
while len(tokens["l"]) < len(tokens["g"]):
tokens["l"] += empty_l
while len(tokens["l"]) > len(tokens["g"]):
tokens["g"] += empty_g
print(tokens)
return ({
"clip": clip,
"base_tokens": tokens,
"regions": [],
"targets": [],
"weights": [],
},)
"""def encode(self, clip, width, height, crop_w, crop_h, target_width, target_height, text_g, text_l):
tokens = clip.tokenize(text_g)
tokens["l"] = clip.tokenize(text_l)["l"]
if len(tokens["l"]) != len(tokens["g"]):
empty = clip.tokenize("")
while len(tokens["l"]) < len(tokens["g"]):
tokens["l"] += empty["l"]
while len(tokens["l"]) > len(tokens["g"]):
tokens["g"] += empty["g"]
return ({
"clip" : clip,
"base_tokens" : tokens,
"regions" : [],
"targets" : [],
"weights" : [],
},)"""
+31 -2
View File
@@ -36,6 +36,7 @@ class ConcatString:
"multiline": False,
"default": "World"
}),
"newline": ("BOOLEAN",),
},
}
@@ -44,8 +45,36 @@ class ConcatString:
FUNCTION = "execute"
CATEGORY = "Badman"
def execute(self, string_field_0, string_field_1):
return (string_field_0 + string_field_1,)
def execute(self, string_field_0, string_field_1,newline):
if newline:
return (string_field_0 +"\n"+string_field_1,)
else:
return (string_field_0 + string_field_1,)
class SelectString:
def __init__(self):
pass
@classmethod
def INPUT_TYPES(s):
return {
"required": {
"string_List": ("STRING", {
}),
"Index": ("INT", {
"default": 0,
"min": 0}),
},
}
INPUT_IS_LIST = True
RETURN_TYPES = ("STRING",)
RETURN_NAMES = ("STRING",)
FUNCTION = "execute"
CATEGORY = "Badman"
def execute(self,string_List ,Index ):
return (string_List[Index[0]],)
class BadmanString:
View File
+5
View File
@@ -1,6 +1,7 @@
from .BadmanStrings import *
from .BadmanImage import *
from .BadmanNumbers import *
from .BadmanConditioning import *
NODE_CLASS_MAPPINGS = {
@@ -11,6 +12,8 @@ NODE_CLASS_MAPPINGS = {
"Badman_Print": BadmanPrint,
"BadmanIO" : BadmanIOConfigurator,
"BadmanIntUtil" : BadmanIntUtil,
"BadmanCLIPTextEncodeSDXLRegion" : BadmanCLIPTextEncodeSDXLRegion,
"BadmanStringSelect" : SelectString,
}
NODE_DISPLAY_NAME_MAPPINGS = {
@@ -21,4 +24,6 @@ NODE_DISPLAY_NAME_MAPPINGS = {
"Badman_Print": "Print (Badman)",
"Badman_IO": "IO Config (Badman)",
"BadmanIntUtil": "Int Math (Badman)",
"BadmanStringSelect": "Select String from List (Badman)",
"BadmanCLIPTextEncodeSDXLRegion" : "CLIPTextEncodeSDXLRegion (Badman)",
}
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.