diff --git a/README.md b/README.md index 26a22e7..ed3d384 100644 --- a/README.md +++ b/README.md @@ -1,6 +1,15 @@ # String Essentials - Custom nodes for ComfyUI -Easy to use string manipulation nodes for ComfyUI (strip/remove multiple text strings or search and replace text strings). Particularly useful for modifying text from LLM outputs (Ollama, Claude.ai, OpenAI ChatGPT), such as prompts or image-to-text description results. Nodes will be located under standard `Add Node` > `utils` menu. +Simple string manipulation nodes for ComfyUI (strip/remove text strings, search and replace text strings, preview modified string outputs). Particularly useful for modifying text from LLM outputs (Ollama, Claude.ai, OpenAI ChatGPT), such as prompts or image-to-text description results. No bloat/additional Python dependencies or external modules required. Nodes use a small amount of basic Python and Javascript code. + +## Nodes included: + +- String Textbox +- String Strip +- String Replace +- String Preview + +***Once added nodes can be found under the `Add Node` > `utils` menu.*** ## Features - Remove or replace text, words, numbers in input strings @@ -8,10 +17,15 @@ Easy to use string manipulation nodes for ComfyUI (strip/remove multiple text st - 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 separate lines. +## String Textbox +A simple multiline textbox for free form text. + +![stringtextbox](images/stringtextbox.png) + +## String Strip +Removes specified strings from input text. Each line should contain the string to be searched. The string can contain multiple words. To strip multiple individual words/strings place on separate lines. -![stringstrip](stringstrip.png) +![stringstrip](images/stringstrip.png) ### Inputs - **`input_string`**: The string or text to process @@ -20,13 +34,10 @@ Removes specified strings from input text. Each line should contain the string t - **`match_whole_string`**: Ensure only exact matches are removed (default: enabled) - **`remove_extra_spaces`**: Clean up extra spaces after removal (default: enabled) -### String Strip Example Usage: -![examplestrip](examplestrip.png) +## String Replace +Replaces text strings with new strings (replace/swap words etc.). Each line should contain a search and replace pair separated by the replacement_delimiter (default is double colon `::`). Example to replace dog with cat `dog::cat`. Supports mulitple string replacements, just add one replacement per line. -## String Replace Node -Replaces text strings with new strings. Each line should contain a search and replace pair separated by the replacement_delimiter (default is double colon `::`). - -![stringreplace](stringreplace.png) +![stringreplace](images/stringreplace.png) ### Inputs - **`input_string`**: The string or text to process @@ -36,8 +47,15 @@ Replaces text strings with new strings. Each line should contain a search and re - **`match_whole_string`**: Ensure only exact matches are replaced (default: disabled) - **`remove_extra_spaces`**: Clean up extra spaces after replacement (default: enabled) -### String Replace Example Usage: -![examplereplace](examplereplace.png) +## String Preview +Simply displays a string output. Can be used to view the results/changes to the input_string by the `String Strip` or `String Replace`. + +![stringpreview](images/stringpreview.png) + +## Example Usage + +![exampleusage](images/exampleusage.png) + ## Installation 1. Navigate to the `custom_nodes` directory in your ComfyUI installation path. @@ -46,4 +64,7 @@ Replaces text strings with new strings. Each line should contain a search and re 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` \ No newline at end of file +4. Select node from the `Add Node` > `utils` menu. + + +### If you found these nodes useful please star the repo. \ No newline at end of file diff --git a/__init__.py b/__init__.py index 1a8ca7e..660886f 100644 --- a/__init__.py +++ b/__init__.py @@ -1,16 +1,22 @@ """String manipulation nodes for ComfyUI""" +from .string_textbox_node import StringTextboxNode from .string_strip_node import StringStripNode -from .string_replace_node import StringReplaceNode +from .string_replace_node import StringReplaceNode +from .string_preview_node import StringPreviewNode NODE_CLASS_MAPPINGS = { + "StringTextbox": StringTextboxNode, "StringStrip": StringStripNode, - "StringReplace": StringReplaceNode + "StringReplace": StringReplaceNode, + "StringPreview": StringPreviewNode } NODE_DISPLAY_NAME_MAPPINGS = { + "StringTextbox": "String Textbox", "StringStrip": "String Strip", - "StringReplace": "String Replace" + "StringReplace": "String Replace", + "StringPreview": "String Preview" } WEB_DIRECTORY = "./js" diff --git a/examplereplace.png b/examplereplace.png deleted file mode 100644 index 600141a..0000000 Binary files a/examplereplace.png and /dev/null differ diff --git a/examplestrip.png b/examplestrip.png deleted file mode 100644 index fab531d..0000000 Binary files a/examplestrip.png and /dev/null differ diff --git a/images/exampleusage.png b/images/exampleusage.png new file mode 100644 index 0000000..c46082b Binary files /dev/null and b/images/exampleusage.png differ diff --git a/images/stringpreview.png b/images/stringpreview.png new file mode 100644 index 0000000..e20db71 Binary files /dev/null and b/images/stringpreview.png differ diff --git a/images/stringreplace.png b/images/stringreplace.png new file mode 100644 index 0000000..9fa4147 Binary files /dev/null and b/images/stringreplace.png differ diff --git a/images/stringstrip.png b/images/stringstrip.png new file mode 100644 index 0000000..a45840f Binary files /dev/null and b/images/stringstrip.png differ diff --git a/images/stringtextbox.png b/images/stringtextbox.png new file mode 100644 index 0000000..eb0118c Binary files /dev/null and b/images/stringtextbox.png differ diff --git a/images/utilsmenu.png b/images/utilsmenu.png new file mode 100644 index 0000000..3b7035a Binary files /dev/null and b/images/utilsmenu.png differ diff --git a/js/string_essentials.js b/js/string_essentials.js index 4d35a6a..28ac346 100644 --- a/js/string_essentials.js +++ b/js/string_essentials.js @@ -1,11 +1,11 @@ import { app } from "../../../scripts/app.js"; +import { ComfyWidgets } from "../../../scripts/widgets.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"); }; } @@ -17,9 +17,30 @@ app.registerExtension({ async beforeRegisterNodeDef(nodeType) { if (nodeType.comfyClass === "StringReplace") { nodeType.prototype.onNodeCreated = function() { - // Add an input port for `input_text` this.addInput("input_string", "STRING"); }; } } +}); + +app.registerExtension({ + name: "string.preview", + async beforeRegisterNodeDef(nodeType, nodeData) { + if (nodeType.comfyClass === "StringPreview") { + nodeType.prototype.onNodeCreated = function() { + this.addInput("input_string", "STRING"); + this.showValueWidget = ComfyWidgets["STRING"](this, "preview", ["STRING", { multiline: true }], app).widget; + this.showValueWidget.inputEl.readOnly = true; + this.showValueWidget.inputEl.style.opacity = 0.6; + }; + + const onExecuted = nodeType.prototype.onExecuted; + nodeType.prototype.onExecuted = function(message) { + onExecuted?.apply(this, arguments); + if (message?.text?.[0] !== undefined) { + this.showValueWidget.value = message.text[0]; + } + }; + } + } }); \ No newline at end of file diff --git a/pyproject.toml b/pyproject.toml index 249244c..bd7d72c 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -1,7 +1,7 @@ [project] name = "comfyui_stringessentials" -description = "Easy to use string manipulation nodes for ComfyUI (strip/remove text strings or search and replace text strings). Particularly useful for modifying text prompts or results from LLM outputs. Nodes will be located under standard Add Node > utils menu. Node names: String Strip and String Replace" -version = "1.0.2" +description = "Simple string manipulation nodes for ComfyUI (strip/remove text strings, search and replace text strings, preview modified string outputs). Useful for modifying text prompts or results from LLM outputs. Nodes will be located under standard Add Node > utils menu. Node names: String Textbox, String Strip, String Replace, and String Preview." +version = "1.0.3" license = {file = "LICENSE"} [project.urls] diff --git a/string_preview_node.py b/string_preview_node.py new file mode 100644 index 0000000..7472d04 --- /dev/null +++ b/string_preview_node.py @@ -0,0 +1,15 @@ +class StringPreviewNode: + @classmethod + def INPUT_TYPES(s): + return { + "required": {}, + } + + RETURN_TYPES = ("STRING",) + RETURN_NAMES = ("output_string",) + FUNCTION = "preview_string" + CATEGORY = "utils" + OUTPUT_NODE = True + + def preview_string(self, input_string=""): + return {"ui": {"text": (input_string,)}, "result": (input_string,)} \ No newline at end of file diff --git a/string_textbox_node.py b/string_textbox_node.py new file mode 100644 index 0000000..8f0b1da --- /dev/null +++ b/string_textbox_node.py @@ -0,0 +1,20 @@ +class StringTextboxNode: + @classmethod + def INPUT_TYPES(s): + return { + "required": { + "input_string": ("STRING", { + "multiline": True, + "default": "", + "tooltip": "Enter text here" + }) + } + } + + RETURN_TYPES = ("STRING",) + RETURN_NAMES = ("output_string",) + FUNCTION = "pass_string" + CATEGORY = "utils" + + def pass_string(self, input_string): + return (input_string,) \ No newline at end of file diff --git a/stringreplace.png b/stringreplace.png deleted file mode 100644 index 7a3e4c6..0000000 Binary files a/stringreplace.png and /dev/null differ diff --git a/stringstrip.png b/stringstrip.png deleted file mode 100644 index f0bc310..0000000 Binary files a/stringstrip.png and /dev/null differ diff --git a/utilsmenu.png b/utilsmenu.png deleted file mode 100644 index db3fbbb..0000000 Binary files a/utilsmenu.png and /dev/null differ