Repository: theUpsider/ComfyUI-Logic Branch: master Commit: 214cfba93329 Files: 8 Total size: 9.9 KB Directory structure: gitextract_k2vrneew/ ├── .github/ │ ├── ISSUE_TEMPLATE/ │ │ ├── bug_report.md │ │ └── feature_request.md │ └── workflows/ │ └── publish.yml ├── .gitignore ├── README.md ├── __init__.py ├── nodes.py └── pyproject.toml ================================================ FILE CONTENTS ================================================ ================================================ FILE: .github/ISSUE_TEMPLATE/bug_report.md ================================================ --- name: Bug report about: Create a report to help us improve title: '' labels: '' assignees: '' --- **Describe the bug** A clear and concise description of what the bug is. **To Reproduce** __Please attach a workflow file to make it easier for others to reproduce the error!__ **Expected behavior** A clear and concise description of what you expected to happen. **Screenshots** If applicable, add screenshots to help explain your problem. **Version:** - ComfyUI Version **Additional context** Add any other context about the problem here. ================================================ FILE: .github/ISSUE_TEMPLATE/feature_request.md ================================================ --- name: Feature request about: Suggest an idea for this project title: '' labels: '' assignees: '' --- **Is your feature request related to a problem? Please describe.** A clear and concise description of what the problem is. Ex. I'm always frustrated when [...] **Describe the solution you'd like** A clear and concise description of what you want to happen. **Describe alternatives you've considered** A clear and concise description of any alternative solutions or features you've considered. **Additional context** Add any other context or screenshots about the feature request here. ================================================ FILE: .github/workflows/publish.yml ================================================ name: Publish to Comfy registry on: workflow_dispatch: push: branches: - main paths: - "pyproject.toml" jobs: publish-node: name: Publish Custom Node to registry runs-on: ubuntu-latest steps: - name: Check out code uses: actions/checkout@v4 - name: Publish Custom Node uses: Comfy-Org/publish-node-action@main with: ## Add your own personal access token to your Github Repository secrets and reference it here. personal_access_token: ${{ secrets.REGISTRY_ACCESS_TOKEN }} ================================================ FILE: .gitignore ================================================ __pycache__/ .pytest_cache/ .tox/ .venv/ .vscode/ .vscode-test/ ================================================ FILE: README.md ================================================ # ComfyUI Logic Nodes Extension - 🔬 > This repo is currently not maintained This repository contains an extension to [ComfyUI](https://github.com/comfyanonymous/ComfyUI) that introduces logic nodes and conditional rendering capabilities: - If - Compare - Int, String, Float, Bool - If ANY return A else B ![image](https://github.com/theUpsider/ComfyUI-Logic/assets/25013640/7807b2a4-989d-4021-9572-1d2d13725304) > **_NOTE:_** This extension is still in development and may contain bugs. Please report any issues you encounter. New features are in development! ## Installation - Clone this repository into the `custom_nodes` folder of ComfyUI. Restart ComfyUI and the extension should be loaded. - Alternativly use [ComfyUI Manager](https://github.com/ltdrdata/ComfyUI-Manager) - Or use the comfy registry: `comfy node registry-install comfyui-logic`, more infos at [ComfyUI Registry](https://docs.comfy.org/registry/overview) ## Features - **Comparison Nodes**: Compare two values using various comparison operators. - **Data Type Nodes**: Convert and handle `Int`, `String`, `Float` and `Bool` data types. - **Conditional Execution**: Execute different nodes as input based on a boolean condition. - **Debugging**: Print any input to the console for debugging purposes. ## Nodes ### Compare Compares two inputs (`a` and `b`) based on the provided comparison operator. Supported operators include: - `a == b` - `a != b` - `a < b` - `a > b` - `a <= b` - `a >= b` ### Int Accepts an integer value and returns it. ### String Accepts a string value and returns it. ### Float Accepts a float value and returns it. ### Bool Accepts a boolean value and returns it. ### If ANY return A else B Pass the value of the `IF_TRUE` node if the `ANY` input is `True`, otherwise it passes the `IF_FALSE` node. ### DebugPrint Prints the provided input to the console. Useful for debugging. >Note: The names have a globally unique identifier: -🔬 so dear developers please refrain from also using this name for other nodes. ## Author - David Fischer - GitHub: [theUpsider](https://github.com/theUpsider) - Support me on [BuyMeACoffee](https://www.buymeacoffee.com/theupsider) ================================================ FILE: __init__.py ================================================ from .nodes import * ================================================ FILE: nodes.py ================================================ import nodes COMPARE_FUNCTIONS = { "a == b": lambda a, b: a == b, "a != b": lambda a, b: a != b, "a < b": lambda a, b: a < b, "a > b": lambda a, b: a > b, "a <= b": lambda a, b: a <= b, "a >= b": lambda a, b: a >= b, } class AlwaysEqualProxy(str): def __eq__(self, _): return True def __ne__(self, _): return False class String: @classmethod def INPUT_TYPES(s): return { "required": {"value": ("STRING", {"default": "", "multiline": True})}, } RETURN_TYPES = ("STRING",) RETURN_NAMES = ("STRING",) FUNCTION = "execute" CATEGORY = "Logic" def execute(self, value): return (value,) class Int: @classmethod def INPUT_TYPES(s): return { "required": {"value": ("INT", {"default": 0})}, } RETURN_TYPES = ("INT",) RETURN_NAMES = ("INT",) FUNCTION = "execute" CATEGORY = "Logic" def execute(self, value): return (value,) class Float: @classmethod def INPUT_TYPES(s): return { "required": {"value": ("FLOAT", {"default": 0, "step": 0.01})}, } RETURN_TYPES = ("FLOAT",) RETURN_NAMES = ("FLOAT",) FUNCTION = "execute" CATEGORY = "Logic" def execute(self, value): return (value,) class Bool: @classmethod def INPUT_TYPES(s): return { "required": {"value": ("BOOLEAN", {"default": False})}, } RETURN_TYPES = ("BOOLEAN",) RETURN_NAMES = ("BOOLEAN",) FUNCTION = "execute" CATEGORY = "Logic" def execute(self, value): return (value,) class Compare: """ This nodes compares the two inputs and outputs the result of the comparison. """ @classmethod def INPUT_TYPES(s): """ Comparison node takes two inputs, a and b, and compares them. """ s.compare_functions = list(COMPARE_FUNCTIONS.keys()) return { "required": { "a": (AlwaysEqualProxy("*"), {"default": 0}), "b": (AlwaysEqualProxy("*"), {"default": 0}), "comparison": (s.compare_functions, {"default": "a == b"}), }, } RETURN_TYPES = ("BOOLEAN",) RETURN_NAMES = ("BOOLEAN",) FUNCTION = "compare" CATEGORY = "Logic" def compare(self, a, b, comparison): """ Compare two inputs and return the result of the comparison. Args: a (UNKNOWN): The first input. b (UNKNOWN): The second input. comparison (STRING): The comparison to perform. Can be one of "==", "!=", "<", ">", "<=", ">=". Returns: : The result of the comparison. """ return (COMPARE_FUNCTIONS[comparison](a, b),) class IfExecute: """ This node executes IF_TRUE if ANY is True, otherwise it executes IF_FALSE. ANY can be any input, IF_TRUE and IF_FALSE can be any output. """ @classmethod def INPUT_TYPES(s): return { "required": { "ANY": (AlwaysEqualProxy("*"),), "IF_TRUE": (AlwaysEqualProxy("*"),), "IF_FALSE": (AlwaysEqualProxy("*"),), }, } RETURN_TYPES = (AlwaysEqualProxy("*"),) OUTPUT_TOOLTIPS = ( "Based on the value of ANY, either IF_TRUE or IF_FALSE will be returned.", ) RETURN_NAMES = ("?",) FUNCTION = "return_based_on_bool" CATEGORY = "Logic" def return_based_on_bool(self, ANY, IF_TRUE, IF_FALSE): return (IF_TRUE if ANY else IF_FALSE,) class IfExecuteNode: """ This node lets you choose from all nodes and execute the selected one when ANY is True. """ @classmethod def INPUT_TYPES(cls): cls.node_names = list(nodes.NODE_CLASS_MAPPINGS.keys()) return { "required": { "ANY": (AlwaysEqualProxy("*"),), "NODE_TRUE": (cls.node_names, {"default": cls.node_names[0]}), "NODE_FALSE": (cls.node_names, {"default": cls.node_names[0]}), }, } RETURN_TYPES = () OUTPUT_NODE = True CATEGORY = "Logic" FUNCTION = "execute" def execute(self, ANY, NODE_TRUE, NODE_FALSE): if ANY: return self.execute_node(NODE_TRUE) else: return self.execute_node(NODE_FALSE) def execute_node(self, node_name): node = nodes.NODE_CLASS_MAPPINGS[node_name]() return node.execute() class DebugPrint: """ This node prints the input to the console. """ @classmethod def INPUT_TYPES(s): """ Takes in any input. """ return {"required": {"ANY": (AlwaysEqualProxy({}),)}} RETURN_TYPES = () OUTPUT_NODE = True FUNCTION = "log_input" CATEGORY = "Logic" def log_input(self, ANY): print(ANY) return {} # A dictionary that contains all nodes you want to export with their names # NOTE: names should be globally unique NODE_CLASS_MAPPINGS = { "Compare-🔬": Compare, "Int-🔬": Int, "Float-🔬": Float, "Bool-🔬": Bool, "String-🔬": String, "If ANY return A else B-🔬": IfExecute, "DebugPrint-🔬": DebugPrint, # "If ANY execute A else B-🔬": IfExecuteNode, } # A dictionary that contains the friendly/humanly readable titles for the nodes NODE_DISPLAY_NAME_MAPPINGS = { "Compare-🔬": "Compare", "Int-🔬": "Int", "Float-🔬": "Float", "Bool-🔬": "Bool", "String-🔬": "String", "If ANY return A else B-🔬": "If ANY return A else B", "DebugPrint-🔬": "DebugPrint", # "If ANY execute A else B-🔬": "If ANY execute A else B", } print("\033[94mtheUpsiders Logic Nodes: \033[92mLoaded\033[0m") ================================================ FILE: pyproject.toml ================================================ [project] name = "comfyui-logic" description = "An extension to ComfyUI that introduces logic nodes and conditional rendering capabilities." version = "1.2.0" license = "MIT" [project.urls] Repository = "https://github.com/theUpsider/ComfyUI-Logic" # Used by Comfy Registry https://comfyregistry.org [tool.comfy] PublisherId = "theupsider" DisplayName = "ComfyUI-Logic" Icon = ""