This commit is contained in:
justumen
2024-09-12 17:23:11 +02:00
parent 673510e092
commit d0b40589ea
3 changed files with 58 additions and 9 deletions

View File

@@ -1,4 +1,4 @@
# 🔗 Comfyui : Bjornulf_custom_nodes v0.21 🔗
# 🔗 Comfyui : Bjornulf_custom_nodes v0.22 🔗
# ☁ Usage in cloud :
@@ -63,7 +63,8 @@ wget --content-disposition -P /workspace/ComfyUI/models/checkpoints "https://civ
- **v0.18**: New loop node, Free VRAM hack
- **v0.19**: Changes for save to folder node : ignore missing images filenames, will use the highest number found + 1.
- **v0.20**: Changes for lobechat save image : include the code of free VRAM hack + ignore missing images filenames
- **v0.21**: Add a write text node that also display the text in the comfyui console (good for debugging)
- **v0.21**: Add a new write text node that also display the text in the comfyui console (good for debugging)
- **v0.22**: Allow write text node to use random selection like this {hood|helmet} will randomly choose between hood or helmet.
# 📝 Nodes descriptions
@@ -75,6 +76,7 @@ wget --content-disposition -P /workspace/ComfyUI/models/checkpoints "https://civ
Three simple nodes to write and show text.
Write node is a textarea where you can write your text.
The show text node will only display the text. (That's why I made it a different color : green, uneditable, display only.)
Write text node now allow for special syntax to accept random variants, like `{hood|helmet}` will randomly choose between hood or helmet.
## 3 - 🔗 Combine Texts
![Combine Texts](screenshots/combine_texts.png)

View File

@@ -1,19 +1,44 @@
import re
import random
import time
class WriteText:
@classmethod
def INPUT_TYPES(s):
return {
"required": {
"text": ("STRING", {"multiline": True}),
}
},
"hidden": {
"seed": ("INT", {"default": 0, "min": 0, "max": 0xffffffffffffffff}),
"control_after_update": ("INT", {"default": 0})
},
}
# INPUT_IS_LIST = True
RETURN_TYPES = ("STRING",)
RETURN_NAMES = ("text",)
FUNCTION = "write_text"
OUTPUT_NODE = True
OUTPUT_IS_LIST = (False,)
CATEGORY = "Bjornulf"
def write_text(self, text):
return {"ui": {"text": text}, "result": (text,)}
def write_text(self, text, seed=None, control_after_update=None):
# If seed is not provided, generate a new one
if seed is None:
seed = int(time.time() * 1000)
# Use the seed to initialize the random number generator
random.seed(seed)
def replace_random(match):
options = match.group(1).split('|')
return random.choice(options)
pattern = r'\{([^}]+)\}'
result = re.sub(pattern, replace_random, text)
return (result,)
@classmethod
def IS_CHANGED(s, text, seed=None, control_after_update=None):
# This method is called to determine if the node needs to be re-executed
return float("nan") # Always re-execute to ensure consistency

View File

@@ -1,3 +1,6 @@
import re
import random
import time
import logging
class WriteTextInConsole:
@classmethod
@@ -16,6 +19,25 @@ class WriteTextInConsole:
OUTPUT_IS_LIST = (False,)
CATEGORY = "Bjornulf"
def write_text_in_console(self, text):
def write_text_in_console(self, text, seed=None, control_after_update=None):
logging.info(f"Text: {text}")
return {"ui": {"text": text}, "result": (text,)}
# If seed is not provided, generate a new one
if seed is None:
seed = int(time.time() * 1000)
# Use the seed to initialize the random number generator
random.seed(seed)
def replace_random(match):
options = match.group(1).split('|')
return random.choice(options)
pattern = r'\{([^}]+)\}'
result = re.sub(pattern, replace_random, text)
return (result,)
@classmethod
def IS_CHANGED(s, text, seed=None, control_after_update=None):
# This method is called to determine if the node needs to be re-executed
return float("nan") # Always re-execute to ensure consistency