Invoke is a leading creative engine that uses image and video generation models to empower professionals, artists, and enthusiasts to generate and create visual media using the latest AI-driven technologies. The solution offers an industry-leading application interface, and serves as the foundation for multiple commercial products.
TypeScript ai-artartificial-intelligencegenerative-artimage-generationimg2imginpaintinglatent-diffusionlinuxmacosoutpaintingstable-diffusiontxt2imgwindows
Added additional logic operators.
JPPhoto4113186cac1b
diff --git a/invokeai/app/invocations/logic.py b/invokeai/app/invocations/logic.pyindex 4f0064877c..43deda5d42 100644--- a/invokeai/app/invocations/logic.py+++ b/invokeai/app/invocations/logic.py@@ -42,17 +42,25 @@ class IfInvocation(BaseInvocation):return IfInvocationOutput(value=self.true_input if self.condition else self.false_input)-BOOLEAN_OPERATIONS = Literal["AND", "OR", "XOR", "NOT"]+BOOLEAN_OPERATIONS = Literal["AND", "OR", "XOR", "NOT", "NAND", "NOR", "XNOR"]@invocation("boolean_logic", title="Boolean Logic", tags=["logic", "boolean"], category="math", version="1.0.0")class BooleanLogicInvocation(BaseInvocation):- """Performs Boolean AND, OR, XOR, or NOT operations."""+ """Performs Boolean AND, OR, XOR, NOT, NAND, NOR, or XNOR operations. NOT uses only A."""operation: BOOLEAN_OPERATIONS = InputField(default="AND",description="The logical operation to perform",- ui_choice_labels={"AND": "A AND B", "OR": "A OR B", "XOR": "A XOR B", "NOT": "NOT A"},+ ui_choice_labels={+ "AND": "A AND B",+ "OR": "A OR B",+ "XOR": "A XOR B",+ "NOT": "NOT A",+ "NAND": "A NAND B",+ "NOR": "A NOR B",+ "XNOR": "A XNOR B",+ },)a: bool = InputField(default=False, description="First Boolean input")b: bool = InputField(default=False, description="Second Boolean input (ignored for NOT)")@@ -64,6 +72,12 @@ class BooleanLogicInvocation(BaseInvocation):result = self.a or self.belif self.operation == "XOR":result = self.a != self.b- else: # self.operation == "NOT"+ elif self.operation == "NOT":result = not self.a+ elif self.operation == "NAND":+ result = not (self.a and self.b)+ elif self.operation == "NOR":+ result = not (self.a or self.b)+ else: # self.operation == "XNOR"+ result = self.a == self.breturn BooleanOutput(value=result)diff --git a/tests/app/invocations/test_boolean_logic.py b/tests/app/invocations/test_boolean_logic.pyindex 77cdad7d82..26b9ad9446 100644--- a/tests/app/invocations/test_boolean_logic.py+++ b/tests/app/invocations/test_boolean_logic.py@@ -7,15 +7,18 @@ from invokeai.app.invocations.logic import BooleanLogicInvocationfrom invokeai.app.invocations.primitives import BooleanOutput[email protected]("operation", ["AND", "OR", "XOR", "NOT"])[email protected]("operation", ["AND", "OR", "XOR", "NOT", "NAND", "NOR", "XNOR"])@pytest.mark.parametrize("a", [False, True])@pytest.mark.parametrize("b", [False, True])-def test_boolean_logic(operation: Literal["AND", "OR", "XOR", "NOT"], a: bool, b: bool) -> None:+def test_boolean_logic(operation: Literal["AND", "OR", "XOR", "NOT", "NAND", "NOR", "XNOR"], a: bool, b: bool) -> None:expected = {"AND": a and b,"OR": a or b,"XOR": a != b,"NOT": not a,+ "NAND": not (a and b),+ "NOR": not (a or b),+ "XNOR": a == b,}[operation]output = BooleanLogicInvocation(id="boolean_logic", operation=operation, a=a, b=b).invoke(MagicMock())