From 283e2e2e59e66d69b9fa2adbee3f5dca69ec0254 Mon Sep 17 00:00:00 2001 From: Dekita Date: Sun, 17 Sep 2023 17:48:07 +0100 Subject: [PATCH 1/5] Add 'Random Float' node <3 does what it says on the tin :) --- invokeai/app/invocations/math.py | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) diff --git a/invokeai/app/invocations/math.py b/invokeai/app/invocations/math.py index ac151464780..d9e07b7cc29 100644 --- a/invokeai/app/invocations/math.py +++ b/invokeai/app/invocations/math.py @@ -2,6 +2,7 @@ from typing import Literal +import random import numpy as np from pydantic import validator @@ -65,6 +66,23 @@ def invoke(self, context: InvocationContext) -> IntegerOutput: return IntegerOutput(value=np.random.randint(self.low, self.high)) +# Added by DekitaRPG +@invocation("rand_float",title="Random Float",tags=["math","float","random"],category="math",version="1.0.0") +class RandomFloatInvocation(BaseInvocation): + """Output a random value between min and max using seed""" + + min: float = InputField(default=0.0, description="The mimimum returned value") + max: float = InputField(default=1.0, description="The maximum returned value") + seed: int = InputField(default=None, description="The seed used for randomization") + decimals: int = InputField(default=2, description="The number of decimal places in the dgenerated float") + + def invoke(self, context:InvocationContext) -> FloatOutput: + random.seed(self.seed) # Set the random seed + random_float = random.uniform(self.min, self.max) + rounded_float = round(random_float, self.decimals) + return FloatOutput(value=rounded_float) + + @invocation( "float_to_int", title="Float To Integer", From f5cf8ffa640630190a27df32dc8cebf60f0db960 Mon Sep 17 00:00:00 2001 From: Dekita Date: Thu, 21 Sep 2023 22:02:16 +0100 Subject: [PATCH 2/5] Add random float + random seeded float nodes altered my random float node as requested by Millu, kept the seeded version as an alternate variant for those that would like to control the randomization seed :) --- invokeai/app/invocations/math.py | 19 ++++++++++++++++--- 1 file changed, 16 insertions(+), 3 deletions(-) diff --git a/invokeai/app/invocations/math.py b/invokeai/app/invocations/math.py index d9e07b7cc29..6517c2814c3 100644 --- a/invokeai/app/invocations/math.py +++ b/invokeai/app/invocations/math.py @@ -66,15 +66,28 @@ def invoke(self, context: InvocationContext) -> IntegerOutput: return IntegerOutput(value=np.random.randint(self.low, self.high)) -# Added by DekitaRPG @invocation("rand_float",title="Random Float",tags=["math","float","random"],category="math",version="1.0.0") class RandomFloatInvocation(BaseInvocation): - """Output a random value between min and max using seed""" + """Output a random value between min and max""" + + min: float = InputField(default=0.0, description="The mimimum returned value") + max: float = InputField(default=1.0, description="The maximum returned value") + decimals: int = InputField(default=2, description="The number of decimal places in the generated float") + + def invoke(self, context:InvocationContext) -> FloatOutput: + random_float = random.uniform(self.min, self.max) + rounded_float = round(random_float, self.decimals) + return FloatOutput(value=rounded_float) + + +@invocation("rand_seed_float",title="Random Seeded Float",tags=["math","float","random"],category="math",version="1.0.0") +class RandomSeededFloatInvocation(BaseInvocation): + """Output a random value between min and max (but using seed)""" min: float = InputField(default=0.0, description="The mimimum returned value") max: float = InputField(default=1.0, description="The maximum returned value") seed: int = InputField(default=None, description="The seed used for randomization") - decimals: int = InputField(default=2, description="The number of decimal places in the dgenerated float") + decimals: int = InputField(default=2, description="The number of decimal places in the generated float") def invoke(self, context:InvocationContext) -> FloatOutput: random.seed(self.seed) # Set the random seed From 4c2470689cd74ca7706fadb63018b06c0f0659a8 Mon Sep 17 00:00:00 2001 From: Dekita Date: Fri, 22 Sep 2023 02:33:02 +0100 Subject: [PATCH 3/5] Update math.py --- invokeai/app/invocations/math.py | 16 ---------------- 1 file changed, 16 deletions(-) diff --git a/invokeai/app/invocations/math.py b/invokeai/app/invocations/math.py index 6517c2814c3..4dcea765e46 100644 --- a/invokeai/app/invocations/math.py +++ b/invokeai/app/invocations/math.py @@ -80,22 +80,6 @@ def invoke(self, context:InvocationContext) -> FloatOutput: return FloatOutput(value=rounded_float) -@invocation("rand_seed_float",title="Random Seeded Float",tags=["math","float","random"],category="math",version="1.0.0") -class RandomSeededFloatInvocation(BaseInvocation): - """Output a random value between min and max (but using seed)""" - - min: float = InputField(default=0.0, description="The mimimum returned value") - max: float = InputField(default=1.0, description="The maximum returned value") - seed: int = InputField(default=None, description="The seed used for randomization") - decimals: int = InputField(default=2, description="The number of decimal places in the generated float") - - def invoke(self, context:InvocationContext) -> FloatOutput: - random.seed(self.seed) # Set the random seed - random_float = random.uniform(self.min, self.max) - rounded_float = round(random_float, self.decimals) - return FloatOutput(value=rounded_float) - - @invocation( "float_to_int", title="Float To Integer", From c990415ed5010883c0f95d8da6dc722f71319010 Mon Sep 17 00:00:00 2001 From: Dekita Date: Fri, 22 Sep 2023 02:35:37 +0100 Subject: [PATCH 4/5] Update math.py --- invokeai/app/invocations/math.py | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/invokeai/app/invocations/math.py b/invokeai/app/invocations/math.py index 4dcea765e46..eb3ad206c74 100644 --- a/invokeai/app/invocations/math.py +++ b/invokeai/app/invocations/math.py @@ -2,7 +2,6 @@ from typing import Literal -import random import numpy as np from pydantic import validator @@ -75,7 +74,7 @@ class RandomFloatInvocation(BaseInvocation): decimals: int = InputField(default=2, description="The number of decimal places in the generated float") def invoke(self, context:InvocationContext) -> FloatOutput: - random_float = random.uniform(self.min, self.max) + random_float = np.random.uniform(self.min, self.max) rounded_float = round(random_float, self.decimals) return FloatOutput(value=rounded_float) From 893b5559d21152710b76191b44dd29eaa21ed166 Mon Sep 17 00:00:00 2001 From: psychedelicious <4822129+psychedelicious@users.noreply.github.com> Date: Tue, 26 Sep 2023 15:50:51 +1000 Subject: [PATCH 5/5] feat(nodes): standardize fields to match other nodes --- invokeai/app/invocations/baseinvocation.py | 3 +++ invokeai/app/invocations/math.py | 22 +++++++++++----------- 2 files changed, 14 insertions(+), 11 deletions(-) diff --git a/invokeai/app/invocations/baseinvocation.py b/invokeai/app/invocations/baseinvocation.py index af7a3432741..3285de3d5af 100644 --- a/invokeai/app/invocations/baseinvocation.py +++ b/invokeai/app/invocations/baseinvocation.py @@ -91,6 +91,9 @@ class FieldDescriptions: board = "The board to save the image to" image = "The image to process" tile_size = "Tile size" + inclusive_low = "The inclusive low value" + exclusive_high = "The exclusive high value" + decimal_places = "The number of decimal places to round to" class Input(str, Enum): diff --git a/invokeai/app/invocations/math.py b/invokeai/app/invocations/math.py index 5205607302b..b52cbb28bfc 100644 --- a/invokeai/app/invocations/math.py +++ b/invokeai/app/invocations/math.py @@ -65,23 +65,23 @@ def invoke(self, context: InvocationContext) -> IntegerOutput: class RandomIntInvocation(BaseInvocation): """Outputs a single random integer.""" - low: int = InputField(default=0, description="The inclusive low value") - high: int = InputField(default=np.iinfo(np.int32).max, description="The exclusive high value") + low: int = InputField(default=0, description=FieldDescriptions.inclusive_low) + high: int = InputField(default=np.iinfo(np.int32).max, description=FieldDescriptions.exclusive_high) def invoke(self, context: InvocationContext) -> IntegerOutput: return IntegerOutput(value=np.random.randint(self.low, self.high)) -@invocation("rand_float",title="Random Float",tags=["math","float","random"],category="math",version="1.0.0") +@invocation("rand_float", title="Random Float", tags=["math", "float", "random"], category="math", version="1.0.0") class RandomFloatInvocation(BaseInvocation): - """Output a random value between min and max""" - - min: float = InputField(default=0.0, description="The mimimum returned value") - max: float = InputField(default=1.0, description="The maximum returned value") - decimals: int = InputField(default=2, description="The number of decimal places in the generated float") - - def invoke(self, context:InvocationContext) -> FloatOutput: - random_float = np.random.uniform(self.min, self.max) + """Outputs a single random float""" + + low: float = InputField(default=0.0, description=FieldDescriptions.inclusive_low) + high: float = InputField(default=1.0, description=FieldDescriptions.exclusive_high) + decimals: int = InputField(default=2, description=FieldDescriptions.decimal_places) + + def invoke(self, context: InvocationContext) -> FloatOutput: + random_float = np.random.uniform(self.low, self.high) rounded_float = round(random_float, self.decimals) return FloatOutput(value=rounded_float)