Full Code of theUpsider/ComfyUI-Logic for AI

master 214cfba93329 cached
8 files
9.9 KB
2.8k tokens
28 symbols
1 requests
Download .txt
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: <nodename>-🔬 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 = ""
Download .txt
gitextract_k2vrneew/

├── .github/
│   ├── ISSUE_TEMPLATE/
│   │   ├── bug_report.md
│   │   └── feature_request.md
│   └── workflows/
│       └── publish.yml
├── .gitignore
├── README.md
├── __init__.py
├── nodes.py
└── pyproject.toml
Download .txt
SYMBOL INDEX (28 symbols across 1 files)

FILE: nodes.py
  class AlwaysEqualProxy (line 13) | class AlwaysEqualProxy(str):
    method __eq__ (line 14) | def __eq__(self, _):
    method __ne__ (line 17) | def __ne__(self, _):
  class String (line 21) | class String:
    method INPUT_TYPES (line 23) | def INPUT_TYPES(s):
    method execute (line 36) | def execute(self, value):
  class Int (line 40) | class Int:
    method INPUT_TYPES (line 42) | def INPUT_TYPES(s):
    method execute (line 55) | def execute(self, value):
  class Float (line 59) | class Float:
    method INPUT_TYPES (line 61) | def INPUT_TYPES(s):
    method execute (line 74) | def execute(self, value):
  class Bool (line 78) | class Bool:
    method INPUT_TYPES (line 80) | def INPUT_TYPES(s):
    method execute (line 93) | def execute(self, value):
  class Compare (line 97) | class Compare:
    method INPUT_TYPES (line 103) | def INPUT_TYPES(s):
    method compare (line 124) | def compare(self, a, b, comparison):
  class IfExecute (line 139) | class IfExecute:
    method INPUT_TYPES (line 147) | def INPUT_TYPES(s):
    method return_based_on_bool (line 168) | def return_based_on_bool(self, ANY, IF_TRUE, IF_FALSE):
  class IfExecuteNode (line 172) | class IfExecuteNode:
    method INPUT_TYPES (line 178) | def INPUT_TYPES(cls):
    method execute (line 196) | def execute(self, ANY, NODE_TRUE, NODE_FALSE):
    method execute_node (line 202) | def execute_node(self, node_name):
  class DebugPrint (line 207) | class DebugPrint:
    method INPUT_TYPES (line 213) | def INPUT_TYPES(s):
    method log_input (line 228) | def log_input(self, ANY):
Condensed preview — 8 files, each showing path, character count, and a content snippet. Download the .json file or copy for the full structured content (11K chars).
[
  {
    "path": ".github/ISSUE_TEMPLATE/bug_report.md",
    "chars": 550,
    "preview": "---\nname: Bug report\nabout: Create a report to help us improve\ntitle: ''\nlabels: ''\nassignees: ''\n\n---\n\n**Describe the b"
  },
  {
    "path": ".github/ISSUE_TEMPLATE/feature_request.md",
    "chars": 595,
    "preview": "---\nname: Feature request\nabout: Suggest an idea for this project\ntitle: ''\nlabels: ''\nassignees: ''\n\n---\n\n**Is your fea"
  },
  {
    "path": ".github/workflows/publish.yml",
    "chars": 565,
    "preview": "name: Publish to Comfy registry\non:\n  workflow_dispatch:\n  push:\n    branches:\n      - main\n    paths:\n      - \"pyprojec"
  },
  {
    "path": ".gitignore",
    "chars": 63,
    "preview": "__pycache__/\n.pytest_cache/\n.tox/\n.venv/\n.vscode/\n.vscode-test/"
  },
  {
    "path": "README.md",
    "chars": 2188,
    "preview": "# ComfyUI Logic Nodes Extension - 🔬\n> This repo is currently not maintained\nThis repository contains an extension to [Co"
  },
  {
    "path": "__init__.py",
    "chars": 21,
    "preview": "from .nodes import *\n"
  },
  {
    "path": "nodes.py",
    "chars": 5765,
    "preview": "import nodes\n\nCOMPARE_FUNCTIONS = {\n    \"a == b\": lambda a, b: a == b,\n    \"a != b\": lambda a, b: a != b,\n    \"a < b\": l"
  },
  {
    "path": "pyproject.toml",
    "chars": 383,
    "preview": "[project]\nname = \"comfyui-logic\"\ndescription = \"An extension to ComfyUI that introduces logic nodes and conditional rend"
  }
]

About this extraction

This page contains the full source code of the theUpsider/ComfyUI-Logic GitHub repository, extracted and formatted as plain text for AI agents and large language models (LLMs). The extraction includes 8 files (9.9 KB), approximately 2.8k tokens, and a symbol index with 28 extracted functions, classes, methods, constants, and types. Use this with OpenClaw, Claude, ChatGPT, Cursor, Windsurf, or any other AI tool that accepts text input. You can copy the full output to your clipboard or download it as a .txt file.

Extracted by GitExtract — free GitHub repo to text converter for AI. Built by Nikandr Surkov.

Copied to clipboard!