This commit is contained in:
justumen
2024-09-17 22:05:03 +02:00
parent c19c417611
commit 7a703f1113
4 changed files with 30 additions and 9 deletions

View File

@@ -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 : `<name>`.
Usage example :
![variables](screenshots/variables.png)
## 4 - 🔗 Combine Texts
![Combine Texts](screenshots/combine_texts.png)

View File

@@ -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]

BIN
screenshots/variables.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 86 KiB

View File

@@ -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)