diff --git a/README.md b/README.md index 688c7d1..9ebf0e4 100644 --- a/README.md +++ b/README.md @@ -1,4 +1,4 @@ -# 🔗 Comfyui : Bjornulf_custom_nodes v0.38 🔗 +# 🔗 Comfyui : Bjornulf_custom_nodes v0.39 🔗 # ❤️ Coffee : ☕☕☕☕☕ 5/5 @@ -90,6 +90,7 @@ If you have any issues with this template from Runpod, please let me know, I'm h - **v0.36**: Fix random model. - **v0.37**: New node : Random Load checkpoint (Model Selector). Alternative to the random checkpoint node. (Not preloading all checkpoints in memory, slower to switch between checkpoints, but more outputs to decide where to store your results.) - **v0.38**: New node : If-Else logic. (input == compare_with), examples with different latent space size. +fix some deserialization issues. +- **v0.39**: Add variables management to Advanced Write Text node. # 📝 Nodes descriptions @@ -108,7 +109,7 @@ The show node will only display text, or a list of several texts. (read only nod **Description:** Simple node to write text. -## 3 - ✒🗔 Advanced Write Text +## 3 - ✒🗔 Advanced Write Text (random selection and variables) ![write Text Advanced](screenshots/write_advanced.png) @@ -122,6 +123,11 @@ Raw text: photo of a {green|blue|red|orange|yellow} {cat|rat|house} Picked text: photo of a green house ``` +You can also create and reuse variables with this syntax : ``. +Usage example : + +![variables](screenshots/variables.png) + ## 4 - 🔗 Combine Texts ![Combine Texts](screenshots/combine_texts.png) diff --git a/pyproject.toml b/pyproject.toml index 8eda4b4..0e43a49 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -1,7 +1,7 @@ [project] name = "bjornulf_custom_nodes" description = "Nodes: Ollama, Text to Speech, Combine Texts, Random Texts, Save image for Bjornulf LobeChat, Text with random Seed, Random line from input, Combine images, Image to grayscale (black & white), Remove image Transparency (alpha), Resize Image, ..." -version = "0.38" +version = "0.39" license = {file = "LICENSE"} [project.urls] diff --git a/screenshots/variables.png b/screenshots/variables.png new file mode 100644 index 0000000..39bdcbc Binary files /dev/null and b/screenshots/variables.png differ diff --git a/write_text_advanced.py b/write_text_advanced.py index f12e5a8..18295ed 100644 --- a/write_text_advanced.py +++ b/write_text_advanced.py @@ -11,6 +11,7 @@ class WriteTextAdvanced: "text": ("STRING", {"multiline": True, "lines": 10}), }, "optional": { + "variables": ("STRING", {"multiline": True, "lines": 5}), "seed": ("INT", {"default": 0, "min": 0, "max": 0xffffffffffffffff}), }, } @@ -21,9 +22,10 @@ class WriteTextAdvanced: OUTPUT_NODE = True CATEGORY = "Bjornulf" - def write_text_special(self, text, seed=None): + def write_text_special(self, text, variables="", seed=None): logging.info(f"Raw text: {text}") - # If seed is not provided, generate a new one + logging.info(f"Variables: {variables}") + if len(text) > 10000: return ("Text too large to process at once. Please split into smaller parts.",) @@ -32,17 +34,30 @@ class WriteTextAdvanced: random.seed(seed) + # Parse variables + var_dict = {} + for line in variables.split('\n'): + if '=' in line: + key, value = line.split('=', 1) + var_dict[key.strip()] = value.strip() + + logging.info(f"Parsed variables: {var_dict}") + + # Replace variables + for key, value in var_dict.items(): + text = text.replace(f"<{key}>", value) + + # Handle random choices pattern = r'\{([^}]+)\}' def replace_random(match): return random.choice(match.group(1).split('|')) result = re.sub(pattern, replace_random, text) - logging.info(f"Picked text: {result}") + logging.info(f"Final text: {result}") return (result,) @classmethod - def IS_CHANGED(s, text, seed=None): - return (text, seed) - + def IS_CHANGED(s, text, variables="", seed=None): + return (text, variables, seed) \ No newline at end of file