diff --git a/BadmanConditioning.py b/BadmanConditioning.py new file mode 100644 index 0000000..0a9c222 --- /dev/null +++ b/BadmanConditioning.py @@ -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" : [], + },)""" \ No newline at end of file diff --git a/BadmanStrings.py b/BadmanStrings.py index 8cf4e5a..9387928 100644 --- a/BadmanStrings.py +++ b/BadmanStrings.py @@ -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: diff --git a/README.md b/README.md new file mode 100644 index 0000000..e69de29 diff --git a/__init__.py b/__init__.py index 2ff1da3..c527da6 100644 --- a/__init__.py +++ b/__init__.py @@ -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)", } diff --git a/__pycache__/BadmanConditioning.cpython-311.pyc b/__pycache__/BadmanConditioning.cpython-311.pyc new file mode 100644 index 0000000..fd1ffe2 Binary files /dev/null and b/__pycache__/BadmanConditioning.cpython-311.pyc differ diff --git a/__pycache__/BadmanImage.cpython-311.pyc b/__pycache__/BadmanImage.cpython-311.pyc new file mode 100644 index 0000000..19a4bfb Binary files /dev/null and b/__pycache__/BadmanImage.cpython-311.pyc differ diff --git a/__pycache__/BadmanNumbers.cpython-311.pyc b/__pycache__/BadmanNumbers.cpython-311.pyc new file mode 100644 index 0000000..d56eb79 Binary files /dev/null and b/__pycache__/BadmanNumbers.cpython-311.pyc differ diff --git a/__pycache__/BadmanStrings.cpython-311.pyc b/__pycache__/BadmanStrings.cpython-311.pyc new file mode 100644 index 0000000..bb31f35 Binary files /dev/null and b/__pycache__/BadmanStrings.cpython-311.pyc differ diff --git a/__pycache__/__init__.cpython-311.pyc b/__pycache__/__init__.cpython-311.pyc new file mode 100644 index 0000000..edc8a49 Binary files /dev/null and b/__pycache__/__init__.cpython-311.pyc differ