Initial commit

This commit is contained in:
BRADSEC
2025-01-25 16:39:27 +10:00
commit 470e2237f7
13 changed files with 256 additions and 0 deletions
+29
View File
@@ -0,0 +1,29 @@
# Python
__pycache__/
*.py[cod]
*.so
.Python
env/
venv/
.env
*.egg-info/
dist/
build/
# Go
*.exe
*.dll
*.so
*.dylib
*.test
*.out
/vendor/
# IDEs
.idea/
.vscode/
*.swp
# OS
.DS_Store
Thumbs.db
+21
View File
@@ -0,0 +1,21 @@
MIT License
Copyright (c) 2024 BRADSEC
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.
+48
View File
@@ -0,0 +1,48 @@
# String Essentials - Custom nodes for ComfyUI
Custom nodes for ComfyUI that provide text/string manipulation capabilities. Particularly useful for modifying text from LLM outputs (Ollama, Claude.ai, OpenAI ChatGPT), such as prompts or image-to-text description results.
![stringstrip](stringstrip.png)![stringreplace](stringreplace.png)
## Features
- Remove or replace text, words, numbers in input strings
- Handle multi-word strings (partial sentences/phrases)
- Case-sensitive/insensitive matching
- Whole string matching option
## String Strip Node
Removes specified strings from input text. Each line should contain the string to be searched. The string can contain multiple words. To match individual words/strings place on seperate lines.
### Inputs
- **`input_string`**: The string or text to process
- **`strings_to_remove`**: List of strings to remove (one per line)
- **`match_case`**: Enable/disable case-sensitive matching
- **`match_whole_string`**: Ensure only exact matches are removed
- **`remove_extra_spaces`**: Clean up extra spaces after removal
### String Strip Example Usage:
![examplestrip](examplestrip.png)
## String Replace Node
Replaces text strings with new strings. Each line should contain a search and replace pair separated by a colon `:` See example image below.
### Inputs
- **`input_string`**: The string or text to process
- **`replacement_pairs`**: List of search:replace pairs (one per line)
- **`match_case`**: Enable/disable case-sensitive matching
- **`match_whole_string`**: Ensure only exact matches are replaced
- **`remove_extra_spaces`**: Clean up extra spaces after replacement
### String Replace Example Usage:
![examplereplace](examplereplace.png)
## Installation
1. Navigate to the `custom_nodes` directory in your ComfyUI installation path.
2. Clone the repository:
```bash
git clone https://github.com/bradsec/ComfyUI_StringEssentials.git
```
3. Restart ComfyUI or refresh your nodes.
4. Select node from the `utils` menu. `Add Node > utils >` `String Strip` or `String Replace`
+18
View File
@@ -0,0 +1,18 @@
"""String manipulation nodes for ComfyUI"""
from .string_strip_node import StringStripNode
from .string_replace_node import StringReplaceNode
NODE_CLASS_MAPPINGS = {
"StringStrip": StringStripNode,
"StringReplace": StringReplaceNode
}
NODE_DISPLAY_NAME_MAPPINGS = {
"StringStrip": "String Strip",
"StringReplace": "String Replace"
}
WEB_DIRECTORY = "./js"
__all__ = ["NODE_CLASS_MAPPINGS", "NODE_DISPLAY_NAME_MAPPINGS", "WEB_DIRECTORY"]
Binary file not shown.

After

Width:  |  Height:  |  Size: 46 KiB

BIN
View File
Binary file not shown.

After

Width:  |  Height:  |  Size: 46 KiB

+25
View File
@@ -0,0 +1,25 @@
import { app } from "../../../scripts/app.js";
app.registerExtension({
name: "string.strip",
async beforeRegisterNodeDef(nodeType) {
if (nodeType.comfyClass === "StringStrip") {
nodeType.prototype.onNodeCreated = function() {
// Add an input port for `input_text`
this.addInput("input_string", "STRING");
};
}
}
});
app.registerExtension({
name: "string.replace",
async beforeRegisterNodeDef(nodeType) {
if (nodeType.comfyClass === "StringReplace") {
nodeType.prototype.onNodeCreated = function() {
// Add an input port for `input_text`
this.addInput("input_string", "STRING");
};
}
}
});
+14
View File
@@ -0,0 +1,14 @@
[project]
name = "comfyui_stringessentials"
description = "Essential string manipulation nodes for ComfyUI."
version = "1.0.0"
license = "MIT"
[project.urls]
Repository = "https://github.com/bradsec/ComfyUI_StringEssentials"
# Used by Comfy Registry https://comfyregistry.org
[tool.comfy]
PublisherId = "BRADSEC"
DisplayName = "ComfyUI String Essentials"
Icon = ""
+54
View File
@@ -0,0 +1,54 @@
import re
class StringReplaceNode:
@classmethod
def INPUT_TYPES(s):
return {
"required": {
"replacement_pairs": ("STRING", {"multiline": True, "default": "",
"tooltip": "Enter replacement pairs, one per line, in format 'search:replace'. Example: 'cat:dog' or 'A drawing of:A photo of'"}),
"match_case": ("BOOLEAN", {"default": False,
"label_on": "enabled", "label_off": "disabled"}),
"match_whole_string": ("BOOLEAN", {"default": True,
"label_on": "enabled", "label_off": "disabled"}),
"remove_extra_spaces": ("BOOLEAN", {"default": True,
"label_on": "enabled", "label_off": "disabled"})
}
}
RETURN_TYPES = ("STRING",)
RETURN_NAMES = ("modified_string",)
FUNCTION = "string_replace"
CATEGORY = "utils"
def string_replace(self, input_string, replacement_pairs, match_case, match_whole_string, remove_extra_spaces):
result = input_string
flags = 0 if match_case else re.IGNORECASE
for line in replacement_pairs.splitlines():
line = line.strip()
if not line or ':' not in line:
continue
search_str, replace_str = line.split(':', 1)
search_str = search_str.strip()
replace_str = replace_str.strip()
if not search_str:
continue
if match_whole_string:
pattern = re.escape(search_str)
pattern = r"(?<!\S)" + pattern + r"(?!\S)"
else:
pattern = re.escape(search_str)
result = re.sub(pattern, replace_str, result, flags=flags)
if remove_extra_spaces:
# Replace multiple spaces with single space
result = re.sub(r'\s+', ' ', result)
# Strip leading and trailing spaces
result = result.strip()
return (result,)
+47
View File
@@ -0,0 +1,47 @@
import re
class StringStripNode:
@classmethod
def INPUT_TYPES(s):
return {
"required": {
"strings_to_remove": ("STRING", {"multiline": True, "default": "",
"tooltip": "Enter strings to remove, one per line. Can include multiple words or strings on one line like: 'This image is'. This will only match this entire string."}),
"match_case": ("BOOLEAN", {"default": False,
"label_on": "enabled", "label_off": "disabled"}),
"match_whole_string": ("BOOLEAN", {"default": True,
"label_on": "enabled", "label_off": "disabled"}),
"remove_extra_spaces": ("BOOLEAN", {"default": True,
"label_on": "enabled", "label_off": "disabled"})
}
}
RETURN_TYPES = ("STRING",)
RETURN_NAMES = ("modified_string",)
FUNCTION = "string_strip"
CATEGORY = "utils"
def string_strip(self, input_string, strings_to_remove, remove_extra_spaces, match_case, match_whole_string):
result = input_string
flags = 0 if match_case else re.IGNORECASE
for string_to_remove in strings_to_remove.splitlines():
string_to_remove = string_to_remove.strip()
if not string_to_remove:
continue
if match_whole_string:
pattern = re.escape(string_to_remove)
pattern = r"(?<!\S)" + pattern + r"(?!\S)"
else:
pattern = re.escape(string_to_remove)
result = re.sub(pattern, "", result, flags=flags)
if remove_extra_spaces:
# Replace multiple spaces with single space
result = re.sub(r'\s+', ' ', result)
# Strip leading and trailing spaces
result = result.strip()
return (result,)
BIN
View File
Binary file not shown.

After

Width:  |  Height:  |  Size: 18 KiB

BIN
View File
Binary file not shown.

After

Width:  |  Height:  |  Size: 17 KiB

BIN
View File
Binary file not shown.

After

Width:  |  Height:  |  Size: 29 KiB