diff --git a/README.md b/README.md new file mode 100644 index 0000000..bf4cb15 --- /dev/null +++ b/README.md @@ -0,0 +1,29 @@ +# Embedding Picker + +Tired of forgetting and misspelling often weird names of embeddings you use? +Or perhaps you use only one, cause you forgot you have tens of them installed? + +Try this. + +# Installation + +Exactly the same as with other simple custom nodes. + +- Click the green **Code** button, select **Download Zip**, and unpack it in your ComfyUI `custom_nodes` directory + +or + +- Clone this repository by running `git clone https://github.com/Tropfchen/ComfyUI-Embedding_Picker.git` in your ComfyUI `custom_nodes` directory + +To uninstall: + +- Delete the `ComfyUi_Embedding_Picker` in your ComfyUI custom_nodes directory + +# Use + +Simply connect `Embedding Picker` node, that you will find in `utils` menu, in between _CLIP Encoding_ and _Text Multiine_ or other similar nodes. +By default the embedding will be set as first prompt, set `append` to True if you prefer it to be the last one. + +## Example Workflow: + +![Example](example_workflow.png) diff --git a/__init__.py b/__init__.py new file mode 100644 index 0000000..0037227 --- /dev/null +++ b/__init__.py @@ -0,0 +1,3 @@ +from .node import NODE_CLASS_MAPPINGS, NODE_DISPLAY_NAME_MAPPINGS + +__all__ = ['NODE_CLASS_MAPPINGS', 'NODE_DISPLAY_NAME_MAPPINGS'] diff --git a/example_workflow.png b/example_workflow.png new file mode 100644 index 0000000..fd2ffed Binary files /dev/null and b/example_workflow.png differ diff --git a/node.py b/node.py new file mode 100644 index 0000000..0093437 --- /dev/null +++ b/node.py @@ -0,0 +1,54 @@ +from pathlib import Path + +import folder_paths + + +class EmbeddingPicker: + def __init__(self): + pass + + @classmethod + def INPUT_TYPES(self): + embeddings = folder_paths.get_filename_list("embeddings") + + return { + "required": { + "prompts": ("STRING", {"forceInput": True}), + "embedding": ((embeddings),), + "emphasis": ( + "FLOAT", + { + "default": 1.0, + "min": 0.05, + "max": 3.0, + "step": 0.05, + }, + ), + "append": ( + "BOOLEAN", + {"default": False, "label_on": "true ", "label_off": "false "}, + ), + }, + } + + RETURN_TYPES = ("STRING",) + RETURN_NAMES = ("prompts",) + FUNCTION = "concat_embedding" + OUTPUT_NODE = False + + CATEGORY = "utils" + + def concat_embedding(self, prompts, embedding, emphasis, append): + emb = "embedding:" + Path(embedding).stem + + emphasis = f"{emphasis:.3f}" + if emphasis != "1.000": + emb = f"({emb}:{emphasis})" + + output = f"{prompts}, {emb}" if append else f"{emb}, {prompts}" + + return (output,) + + +NODE_CLASS_MAPPINGS = {"EmbeddingPicker": EmbeddingPicker} +NODE_DISPLAY_NAME_MAPPINGS = {"EmbeddingPicker": "Embedding Picker"}