Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 3 additions & 1 deletion invokeai/app/invocations/baseinvocation.py
Original file line number Diff line number Diff line change
Expand Up @@ -72,5 +72,7 @@ def get_output_type(cls):
def invoke(self, context: InvocationContext) -> BaseInvocationOutput:
"""Invoke with provided context and return outputs."""
pass


#fmt: off
id: str = Field(description="The id of this node. Must be unique among all nodes.")
#fmt: on
7 changes: 3 additions & 4 deletions invokeai/app/invocations/cv.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,14 +14,13 @@

class CvInpaintInvocation(BaseInvocation):
"""Simple inpaint using opencv."""

#fmt: off
type: Literal["cv_inpaint"] = "cv_inpaint"

# Inputs
image: ImageField = Field(default=None, description="The image to inpaint")
mask: ImageField = Field(
default=None, description="The mask to use when inpainting"
)
mask: ImageField = Field(default=None, description="The mask to use when inpainting")
#fmt: on

def invoke(self, context: InvocationContext) -> ImageOutput:
image = context.services.images.get(
Expand Down
73 changes: 33 additions & 40 deletions invokeai/app/invocations/image.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,29 +23,28 @@ class ImageField(BaseModel):

class ImageOutput(BaseInvocationOutput):
"""Base class for invocations that output an image"""

#fmt: off
type: Literal["image"] = "image"

image: ImageField = Field(default=None, description="The output image")

image: ImageField = Field(default=None, description="The output image")
#fmt: on

class MaskOutput(BaseInvocationOutput):
"""Base class for invocations that output a mask"""

#fmt: off
type: Literal["mask"] = "mask"

mask: ImageField = Field(default=None, description="The output mask")

mask: ImageField = Field(default=None, description="The output mask")
#fomt: on

# TODO: this isn't really necessary anymore
class LoadImageInvocation(BaseInvocation):
"""Load an image from a filename and provide it as output."""

#fmt: off
type: Literal["load_image"] = "load_image"

# Inputs
image_type: ImageType = Field(description="The type of the image")
image_name: str = Field(description="The name of the image")
image_name: str = Field(description="The name of the image")
#fmt: on

def invoke(self, context: InvocationContext) -> ImageOutput:
return ImageOutput(
Expand Down Expand Up @@ -79,17 +78,16 @@ def invoke(self, context: InvocationContext) -> ImageOutput:

class CropImageInvocation(BaseInvocation):
"""Crops an image to a specified box. The box can be outside of the image."""

#fmt: off
type: Literal["crop"] = "crop"

# Inputs
image: ImageField = Field(default=None, description="The image to crop")
x: int = Field(default=0, description="The left x coordinate of the crop rectangle")
y: int = Field(default=0, description="The top y coordinate of the crop rectangle")
width: int = Field(default=512, gt=0, description="The width of the crop rectangle")
height: int = Field(
default=512, gt=0, description="The height of the crop rectangle"
)
x: int = Field(default=0, description="The left x coordinate of the crop rectangle")
y: int = Field(default=0, description="The top y coordinate of the crop rectangle")
width: int = Field(default=512, gt=0, description="The width of the crop rectangle")
height: int = Field(default=512, gt=0, description="The height of the crop rectangle")
#fmt: on

def invoke(self, context: InvocationContext) -> ImageOutput:
image = context.services.images.get(
Expand All @@ -113,21 +111,16 @@ def invoke(self, context: InvocationContext) -> ImageOutput:

class PasteImageInvocation(BaseInvocation):
"""Pastes an image into another image."""

#fmt: off
type: Literal["paste"] = "paste"

# Inputs
base_image: ImageField = Field(default=None, description="The base image")
image: ImageField = Field(default=None, description="The image to paste")
mask: Optional[ImageField] = Field(
default=None, description="The mask to use when pasting"
)
x: int = Field(
default=0, description="The left x coordinate at which to paste the image"
)
y: int = Field(
default=0, description="The top y coordinate at which to paste the image"
)
base_image: ImageField = Field(default=None, description="The base image")
image: ImageField = Field(default=None, description="The image to paste")
mask: Optional[ImageField] = Field(default=None, description="The mask to use when pasting")
x: int = Field(default=0, description="The left x coordinate at which to paste the image")
y: int = Field(default=0, description="The top y coordinate at which to paste the image")
#fmt: on

def invoke(self, context: InvocationContext) -> ImageOutput:
base_image = context.services.images.get(
Expand Down Expand Up @@ -168,14 +161,13 @@ def invoke(self, context: InvocationContext) -> ImageOutput:

class MaskFromAlphaInvocation(BaseInvocation):
"""Extracts the alpha channel of an image as a mask."""

#fmt: off
type: Literal["tomask"] = "tomask"

# Inputs
image: ImageField = Field(
default=None, description="The image to create the mask from"
)
invert: bool = Field(default=False, description="Whether or not to invert the mask")
image: ImageField = Field(default=None, description="The image to create the mask from")
invert: bool = Field(default=False, description="Whether or not to invert the mask")
#fmt: on

def invoke(self, context: InvocationContext) -> MaskOutput:
image = context.services.images.get(
Expand All @@ -197,15 +189,15 @@ def invoke(self, context: InvocationContext) -> MaskOutput:
class BlurInvocation(BaseInvocation):
"""Blurs an image"""

#fmt: off
type: Literal["blur"] = "blur"

# Inputs
image: ImageField = Field(default=None, description="The image to blur")
radius: float = Field(default=8.0, ge=0, description="The blur radius")
blur_type: Literal["gaussian", "box"] = Field(
default="gaussian", description="The type of blur"
)

radius: float = Field(default=8.0, ge=0, description="The blur radius")
blur_type: Literal["gaussian", "box"] = Field(default="gaussian", description="The type of blur")
#fmt: on

def invoke(self, context: InvocationContext) -> ImageOutput:
image = context.services.images.get(
self.image.image_type, self.image.image_name
Expand All @@ -230,13 +222,14 @@ def invoke(self, context: InvocationContext) -> ImageOutput:

class LerpInvocation(BaseInvocation):
"""Linear interpolation of all pixels of an image"""

#fmt: off
type: Literal["lerp"] = "lerp"

# Inputs
image: ImageField = Field(default=None, description="The image to lerp")
min: int = Field(default=0, ge=0, le=255, description="The minimum output value")
max: int = Field(default=255, ge=0, le=255, description="The maximum output value")
#fmt: on

def invoke(self, context: InvocationContext) -> ImageOutput:
image = context.services.images.get(
Expand Down