mirror of
https://github.com/invoke-ai/InvokeAI
synced 2024-08-30 20:32:17 +00:00
feat(nodes): move all invocation metadata (type, title, tags, category) to decorator
All invocation metadata (type, title, tags and category) are now defined in decorators. The decorators add the `type: Literal["invocation_type"]: "invocation_type"` field to the invocation. Category is a new invocation metadata, but it is not used by the frontend just yet. - `@invocation()` decorator for invocations ```py @invocation( "sdxl_compel_prompt", title="SDXL Prompt", tags=["sdxl", "compel", "prompt"], category="conditioning", ) class SDXLCompelPromptInvocation(BaseInvocation, SDXLPromptInvocationBase): ... ``` - `@invocation_output()` decorator for invocation outputs ```py @invocation_output("clip_skip_output") class ClipSkipInvocationOutput(BaseInvocationOutput): ... ``` - update invocation docs - add category to decorator - regen frontend types
This commit is contained in:
parent
ae05d34584
commit
044d4c107a
@ -29,12 +29,13 @@ The first set of things we need to do when creating a new Invocation are -
|
|||||||
|
|
||||||
- Create a new class that derives from a predefined parent class called
|
- Create a new class that derives from a predefined parent class called
|
||||||
`BaseInvocation`.
|
`BaseInvocation`.
|
||||||
- The name of every Invocation must end with the word `Invocation` in order for
|
|
||||||
it to be recognized as an Invocation.
|
|
||||||
- Every Invocation must have a `docstring` that describes what this Invocation
|
- Every Invocation must have a `docstring` that describes what this Invocation
|
||||||
does.
|
does.
|
||||||
- Every Invocation must have a unique `type` field defined which becomes its
|
- While not strictly required, we suggest every invocation class name ends in
|
||||||
indentifier.
|
"Invocation", eg "CropImageInvocation".
|
||||||
|
- Every Invocation must use the `@invocation` decorator to provide its unique
|
||||||
|
invocation type. You may also provide its title, tags and category using the
|
||||||
|
decorator.
|
||||||
- Invocations are strictly typed. We make use of the native
|
- Invocations are strictly typed. We make use of the native
|
||||||
[typing](https://docs.python.org/3/library/typing.html) library and the
|
[typing](https://docs.python.org/3/library/typing.html) library and the
|
||||||
installed [pydantic](https://pydantic-docs.helpmanual.io/) library for
|
installed [pydantic](https://pydantic-docs.helpmanual.io/) library for
|
||||||
@ -43,12 +44,11 @@ The first set of things we need to do when creating a new Invocation are -
|
|||||||
So let us do that.
|
So let us do that.
|
||||||
|
|
||||||
```python
|
```python
|
||||||
from typing import Literal
|
from .baseinvocation import BaseInvocation, invocation
|
||||||
from .baseinvocation import BaseInvocation
|
|
||||||
|
|
||||||
|
@invocation('resize')
|
||||||
class ResizeInvocation(BaseInvocation):
|
class ResizeInvocation(BaseInvocation):
|
||||||
'''Resizes an image'''
|
'''Resizes an image'''
|
||||||
type: Literal['resize'] = 'resize'
|
|
||||||
```
|
```
|
||||||
|
|
||||||
That's great.
|
That's great.
|
||||||
@ -62,8 +62,10 @@ our Invocation takes.
|
|||||||
|
|
||||||
### **Inputs**
|
### **Inputs**
|
||||||
|
|
||||||
Every Invocation input is a pydantic `Field` and like everything else should be
|
Every Invocation input must be defined using the `InputField` function. This is
|
||||||
strictly typed and defined.
|
a wrapper around the pydantic `Field` function, which handles a few extra things
|
||||||
|
and provides type hints. Like everything else, this should be strictly typed and
|
||||||
|
defined.
|
||||||
|
|
||||||
So let us create these inputs for our Invocation. First up, the `image` input we
|
So let us create these inputs for our Invocation. First up, the `image` input we
|
||||||
need. Generally, we can use standard variable types in Python but InvokeAI
|
need. Generally, we can use standard variable types in Python but InvokeAI
|
||||||
@ -76,55 +78,51 @@ create your own custom field types later in this guide. For now, let's go ahead
|
|||||||
and use it.
|
and use it.
|
||||||
|
|
||||||
```python
|
```python
|
||||||
from typing import Literal, Union
|
from .baseinvocation import BaseInvocation, InputField, invocation
|
||||||
from pydantic import Field
|
from .primitives import ImageField
|
||||||
|
|
||||||
from .baseinvocation import BaseInvocation
|
|
||||||
from ..models.image import ImageField
|
|
||||||
|
|
||||||
|
@invocation('resize')
|
||||||
class ResizeInvocation(BaseInvocation):
|
class ResizeInvocation(BaseInvocation):
|
||||||
'''Resizes an image'''
|
|
||||||
type: Literal['resize'] = 'resize'
|
|
||||||
|
|
||||||
# Inputs
|
# Inputs
|
||||||
image: Union[ImageField, None] = Field(description="The input image", default=None)
|
image: ImageField = InputField(description="The input image")
|
||||||
```
|
```
|
||||||
|
|
||||||
Let us break down our input code.
|
Let us break down our input code.
|
||||||
|
|
||||||
```python
|
```python
|
||||||
image: Union[ImageField, None] = Field(description="The input image", default=None)
|
image: ImageField = InputField(description="The input image")
|
||||||
```
|
```
|
||||||
|
|
||||||
| Part | Value | Description |
|
| Part | Value | Description |
|
||||||
| --------- | ---------------------------------------------------- | -------------------------------------------------------------------------------------------------- |
|
| --------- | ------------------------------------------- | ------------------------------------------------------------------------------- |
|
||||||
| Name | `image` | The variable that will hold our image |
|
| Name | `image` | The variable that will hold our image |
|
||||||
| Type Hint | `Union[ImageField, None]` | The types for our field. Indicates that the image can either be an `ImageField` type or `None` |
|
| Type Hint | `ImageField` | The types for our field. Indicates that the image must be an `ImageField` type. |
|
||||||
| Field | `Field(description="The input image", default=None)` | The image variable is a field which needs a description and a default value that we set to `None`. |
|
| Field | `InputField(description="The input image")` | The image variable is an `InputField` which needs a description. |
|
||||||
|
|
||||||
Great. Now let us create our other inputs for `width` and `height`
|
Great. Now let us create our other inputs for `width` and `height`
|
||||||
|
|
||||||
```python
|
```python
|
||||||
from typing import Literal, Union
|
from .baseinvocation import BaseInvocation, InputField, invocation
|
||||||
from pydantic import Field
|
from .primitives import ImageField
|
||||||
|
|
||||||
from .baseinvocation import BaseInvocation
|
|
||||||
from ..models.image import ImageField
|
|
||||||
|
|
||||||
|
@invocation('resize')
|
||||||
class ResizeInvocation(BaseInvocation):
|
class ResizeInvocation(BaseInvocation):
|
||||||
'''Resizes an image'''
|
'''Resizes an image'''
|
||||||
type: Literal['resize'] = 'resize'
|
|
||||||
|
|
||||||
# Inputs
|
# Inputs
|
||||||
image: Union[ImageField, None] = Field(description="The input image", default=None)
|
image: ImageField = InputField(description="The input image")
|
||||||
width: int = Field(default=512, ge=64, le=2048, description="Width of the new image")
|
width: int = InputField(default=512, ge=64, le=2048, description="Width of the new image")
|
||||||
height: int = Field(default=512, ge=64, le=2048, description="Height of the new image")
|
height: int = InputField(default=512, ge=64, le=2048, description="Height of the new image")
|
||||||
```
|
```
|
||||||
|
|
||||||
As you might have noticed, we added two new parameters to the field type for
|
As you might have noticed, we added two new arguments to the `InputField`
|
||||||
`width` and `height` called `gt` and `le`. These basically stand for _greater
|
definition for `width` and `height`, called `gt` and `le`. They stand for
|
||||||
than or equal to_ and _less than or equal to_. There are various other param
|
_greater than or equal to_ and _less than or equal to_.
|
||||||
types for field that you can find on the **pydantic** documentation.
|
|
||||||
|
These impose contraints on those fields, and will raise an exception if the
|
||||||
|
values do not meet the constraints. Field constraints are provided by
|
||||||
|
**pydantic**, so anything you see in the **pydantic docs** will work.
|
||||||
|
|
||||||
**Note:** _Any time it is possible to define constraints for our field, we
|
**Note:** _Any time it is possible to define constraints for our field, we
|
||||||
should do it so the frontend has more information on how to parse this field._
|
should do it so the frontend has more information on how to parse this field._
|
||||||
@ -141,20 +139,17 @@ that are provided by it by InvokeAI.
|
|||||||
Let us create this function first.
|
Let us create this function first.
|
||||||
|
|
||||||
```python
|
```python
|
||||||
from typing import Literal, Union
|
from .baseinvocation import BaseInvocation, InputField, invocation
|
||||||
from pydantic import Field
|
from .primitives import ImageField
|
||||||
|
|
||||||
from .baseinvocation import BaseInvocation, InvocationContext
|
|
||||||
from ..models.image import ImageField
|
|
||||||
|
|
||||||
|
@invocation('resize')
|
||||||
class ResizeInvocation(BaseInvocation):
|
class ResizeInvocation(BaseInvocation):
|
||||||
'''Resizes an image'''
|
'''Resizes an image'''
|
||||||
type: Literal['resize'] = 'resize'
|
|
||||||
|
|
||||||
# Inputs
|
# Inputs
|
||||||
image: Union[ImageField, None] = Field(description="The input image", default=None)
|
image: ImageField = InputField(description="The input image")
|
||||||
width: int = Field(default=512, ge=64, le=2048, description="Width of the new image")
|
width: int = InputField(default=512, ge=64, le=2048, description="Width of the new image")
|
||||||
height: int = Field(default=512, ge=64, le=2048, description="Height of the new image")
|
height: int = InputField(default=512, ge=64, le=2048, description="Height of the new image")
|
||||||
|
|
||||||
def invoke(self, context: InvocationContext):
|
def invoke(self, context: InvocationContext):
|
||||||
pass
|
pass
|
||||||
@ -173,21 +168,18 @@ all the necessary info related to image outputs. So let us use that.
|
|||||||
We will cover how to create your own output types later in this guide.
|
We will cover how to create your own output types later in this guide.
|
||||||
|
|
||||||
```python
|
```python
|
||||||
from typing import Literal, Union
|
from .baseinvocation import BaseInvocation, InputField, invocation
|
||||||
from pydantic import Field
|
from .primitives import ImageField
|
||||||
|
|
||||||
from .baseinvocation import BaseInvocation, InvocationContext
|
|
||||||
from ..models.image import ImageField
|
|
||||||
from .image import ImageOutput
|
from .image import ImageOutput
|
||||||
|
|
||||||
|
@invocation('resize')
|
||||||
class ResizeInvocation(BaseInvocation):
|
class ResizeInvocation(BaseInvocation):
|
||||||
'''Resizes an image'''
|
'''Resizes an image'''
|
||||||
type: Literal['resize'] = 'resize'
|
|
||||||
|
|
||||||
# Inputs
|
# Inputs
|
||||||
image: Union[ImageField, None] = Field(description="The input image", default=None)
|
image: ImageField = InputField(description="The input image")
|
||||||
width: int = Field(default=512, ge=64, le=2048, description="Width of the new image")
|
width: int = InputField(default=512, ge=64, le=2048, description="Width of the new image")
|
||||||
height: int = Field(default=512, ge=64, le=2048, description="Height of the new image")
|
height: int = InputField(default=512, ge=64, le=2048, description="Height of the new image")
|
||||||
|
|
||||||
def invoke(self, context: InvocationContext) -> ImageOutput:
|
def invoke(self, context: InvocationContext) -> ImageOutput:
|
||||||
pass
|
pass
|
||||||
@ -195,39 +187,34 @@ class ResizeInvocation(BaseInvocation):
|
|||||||
|
|
||||||
Perfect. Now that we have our Invocation setup, let us do what we want to do.
|
Perfect. Now that we have our Invocation setup, let us do what we want to do.
|
||||||
|
|
||||||
- We will first load the image. Generally we do this using the `PIL` library but
|
- We will first load the image using one of the services provided by InvokeAI to
|
||||||
we can use one of the services provided by InvokeAI to load the image.
|
load the image.
|
||||||
- We will resize the image using `PIL` to our input data.
|
- We will resize the image using `PIL` to our input data.
|
||||||
- We will output this image in the format we set above.
|
- We will output this image in the format we set above.
|
||||||
|
|
||||||
So let's do that.
|
So let's do that.
|
||||||
|
|
||||||
```python
|
```python
|
||||||
from typing import Literal, Union
|
from .baseinvocation import BaseInvocation, InputField, invocation
|
||||||
from pydantic import Field
|
from .primitives import ImageField
|
||||||
|
|
||||||
from .baseinvocation import BaseInvocation, InvocationContext
|
|
||||||
from ..models.image import ImageField, ResourceOrigin, ImageCategory
|
|
||||||
from .image import ImageOutput
|
from .image import ImageOutput
|
||||||
|
|
||||||
|
@invocation("resize")
|
||||||
class ResizeInvocation(BaseInvocation):
|
class ResizeInvocation(BaseInvocation):
|
||||||
'''Resizes an image'''
|
"""Resizes an image"""
|
||||||
type: Literal['resize'] = 'resize'
|
|
||||||
|
|
||||||
# Inputs
|
image: ImageField = InputField(description="The input image")
|
||||||
image: Union[ImageField, None] = Field(description="The input image", default=None)
|
width: int = InputField(default=512, ge=64, le=2048, description="Width of the new image")
|
||||||
width: int = Field(default=512, ge=64, le=2048, description="Width of the new image")
|
height: int = InputField(default=512, ge=64, le=2048, description="Height of the new image")
|
||||||
height: int = Field(default=512, ge=64, le=2048, description="Height of the new image")
|
|
||||||
|
|
||||||
def invoke(self, context: InvocationContext) -> ImageOutput:
|
def invoke(self, context: InvocationContext) -> ImageOutput:
|
||||||
# Load the image using InvokeAI's predefined Image Service.
|
# Load the image using InvokeAI's predefined Image Service. Returns the PIL image.
|
||||||
image = context.services.images.get_pil_image(self.image.image_origin, self.image.image_name)
|
image = context.services.images.get_pil_image(self.image.image_name)
|
||||||
|
|
||||||
# Resizing the image
|
# Resizing the image
|
||||||
# Because we used the above service, we already have a PIL image. So we can simply resize.
|
|
||||||
resized_image = image.resize((self.width, self.height))
|
resized_image = image.resize((self.width, self.height))
|
||||||
|
|
||||||
# Preparing the image for output using InvokeAI's predefined Image Service.
|
# Save the image using InvokeAI's predefined Image Service. Returns the prepared PIL image.
|
||||||
output_image = context.services.images.create(
|
output_image = context.services.images.create(
|
||||||
image=resized_image,
|
image=resized_image,
|
||||||
image_origin=ResourceOrigin.INTERNAL,
|
image_origin=ResourceOrigin.INTERNAL,
|
||||||
@ -241,7 +228,6 @@ class ResizeInvocation(BaseInvocation):
|
|||||||
return ImageOutput(
|
return ImageOutput(
|
||||||
image=ImageField(
|
image=ImageField(
|
||||||
image_name=output_image.image_name,
|
image_name=output_image.image_name,
|
||||||
image_origin=output_image.image_origin,
|
|
||||||
),
|
),
|
||||||
width=output_image.width,
|
width=output_image.width,
|
||||||
height=output_image.height,
|
height=output_image.height,
|
||||||
@ -253,6 +239,20 @@ certain way that the images need to be dispatched in order to be stored and read
|
|||||||
correctly. In 99% of the cases when dealing with an image output, you can simply
|
correctly. In 99% of the cases when dealing with an image output, you can simply
|
||||||
copy-paste the template above.
|
copy-paste the template above.
|
||||||
|
|
||||||
|
### Customization
|
||||||
|
|
||||||
|
We can use the `@invocation` decorator to provide some additional info to the
|
||||||
|
UI, like a custom title, tags and category.
|
||||||
|
|
||||||
|
```python
|
||||||
|
@invocation("resize", title="My Resizer", tags=["resize", "image"], category="My Invocations")
|
||||||
|
class ResizeInvocation(BaseInvocation):
|
||||||
|
"""Resizes an image"""
|
||||||
|
|
||||||
|
image: ImageField = InputField(description="The input image")
|
||||||
|
...
|
||||||
|
```
|
||||||
|
|
||||||
That's it. You made your own **Resize Invocation**.
|
That's it. You made your own **Resize Invocation**.
|
||||||
|
|
||||||
## Result
|
## Result
|
||||||
@ -271,10 +271,57 @@ new Invocation ready to be used.
|
|||||||
![resize node editor](../assets/contributing/resize_node_editor.png)
|
![resize node editor](../assets/contributing/resize_node_editor.png)
|
||||||
|
|
||||||
## Contributing Nodes
|
## Contributing Nodes
|
||||||
Once you've created a Node, the next step is to share it with the community! The best way to do this is to submit a Pull Request to add the Node to the [Community Nodes](nodes/communityNodes) list. If you're not sure how to do that, take a look a at our [contributing nodes overview](contributingNodes).
|
|
||||||
|
Once you've created a Node, the next step is to share it with the community! The
|
||||||
|
best way to do this is to submit a Pull Request to add the Node to the
|
||||||
|
[Community Nodes](nodes/communityNodes) list. If you're not sure how to do that,
|
||||||
|
take a look a at our [contributing nodes overview](contributingNodes).
|
||||||
|
|
||||||
## Advanced
|
## Advanced
|
||||||
|
|
||||||
|
-->
|
||||||
|
|
||||||
|
### Custom Output Types
|
||||||
|
|
||||||
|
Like with custom inputs, sometimes you might find yourself needing custom
|
||||||
|
outputs that InvokeAI does not provide. We can easily set one up.
|
||||||
|
|
||||||
|
Now that you are familiar with Invocations and Inputs, let us use that knowledge
|
||||||
|
to create an output that has an `image` field, a `color` field and a `string`
|
||||||
|
field.
|
||||||
|
|
||||||
|
- An invocation output is a class that derives from the parent class of
|
||||||
|
`BaseInvocationOutput`.
|
||||||
|
- All invocation outputs must use the `@invocation_output` decorator to provide
|
||||||
|
their unique output type.
|
||||||
|
- Output fields must use the provided `OutputField` function. This is very
|
||||||
|
similar to the `InputField` function described earlier - it's a wrapper around
|
||||||
|
`pydantic`'s `Field()`.
|
||||||
|
- It is not mandatory but we recommend using names ending with `Output` for
|
||||||
|
output types.
|
||||||
|
- It is not mandatory but we highly recommend adding a `docstring` to describe
|
||||||
|
what your output type is for.
|
||||||
|
|
||||||
|
Now that we know the basic rules for creating a new output type, let us go ahead
|
||||||
|
and make it.
|
||||||
|
|
||||||
|
```python
|
||||||
|
from .baseinvocation import BaseInvocationOutput, OutputField, invocation_output
|
||||||
|
from .primitives import ImageField, ColorField
|
||||||
|
|
||||||
|
@invocation_output('image_color_string_output')
|
||||||
|
class ImageColorStringOutput(BaseInvocationOutput):
|
||||||
|
'''Base class for nodes that output a single image'''
|
||||||
|
|
||||||
|
image: ImageField = OutputField(description="The image")
|
||||||
|
color: ColorField = OutputField(description="The color")
|
||||||
|
text: str = OutputField(description="The string")
|
||||||
|
```
|
||||||
|
|
||||||
|
That's all there is to it.
|
||||||
|
|
||||||
|
<!-- TODO: DANGER - we probably do not want people to create their own field types, because this requires a lot of work on the frontend to accomodate.
|
||||||
|
|
||||||
### Custom Input Fields
|
### Custom Input Fields
|
||||||
|
|
||||||
Now that you know how to create your own Invocations, let us dive into slightly
|
Now that you know how to create your own Invocations, let us dive into slightly
|
||||||
@ -329,172 +376,6 @@ like this.
|
|||||||
color: ColorField = Field(default=ColorField(r=0, g=0, b=0, a=0), description='Background color of an image')
|
color: ColorField = Field(default=ColorField(r=0, g=0, b=0, a=0), description='Background color of an image')
|
||||||
```
|
```
|
||||||
|
|
||||||
**Extra Config**
|
|
||||||
|
|
||||||
All input fields also take an additional `Config` class that you can use to do
|
|
||||||
various advanced things like setting required parameters and etc.
|
|
||||||
|
|
||||||
Let us do that for our _ColorField_ and enforce all the values because we did
|
|
||||||
not define any defaults for our fields.
|
|
||||||
|
|
||||||
```python
|
|
||||||
class ColorField(BaseModel):
|
|
||||||
'''A field that holds the rgba values of a color'''
|
|
||||||
r: int = Field(ge=0, le=255, description="The red channel")
|
|
||||||
g: int = Field(ge=0, le=255, description="The green channel")
|
|
||||||
b: int = Field(ge=0, le=255, description="The blue channel")
|
|
||||||
a: int = Field(ge=0, le=255, description="The alpha channel")
|
|
||||||
|
|
||||||
class Config:
|
|
||||||
schema_extra = {"required": ["r", "g", "b", "a"]}
|
|
||||||
```
|
|
||||||
|
|
||||||
Now it becomes mandatory for the user to supply all the values required by our
|
|
||||||
input field.
|
|
||||||
|
|
||||||
We will discuss the `Config` class in extra detail later in this guide and how
|
|
||||||
you can use it to make your Invocations more robust.
|
|
||||||
|
|
||||||
### Custom Output Types
|
|
||||||
|
|
||||||
Like with custom inputs, sometimes you might find yourself needing custom
|
|
||||||
outputs that InvokeAI does not provide. We can easily set one up.
|
|
||||||
|
|
||||||
Now that you are familiar with Invocations and Inputs, let us use that knowledge
|
|
||||||
to put together a custom output type for an Invocation that returns _width_,
|
|
||||||
_height_ and _background_color_ that we need to create a blank image.
|
|
||||||
|
|
||||||
- A custom output type is a class that derives from the parent class of
|
|
||||||
`BaseInvocationOutput`.
|
|
||||||
- It is not mandatory but we recommend using names ending with `Output` for
|
|
||||||
output types. So we'll call our class `BlankImageOutput`
|
|
||||||
- It is not mandatory but we highly recommend adding a `docstring` to describe
|
|
||||||
what your output type is for.
|
|
||||||
- Like Invocations, each output type should have a `type` variable that is
|
|
||||||
**unique**
|
|
||||||
|
|
||||||
Now that we know the basic rules for creating a new output type, let us go ahead
|
|
||||||
and make it.
|
|
||||||
|
|
||||||
```python
|
|
||||||
from typing import Literal
|
|
||||||
from pydantic import Field
|
|
||||||
|
|
||||||
from .baseinvocation import BaseInvocationOutput
|
|
||||||
|
|
||||||
class BlankImageOutput(BaseInvocationOutput):
|
|
||||||
'''Base output type for creating a blank image'''
|
|
||||||
type: Literal['blank_image_output'] = 'blank_image_output'
|
|
||||||
|
|
||||||
# Inputs
|
|
||||||
width: int = Field(description='Width of blank image')
|
|
||||||
height: int = Field(description='Height of blank image')
|
|
||||||
bg_color: ColorField = Field(description='Background color of blank image')
|
|
||||||
|
|
||||||
class Config:
|
|
||||||
schema_extra = {"required": ["type", "width", "height", "bg_color"]}
|
|
||||||
```
|
|
||||||
|
|
||||||
All set. We now have an output type that requires what we need to create a
|
|
||||||
blank_image. And if you noticed it, we even used the `Config` class to ensure
|
|
||||||
the fields are required.
|
|
||||||
|
|
||||||
### Custom Configuration
|
|
||||||
|
|
||||||
As you might have noticed when making inputs and outputs, we used a class called
|
|
||||||
`Config` from _pydantic_ to further customize them. Because our inputs and
|
|
||||||
outputs essentially inherit from _pydantic_'s `BaseModel` class, all
|
|
||||||
[configuration options](https://docs.pydantic.dev/latest/usage/schema/#schema-customization)
|
|
||||||
that are valid for _pydantic_ classes are also valid for our inputs and outputs.
|
|
||||||
You can do the same for your Invocations too but InvokeAI makes our life a
|
|
||||||
little bit easier on that end.
|
|
||||||
|
|
||||||
InvokeAI provides a custom configuration class called `InvocationConfig`
|
|
||||||
particularly for configuring Invocations. This is exactly the same as the raw
|
|
||||||
`Config` class from _pydantic_ with some extra stuff on top to help faciliate
|
|
||||||
parsing of the scheme in the frontend UI.
|
|
||||||
|
|
||||||
At the current moment, tihs `InvocationConfig` class is further improved with
|
|
||||||
the following features related the `ui`.
|
|
||||||
|
|
||||||
| Config Option | Field Type | Example |
|
|
||||||
| ------------- | ------------------------------------------------------------------------------------------------------------- | --------------------------------------------------------------------------------------------------------------------- |
|
|
||||||
| type_hints | `Dict[str, Literal["integer", "float", "boolean", "string", "enum", "image", "latents", "model", "control"]]` | `type_hint: "model"` provides type hints related to the model like displaying a list of available models |
|
|
||||||
| tags | `List[str]` | `tags: ['resize', 'image']` will classify your invocation under the tags of resize and image. |
|
|
||||||
| title | `str` | `title: 'Resize Image` will rename your to this custom title rather than infer from the name of the Invocation class. |
|
|
||||||
|
|
||||||
So let us update your `ResizeInvocation` with some extra configuration and see
|
|
||||||
how that works.
|
|
||||||
|
|
||||||
```python
|
|
||||||
from typing import Literal, Union
|
|
||||||
from pydantic import Field
|
|
||||||
|
|
||||||
from .baseinvocation import BaseInvocation, InvocationContext, InvocationConfig
|
|
||||||
from ..models.image import ImageField, ResourceOrigin, ImageCategory
|
|
||||||
from .image import ImageOutput
|
|
||||||
|
|
||||||
class ResizeInvocation(BaseInvocation):
|
|
||||||
'''Resizes an image'''
|
|
||||||
type: Literal['resize'] = 'resize'
|
|
||||||
|
|
||||||
# Inputs
|
|
||||||
image: Union[ImageField, None] = Field(description="The input image", default=None)
|
|
||||||
width: int = Field(default=512, ge=64, le=2048, description="Width of the new image")
|
|
||||||
height: int = Field(default=512, ge=64, le=2048, description="Height of the new image")
|
|
||||||
|
|
||||||
class Config(InvocationConfig):
|
|
||||||
schema_extra: {
|
|
||||||
ui: {
|
|
||||||
tags: ['resize', 'image'],
|
|
||||||
title: ['My Custom Resize']
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
def invoke(self, context: InvocationContext) -> ImageOutput:
|
|
||||||
# Load the image using InvokeAI's predefined Image Service.
|
|
||||||
image = context.services.images.get_pil_image(self.image.image_origin, self.image.image_name)
|
|
||||||
|
|
||||||
# Resizing the image
|
|
||||||
# Because we used the above service, we already have a PIL image. So we can simply resize.
|
|
||||||
resized_image = image.resize((self.width, self.height))
|
|
||||||
|
|
||||||
# Preparing the image for output using InvokeAI's predefined Image Service.
|
|
||||||
output_image = context.services.images.create(
|
|
||||||
image=resized_image,
|
|
||||||
image_origin=ResourceOrigin.INTERNAL,
|
|
||||||
image_category=ImageCategory.GENERAL,
|
|
||||||
node_id=self.id,
|
|
||||||
session_id=context.graph_execution_state_id,
|
|
||||||
is_intermediate=self.is_intermediate,
|
|
||||||
)
|
|
||||||
|
|
||||||
# Returning the Image
|
|
||||||
return ImageOutput(
|
|
||||||
image=ImageField(
|
|
||||||
image_name=output_image.image_name,
|
|
||||||
image_origin=output_image.image_origin,
|
|
||||||
),
|
|
||||||
width=output_image.width,
|
|
||||||
height=output_image.height,
|
|
||||||
)
|
|
||||||
```
|
|
||||||
|
|
||||||
We now customized our code to let the frontend know that our Invocation falls
|
|
||||||
under `resize` and `image` categories. So when the user searches for these
|
|
||||||
particular words, our Invocation will show up too.
|
|
||||||
|
|
||||||
We also set a custom title for our Invocation. So instead of being called
|
|
||||||
`Resize`, it will be called `My Custom Resize`.
|
|
||||||
|
|
||||||
As simple as that.
|
|
||||||
|
|
||||||
As time goes by, InvokeAI will further improve and add more customizability for
|
|
||||||
Invocation configuration. We will have more documentation regarding this at a
|
|
||||||
later time.
|
|
||||||
|
|
||||||
# **[TODO]**
|
|
||||||
|
|
||||||
### Custom Components For Frontend
|
### Custom Components For Frontend
|
||||||
|
|
||||||
Every backend input type should have a corresponding frontend component so the
|
Every backend input type should have a corresponding frontend component so the
|
||||||
@ -513,282 +394,4 @@ Let us create a new component for our custom color field we created above. When
|
|||||||
we use a color field, let us say we want the UI to display a color picker for
|
we use a color field, let us say we want the UI to display a color picker for
|
||||||
the user to pick from rather than entering values. That is what we will build
|
the user to pick from rather than entering values. That is what we will build
|
||||||
now.
|
now.
|
||||||
|
-->
|
||||||
---
|
|
||||||
|
|
||||||
<!-- # OLD -- TO BE DELETED OR MOVED LATER
|
|
||||||
|
|
||||||
---
|
|
||||||
|
|
||||||
## Creating a new invocation
|
|
||||||
|
|
||||||
To create a new invocation, either find the appropriate module file in
|
|
||||||
`/ldm/invoke/app/invocations` to add your invocation to, or create a new one in
|
|
||||||
that folder. All invocations in that folder will be discovered and made
|
|
||||||
available to the CLI and API automatically. Invocations make use of
|
|
||||||
[typing](https://docs.python.org/3/library/typing.html) and
|
|
||||||
[pydantic](https://pydantic-docs.helpmanual.io/) for validation and integration
|
|
||||||
into the CLI and API.
|
|
||||||
|
|
||||||
An invocation looks like this:
|
|
||||||
|
|
||||||
```py
|
|
||||||
class UpscaleInvocation(BaseInvocation):
|
|
||||||
"""Upscales an image."""
|
|
||||||
|
|
||||||
# fmt: off
|
|
||||||
type: Literal["upscale"] = "upscale"
|
|
||||||
|
|
||||||
# Inputs
|
|
||||||
image: Union[ImageField, None] = Field(description="The input image", default=None)
|
|
||||||
strength: float = Field(default=0.75, gt=0, le=1, description="The strength")
|
|
||||||
level: Literal[2, 4] = Field(default=2, description="The upscale level")
|
|
||||||
# fmt: on
|
|
||||||
|
|
||||||
# Schema customisation
|
|
||||||
class Config(InvocationConfig):
|
|
||||||
schema_extra = {
|
|
||||||
"ui": {
|
|
||||||
"tags": ["upscaling", "image"],
|
|
||||||
},
|
|
||||||
}
|
|
||||||
|
|
||||||
def invoke(self, context: InvocationContext) -> ImageOutput:
|
|
||||||
image = context.services.images.get_pil_image(
|
|
||||||
self.image.image_origin, self.image.image_name
|
|
||||||
)
|
|
||||||
results = context.services.restoration.upscale_and_reconstruct(
|
|
||||||
image_list=[[image, 0]],
|
|
||||||
upscale=(self.level, self.strength),
|
|
||||||
strength=0.0, # GFPGAN strength
|
|
||||||
save_original=False,
|
|
||||||
image_callback=None,
|
|
||||||
)
|
|
||||||
|
|
||||||
# Results are image and seed, unwrap for now
|
|
||||||
# TODO: can this return multiple results?
|
|
||||||
image_dto = context.services.images.create(
|
|
||||||
image=results[0][0],
|
|
||||||
image_origin=ResourceOrigin.INTERNAL,
|
|
||||||
image_category=ImageCategory.GENERAL,
|
|
||||||
node_id=self.id,
|
|
||||||
session_id=context.graph_execution_state_id,
|
|
||||||
is_intermediate=self.is_intermediate,
|
|
||||||
)
|
|
||||||
|
|
||||||
return ImageOutput(
|
|
||||||
image=ImageField(
|
|
||||||
image_name=image_dto.image_name,
|
|
||||||
image_origin=image_dto.image_origin,
|
|
||||||
),
|
|
||||||
width=image_dto.width,
|
|
||||||
height=image_dto.height,
|
|
||||||
)
|
|
||||||
|
|
||||||
```
|
|
||||||
|
|
||||||
Each portion is important to implement correctly.
|
|
||||||
|
|
||||||
### Class definition and type
|
|
||||||
|
|
||||||
```py
|
|
||||||
class UpscaleInvocation(BaseInvocation):
|
|
||||||
"""Upscales an image."""
|
|
||||||
type: Literal['upscale'] = 'upscale'
|
|
||||||
```
|
|
||||||
|
|
||||||
All invocations must derive from `BaseInvocation`. They should have a docstring
|
|
||||||
that declares what they do in a single, short line. They should also have a
|
|
||||||
`type` with a type hint that's `Literal["command_name"]`, where `command_name`
|
|
||||||
is what the user will type on the CLI or use in the API to create this
|
|
||||||
invocation. The `command_name` must be unique. The `type` must be assigned to
|
|
||||||
the value of the literal in the type hint.
|
|
||||||
|
|
||||||
### Inputs
|
|
||||||
|
|
||||||
```py
|
|
||||||
# Inputs
|
|
||||||
image: Union[ImageField,None] = Field(description="The input image")
|
|
||||||
strength: float = Field(default=0.75, gt=0, le=1, description="The strength")
|
|
||||||
level: Literal[2,4] = Field(default=2, description="The upscale level")
|
|
||||||
```
|
|
||||||
|
|
||||||
Inputs consist of three parts: a name, a type hint, and a `Field` with default,
|
|
||||||
description, and validation information. For example:
|
|
||||||
|
|
||||||
| Part | Value | Description |
|
|
||||||
| --------- | ------------------------------------------------------------- | ------------------------------------------------------------------------------------------------------------------------- |
|
|
||||||
| Name | `strength` | This field is referred to as `strength` |
|
|
||||||
| Type Hint | `float` | This field must be of type `float` |
|
|
||||||
| Field | `Field(default=0.75, gt=0, le=1, description="The strength")` | The default value is `0.75`, the value must be in the range (0,1], and help text will show "The strength" for this field. |
|
|
||||||
|
|
||||||
Notice that `image` has type `Union[ImageField,None]`. The `Union` allows this
|
|
||||||
field to be parsed with `None` as a value, which enables linking to previous
|
|
||||||
invocations. All fields should either provide a default value or allow `None` as
|
|
||||||
a value, so that they can be overwritten with a linked output from another
|
|
||||||
invocation.
|
|
||||||
|
|
||||||
The special type `ImageField` is also used here. All images are passed as
|
|
||||||
`ImageField`, which protects them from pydantic validation errors (since images
|
|
||||||
only ever come from links).
|
|
||||||
|
|
||||||
Finally, note that for all linking, the `type` of the linked fields must match.
|
|
||||||
If the `name` also matches, then the field can be **automatically linked** to a
|
|
||||||
previous invocation by name and matching.
|
|
||||||
|
|
||||||
### Config
|
|
||||||
|
|
||||||
```py
|
|
||||||
# Schema customisation
|
|
||||||
class Config(InvocationConfig):
|
|
||||||
schema_extra = {
|
|
||||||
"ui": {
|
|
||||||
"tags": ["upscaling", "image"],
|
|
||||||
},
|
|
||||||
}
|
|
||||||
```
|
|
||||||
|
|
||||||
This is an optional configuration for the invocation. It inherits from
|
|
||||||
pydantic's model `Config` class, and it used primarily to customize the
|
|
||||||
autogenerated OpenAPI schema.
|
|
||||||
|
|
||||||
The UI relies on the OpenAPI schema in two ways:
|
|
||||||
|
|
||||||
- An API client & Typescript types are generated from it. This happens at build
|
|
||||||
time.
|
|
||||||
- The node editor parses the schema into a template used by the UI to create the
|
|
||||||
node editor UI. This parsing happens at runtime.
|
|
||||||
|
|
||||||
In this example, a `ui` key has been added to the `schema_extra` dict to provide
|
|
||||||
some tags for the UI, to facilitate filtering nodes.
|
|
||||||
|
|
||||||
See the Schema Generation section below for more information.
|
|
||||||
|
|
||||||
### Invoke Function
|
|
||||||
|
|
||||||
```py
|
|
||||||
def invoke(self, context: InvocationContext) -> ImageOutput:
|
|
||||||
image = context.services.images.get_pil_image(
|
|
||||||
self.image.image_origin, self.image.image_name
|
|
||||||
)
|
|
||||||
results = context.services.restoration.upscale_and_reconstruct(
|
|
||||||
image_list=[[image, 0]],
|
|
||||||
upscale=(self.level, self.strength),
|
|
||||||
strength=0.0, # GFPGAN strength
|
|
||||||
save_original=False,
|
|
||||||
image_callback=None,
|
|
||||||
)
|
|
||||||
|
|
||||||
# Results are image and seed, unwrap for now
|
|
||||||
# TODO: can this return multiple results?
|
|
||||||
image_dto = context.services.images.create(
|
|
||||||
image=results[0][0],
|
|
||||||
image_origin=ResourceOrigin.INTERNAL,
|
|
||||||
image_category=ImageCategory.GENERAL,
|
|
||||||
node_id=self.id,
|
|
||||||
session_id=context.graph_execution_state_id,
|
|
||||||
is_intermediate=self.is_intermediate,
|
|
||||||
)
|
|
||||||
|
|
||||||
return ImageOutput(
|
|
||||||
image=ImageField(
|
|
||||||
image_name=image_dto.image_name,
|
|
||||||
image_origin=image_dto.image_origin,
|
|
||||||
),
|
|
||||||
width=image_dto.width,
|
|
||||||
height=image_dto.height,
|
|
||||||
)
|
|
||||||
```
|
|
||||||
|
|
||||||
The `invoke` function is the last portion of an invocation. It is provided an
|
|
||||||
`InvocationContext` which contains services to perform work as well as a
|
|
||||||
`session_id` for use as needed. It should return a class with output values that
|
|
||||||
derives from `BaseInvocationOutput`.
|
|
||||||
|
|
||||||
Before being called, the invocation will have all of its fields set from
|
|
||||||
defaults, inputs, and finally links (overriding in that order).
|
|
||||||
|
|
||||||
Assume that this invocation may be running simultaneously with other
|
|
||||||
invocations, may be running on another machine, or in other interesting
|
|
||||||
scenarios. If you need functionality, please provide it as a service in the
|
|
||||||
`InvocationServices` class, and make sure it can be overridden.
|
|
||||||
|
|
||||||
### Outputs
|
|
||||||
|
|
||||||
```py
|
|
||||||
class ImageOutput(BaseInvocationOutput):
|
|
||||||
"""Base class for invocations that output an image"""
|
|
||||||
|
|
||||||
# fmt: off
|
|
||||||
type: Literal["image_output"] = "image_output"
|
|
||||||
image: ImageField = Field(default=None, description="The output image")
|
|
||||||
width: int = Field(description="The width of the image in pixels")
|
|
||||||
height: int = Field(description="The height of the image in pixels")
|
|
||||||
# fmt: on
|
|
||||||
|
|
||||||
class Config:
|
|
||||||
schema_extra = {"required": ["type", "image", "width", "height"]}
|
|
||||||
```
|
|
||||||
|
|
||||||
Output classes look like an invocation class without the invoke method. Prefer
|
|
||||||
to use an existing output class if available, and prefer to name inputs the same
|
|
||||||
as outputs when possible, to promote automatic invocation linking.
|
|
||||||
|
|
||||||
## Schema Generation
|
|
||||||
|
|
||||||
Invocation, output and related classes are used to generate an OpenAPI schema.
|
|
||||||
|
|
||||||
### Required Properties
|
|
||||||
|
|
||||||
The schema generation treat all properties with default values as optional. This
|
|
||||||
makes sense internally, but when when using these classes via the generated
|
|
||||||
schema, we end up with e.g. the `ImageOutput` class having its `image` property
|
|
||||||
marked as optional.
|
|
||||||
|
|
||||||
We know that this property will always be present, so the additional logic
|
|
||||||
needed to always check if the property exists adds a lot of extraneous cruft.
|
|
||||||
|
|
||||||
To fix this, we can leverage `pydantic`'s
|
|
||||||
[schema customisation](https://docs.pydantic.dev/usage/schema/#schema-customization)
|
|
||||||
to mark properties that we know will always be present as required.
|
|
||||||
|
|
||||||
Here's that `ImageOutput` class, without the needed schema customisation:
|
|
||||||
|
|
||||||
```python
|
|
||||||
class ImageOutput(BaseInvocationOutput):
|
|
||||||
"""Base class for invocations that output an image"""
|
|
||||||
|
|
||||||
# fmt: off
|
|
||||||
type: Literal["image_output"] = "image_output"
|
|
||||||
image: ImageField = Field(default=None, description="The output image")
|
|
||||||
width: int = Field(description="The width of the image in pixels")
|
|
||||||
height: int = Field(description="The height of the image in pixels")
|
|
||||||
# fmt: on
|
|
||||||
```
|
|
||||||
|
|
||||||
The OpenAPI schema that results from this `ImageOutput` will have the `type`,
|
|
||||||
`image`, `width` and `height` properties marked as optional, even though we know
|
|
||||||
they will always have a value.
|
|
||||||
|
|
||||||
```python
|
|
||||||
class ImageOutput(BaseInvocationOutput):
|
|
||||||
"""Base class for invocations that output an image"""
|
|
||||||
|
|
||||||
# fmt: off
|
|
||||||
type: Literal["image_output"] = "image_output"
|
|
||||||
image: ImageField = Field(default=None, description="The output image")
|
|
||||||
width: int = Field(description="The width of the image in pixels")
|
|
||||||
height: int = Field(description="The height of the image in pixels")
|
|
||||||
# fmt: on
|
|
||||||
|
|
||||||
# Add schema customization
|
|
||||||
class Config:
|
|
||||||
schema_extra = {"required": ["type", "image", "width", "height"]}
|
|
||||||
```
|
|
||||||
|
|
||||||
With the customization in place, the schema will now show these properties as
|
|
||||||
required, obviating the need for extensive null checks in client code.
|
|
||||||
|
|
||||||
See this `pydantic` issue for discussion on this solution:
|
|
||||||
<https://github.com/pydantic/pydantic/discussions/4577> -->
|
|
||||||
|
|
||||||
|
@ -2,16 +2,18 @@
|
|||||||
|
|
||||||
from __future__ import annotations
|
from __future__ import annotations
|
||||||
|
|
||||||
|
import json
|
||||||
from abc import ABC, abstractmethod
|
from abc import ABC, abstractmethod
|
||||||
from enum import Enum
|
from enum import Enum
|
||||||
from inspect import signature
|
from inspect import signature
|
||||||
import json
|
import re
|
||||||
from typing import (
|
from typing import (
|
||||||
TYPE_CHECKING,
|
TYPE_CHECKING,
|
||||||
AbstractSet,
|
AbstractSet,
|
||||||
Any,
|
Any,
|
||||||
Callable,
|
Callable,
|
||||||
ClassVar,
|
ClassVar,
|
||||||
|
Literal,
|
||||||
Mapping,
|
Mapping,
|
||||||
Optional,
|
Optional,
|
||||||
Type,
|
Type,
|
||||||
@ -22,7 +24,7 @@ from typing import (
|
|||||||
)
|
)
|
||||||
|
|
||||||
from pydantic import BaseModel, Field, validator
|
from pydantic import BaseModel, Field, validator
|
||||||
from pydantic.fields import Undefined
|
from pydantic.fields import Undefined, ModelField
|
||||||
from pydantic.typing import NoArgAnyCallable
|
from pydantic.typing import NoArgAnyCallable
|
||||||
|
|
||||||
if TYPE_CHECKING:
|
if TYPE_CHECKING:
|
||||||
@ -368,8 +370,7 @@ def OutputField(
|
|||||||
class UIConfigBase(BaseModel):
|
class UIConfigBase(BaseModel):
|
||||||
"""
|
"""
|
||||||
Provides additional node configuration to the UI.
|
Provides additional node configuration to the UI.
|
||||||
This is used internally by the @tags and @title decorator logic. You probably want to use those
|
This is used internally by the @invocation decorator logic. Do not use this directly.
|
||||||
decorators, though you may add this class to a node definition to specify the title and tags.
|
|
||||||
"""
|
"""
|
||||||
|
|
||||||
tags: Optional[list[str]] = Field(default_factory=None, description="The node's tags")
|
tags: Optional[list[str]] = Field(default_factory=None, description="The node's tags")
|
||||||
@ -387,10 +388,11 @@ class InvocationContext:
|
|||||||
|
|
||||||
|
|
||||||
class BaseInvocationOutput(BaseModel):
|
class BaseInvocationOutput(BaseModel):
|
||||||
"""Base class for all invocation outputs"""
|
"""
|
||||||
|
Base class for all invocation outputs.
|
||||||
|
|
||||||
# All outputs must include a type name like this:
|
All invocation outputs must use the `@invocation_output` decorator to provide their unique type.
|
||||||
# type: Literal['your_output_name'] # noqa f821
|
"""
|
||||||
|
|
||||||
@classmethod
|
@classmethod
|
||||||
def get_all_subclasses_tuple(cls):
|
def get_all_subclasses_tuple(cls):
|
||||||
@ -426,12 +428,12 @@ class MissingInputException(Exception):
|
|||||||
|
|
||||||
|
|
||||||
class BaseInvocation(ABC, BaseModel):
|
class BaseInvocation(ABC, BaseModel):
|
||||||
"""A node to process inputs and produce outputs.
|
|
||||||
May use dependency injection in __init__ to receive providers.
|
|
||||||
"""
|
"""
|
||||||
|
A node to process inputs and produce outputs.
|
||||||
|
May use dependency injection in __init__ to receive providers.
|
||||||
|
|
||||||
# All invocations must include a type name like this:
|
All invocations must use the `@invocation` decorator to provide their unique type.
|
||||||
# type: Literal['your_output_name'] # noqa f821
|
"""
|
||||||
|
|
||||||
@classmethod
|
@classmethod
|
||||||
def get_all_subclasses(cls):
|
def get_all_subclasses(cls):
|
||||||
@ -511,9 +513,11 @@ class BaseInvocation(ABC, BaseModel):
|
|||||||
raise MissingInputException(self.__fields__["type"].default, field_name)
|
raise MissingInputException(self.__fields__["type"].default, field_name)
|
||||||
return self.invoke(context)
|
return self.invoke(context)
|
||||||
|
|
||||||
id: str = Field(description="The id of this node. Must be unique among all nodes.")
|
id: str = Field(
|
||||||
|
description="The id of this instance of an invocation. Must be unique among all instances of invocations."
|
||||||
|
)
|
||||||
is_intermediate: bool = InputField(
|
is_intermediate: bool = InputField(
|
||||||
default=False, description="Whether or not this node is an intermediate node.", ui_type=UIType.IsIntermediate
|
default=False, description="Whether or not this is an intermediate invocation.", ui_type=UIType.IsIntermediate
|
||||||
)
|
)
|
||||||
workflow: Optional[str] = InputField(
|
workflow: Optional[str] = InputField(
|
||||||
default=None,
|
default=None,
|
||||||
@ -534,66 +538,85 @@ class BaseInvocation(ABC, BaseModel):
|
|||||||
UIConfig: ClassVar[Type[UIConfigBase]]
|
UIConfig: ClassVar[Type[UIConfigBase]]
|
||||||
|
|
||||||
|
|
||||||
T = TypeVar("T", bound=BaseInvocation)
|
GenericBaseInvocation = TypeVar("GenericBaseInvocation", bound=BaseInvocation)
|
||||||
|
|
||||||
|
|
||||||
def title(title: str) -> Callable[[Type[T]], Type[T]]:
|
def invocation(
|
||||||
"""Adds a title to the invocation. Use this to override the default title generation, which is based on the class name."""
|
invocation_type: str, title: Optional[str] = None, tags: Optional[list[str]] = None, category: Optional[str] = None
|
||||||
|
) -> Callable[[Type[GenericBaseInvocation]], Type[GenericBaseInvocation]]:
|
||||||
def wrapper(cls: Type[T]) -> Type[T]:
|
|
||||||
uiconf_name = cls.__qualname__ + ".UIConfig"
|
|
||||||
if not hasattr(cls, "UIConfig") or cls.UIConfig.__qualname__ != uiconf_name:
|
|
||||||
cls.UIConfig = type(uiconf_name, (UIConfigBase,), dict())
|
|
||||||
cls.UIConfig.title = title
|
|
||||||
return cls
|
|
||||||
|
|
||||||
return wrapper
|
|
||||||
|
|
||||||
|
|
||||||
def tags(*tags: str) -> Callable[[Type[T]], Type[T]]:
|
|
||||||
"""Adds tags to the invocation. Use this to improve the streamline finding the invocation in the UI."""
|
|
||||||
|
|
||||||
def wrapper(cls: Type[T]) -> Type[T]:
|
|
||||||
uiconf_name = cls.__qualname__ + ".UIConfig"
|
|
||||||
if not hasattr(cls, "UIConfig") or cls.UIConfig.__qualname__ != uiconf_name:
|
|
||||||
cls.UIConfig = type(uiconf_name, (UIConfigBase,), dict())
|
|
||||||
cls.UIConfig.tags = list(tags)
|
|
||||||
return cls
|
|
||||||
|
|
||||||
return wrapper
|
|
||||||
|
|
||||||
|
|
||||||
def category(category: str) -> Callable[[Type[T]], Type[T]]:
|
|
||||||
"""Adds a category to the invocation. This is used to group invocations in the UI."""
|
|
||||||
|
|
||||||
def wrapper(cls: Type[T]) -> Type[T]:
|
|
||||||
uiconf_name = cls.__qualname__ + ".UIConfig"
|
|
||||||
if not hasattr(cls, "UIConfig") or cls.UIConfig.__qualname__ != uiconf_name:
|
|
||||||
cls.UIConfig = type(uiconf_name, (UIConfigBase,), dict())
|
|
||||||
cls.UIConfig.category = category
|
|
||||||
return cls
|
|
||||||
|
|
||||||
return wrapper
|
|
||||||
|
|
||||||
|
|
||||||
def node(
|
|
||||||
title: Optional[str] = None, tags: Optional[list[str]] = None, category: Optional[str] = None
|
|
||||||
) -> Callable[[Type[T]], Type[T]]:
|
|
||||||
"""
|
"""
|
||||||
Adds metadata to the invocation as a decorator.
|
Adds metadata to an invocation.
|
||||||
|
|
||||||
:param Optional[str] title: Adds a title to the node. Use if the auto-generated title isn't quite right. Defaults to None.
|
:param str invocation_type: The type of the invocation. Must be unique among all invocations.
|
||||||
:param Optional[list[str]] tags: Adds tags to the node. Nodes may be searched for by their tags. Defaults to None.
|
:param Optional[str] title: Adds a title to the invocation. Use if the auto-generated title isn't quite right. Defaults to None.
|
||||||
:param Optional[str] category: Adds a category to the node. Used to group the nodes in the UI. Defaults to None.
|
:param Optional[list[str]] tags: Adds tags to the invocation. Invocations may be searched for by their tags. Defaults to None.
|
||||||
|
:param Optional[str] category: Adds a category to the invocation. Used to group the invocations in the UI. Defaults to None.
|
||||||
"""
|
"""
|
||||||
|
|
||||||
def wrapper(cls: Type[T]) -> Type[T]:
|
def wrapper(cls: Type[GenericBaseInvocation]) -> Type[GenericBaseInvocation]:
|
||||||
|
# Validate invocation types on creation of invocation classes
|
||||||
|
# TODO: ensure unique?
|
||||||
|
if re.compile(r"^\S+$").match(invocation_type) is None:
|
||||||
|
raise ValueError(f'"invocation_type" must consist of non-whitespace characters, got "{invocation_type}"')
|
||||||
|
|
||||||
|
# Add OpenAPI schema extras
|
||||||
uiconf_name = cls.__qualname__ + ".UIConfig"
|
uiconf_name = cls.__qualname__ + ".UIConfig"
|
||||||
if not hasattr(cls, "UIConfig") or cls.UIConfig.__qualname__ != uiconf_name:
|
if not hasattr(cls, "UIConfig") or cls.UIConfig.__qualname__ != uiconf_name:
|
||||||
cls.UIConfig = type(uiconf_name, (UIConfigBase,), dict())
|
cls.UIConfig = type(uiconf_name, (UIConfigBase,), dict())
|
||||||
cls.UIConfig.title = title
|
if title is not None:
|
||||||
cls.UIConfig.tags = tags
|
cls.UIConfig.title = title
|
||||||
cls.UIConfig.category = category
|
if tags is not None:
|
||||||
|
cls.UIConfig.tags = tags
|
||||||
|
if category is not None:
|
||||||
|
cls.UIConfig.category = category
|
||||||
|
|
||||||
|
# Add the invocation type to the pydantic model of the invocation
|
||||||
|
invocation_type_annotation = Literal[invocation_type] # type: ignore
|
||||||
|
invocation_type_field = ModelField.infer(
|
||||||
|
name="type",
|
||||||
|
value=invocation_type,
|
||||||
|
annotation=invocation_type_annotation,
|
||||||
|
class_validators=None,
|
||||||
|
config=cls.__config__,
|
||||||
|
)
|
||||||
|
cls.__fields__.update({"type": invocation_type_field})
|
||||||
|
cls.__annotations__.update({"type": invocation_type_annotation})
|
||||||
|
|
||||||
|
return cls
|
||||||
|
|
||||||
|
return wrapper
|
||||||
|
|
||||||
|
|
||||||
|
GenericBaseInvocationOutput = TypeVar("GenericBaseInvocationOutput", bound=BaseInvocationOutput)
|
||||||
|
|
||||||
|
|
||||||
|
def invocation_output(
|
||||||
|
output_type: str,
|
||||||
|
) -> Callable[[Type[GenericBaseInvocationOutput]], Type[GenericBaseInvocationOutput]]:
|
||||||
|
"""
|
||||||
|
Adds metadata to an invocation output.
|
||||||
|
|
||||||
|
:param str output_type: The type of the invocation output. Must be unique among all invocation outputs.
|
||||||
|
"""
|
||||||
|
|
||||||
|
def wrapper(cls: Type[GenericBaseInvocationOutput]) -> Type[GenericBaseInvocationOutput]:
|
||||||
|
# Validate output types on creation of invocation output classes
|
||||||
|
# TODO: ensure unique?
|
||||||
|
if re.compile(r"^\S+$").match(output_type) is None:
|
||||||
|
raise ValueError(f'"output_type" must consist of non-whitespace characters, got "{output_type}"')
|
||||||
|
|
||||||
|
# Add the output type to the pydantic model of the invocation output
|
||||||
|
output_type_annotation = Literal[output_type] # type: ignore
|
||||||
|
output_type_field = ModelField.infer(
|
||||||
|
name="type",
|
||||||
|
value=output_type,
|
||||||
|
annotation=output_type_annotation,
|
||||||
|
class_validators=None,
|
||||||
|
config=cls.__config__,
|
||||||
|
)
|
||||||
|
cls.__fields__.update({"type": output_type_field})
|
||||||
|
cls.__annotations__.update({"type": output_type_annotation})
|
||||||
|
|
||||||
return cls
|
return cls
|
||||||
|
|
||||||
return wrapper
|
return wrapper
|
||||||
|
@ -1,6 +1,5 @@
|
|||||||
# Copyright (c) 2023 Kyle Schouviller (https://github.com/kyle0654) and the InvokeAI Team
|
# Copyright (c) 2023 Kyle Schouviller (https://github.com/kyle0654) and the InvokeAI Team
|
||||||
|
|
||||||
from typing import Literal
|
|
||||||
|
|
||||||
import numpy as np
|
import numpy as np
|
||||||
from pydantic import validator
|
from pydantic import validator
|
||||||
@ -8,16 +7,13 @@ from pydantic import validator
|
|||||||
from invokeai.app.invocations.primitives import IntegerCollectionOutput
|
from invokeai.app.invocations.primitives import IntegerCollectionOutput
|
||||||
from invokeai.app.util.misc import SEED_MAX, get_random_seed
|
from invokeai.app.util.misc import SEED_MAX, get_random_seed
|
||||||
|
|
||||||
from .baseinvocation import BaseInvocation, InputField, InvocationContext, node
|
from .baseinvocation import BaseInvocation, InputField, InvocationContext, invocation
|
||||||
|
|
||||||
|
|
||||||
@node(title="Integer Range", tags=["collection", "integer", "range"], category="collections")
|
@invocation("range", title="Integer Range", tags=["collection", "integer", "range"], category="collections")
|
||||||
class RangeInvocation(BaseInvocation):
|
class RangeInvocation(BaseInvocation):
|
||||||
"""Creates a range of numbers from start to stop with step"""
|
"""Creates a range of numbers from start to stop with step"""
|
||||||
|
|
||||||
type: Literal["range"] = "range"
|
|
||||||
|
|
||||||
# Inputs
|
|
||||||
start: int = InputField(default=0, description="The start of the range")
|
start: int = InputField(default=0, description="The start of the range")
|
||||||
stop: int = InputField(default=10, description="The stop of the range")
|
stop: int = InputField(default=10, description="The stop of the range")
|
||||||
step: int = InputField(default=1, description="The step of the range")
|
step: int = InputField(default=1, description="The step of the range")
|
||||||
@ -32,13 +28,15 @@ class RangeInvocation(BaseInvocation):
|
|||||||
return IntegerCollectionOutput(collection=list(range(self.start, self.stop, self.step)))
|
return IntegerCollectionOutput(collection=list(range(self.start, self.stop, self.step)))
|
||||||
|
|
||||||
|
|
||||||
@node(title="Integer Range of Size", tags=["collection", "integer", "size", "range"], category="collections")
|
@invocation(
|
||||||
|
"range_of_size",
|
||||||
|
title="Integer Range of Size",
|
||||||
|
tags=["collection", "integer", "size", "range"],
|
||||||
|
category="collections",
|
||||||
|
)
|
||||||
class RangeOfSizeInvocation(BaseInvocation):
|
class RangeOfSizeInvocation(BaseInvocation):
|
||||||
"""Creates a range from start to start + size with step"""
|
"""Creates a range from start to start + size with step"""
|
||||||
|
|
||||||
type: Literal["range_of_size"] = "range_of_size"
|
|
||||||
|
|
||||||
# Inputs
|
|
||||||
start: int = InputField(default=0, description="The start of the range")
|
start: int = InputField(default=0, description="The start of the range")
|
||||||
size: int = InputField(default=1, description="The number of values")
|
size: int = InputField(default=1, description="The number of values")
|
||||||
step: int = InputField(default=1, description="The step of the range")
|
step: int = InputField(default=1, description="The step of the range")
|
||||||
@ -47,13 +45,15 @@ class RangeOfSizeInvocation(BaseInvocation):
|
|||||||
return IntegerCollectionOutput(collection=list(range(self.start, self.start + self.size, self.step)))
|
return IntegerCollectionOutput(collection=list(range(self.start, self.start + self.size, self.step)))
|
||||||
|
|
||||||
|
|
||||||
@node(title="Random Range", tags=["range", "integer", "random", "collection"], category="collections")
|
@invocation(
|
||||||
|
"random_range",
|
||||||
|
title="Random Range",
|
||||||
|
tags=["range", "integer", "random", "collection"],
|
||||||
|
category="collections",
|
||||||
|
)
|
||||||
class RandomRangeInvocation(BaseInvocation):
|
class RandomRangeInvocation(BaseInvocation):
|
||||||
"""Creates a collection of random numbers"""
|
"""Creates a collection of random numbers"""
|
||||||
|
|
||||||
type: Literal["random_range"] = "random_range"
|
|
||||||
|
|
||||||
# Inputs
|
|
||||||
low: int = InputField(default=0, description="The inclusive low value")
|
low: int = InputField(default=0, description="The inclusive low value")
|
||||||
high: int = InputField(default=np.iinfo(np.int32).max, description="The exclusive high value")
|
high: int = InputField(default=np.iinfo(np.int32).max, description="The exclusive high value")
|
||||||
size: int = InputField(default=1, description="The number of values to generate")
|
size: int = InputField(default=1, description="The number of values to generate")
|
||||||
|
@ -1,6 +1,6 @@
|
|||||||
import re
|
import re
|
||||||
from dataclasses import dataclass
|
from dataclasses import dataclass
|
||||||
from typing import List, Literal, Union
|
from typing import List, Union
|
||||||
|
|
||||||
import torch
|
import torch
|
||||||
from compel import Compel, ReturnedEmbeddingsType
|
from compel import Compel, ReturnedEmbeddingsType
|
||||||
@ -26,9 +26,8 @@ from .baseinvocation import (
|
|||||||
InvocationContext,
|
InvocationContext,
|
||||||
OutputField,
|
OutputField,
|
||||||
UIComponent,
|
UIComponent,
|
||||||
category,
|
invocation,
|
||||||
tags,
|
invocation_output,
|
||||||
title,
|
|
||||||
)
|
)
|
||||||
from .model import ClipField
|
from .model import ClipField
|
||||||
|
|
||||||
@ -45,14 +44,10 @@ class ConditioningFieldData:
|
|||||||
# PerpNeg = "perp_neg"
|
# PerpNeg = "perp_neg"
|
||||||
|
|
||||||
|
|
||||||
@title("Prompt")
|
@invocation("compel", title="Prompt", tags=["prompt", "compel"], category="conditioning")
|
||||||
@tags("prompt", "compel")
|
|
||||||
@category("conditioning")
|
|
||||||
class CompelInvocation(BaseInvocation):
|
class CompelInvocation(BaseInvocation):
|
||||||
"""Parse prompt using compel package to conditioning."""
|
"""Parse prompt using compel package to conditioning."""
|
||||||
|
|
||||||
type: Literal["compel"] = "compel"
|
|
||||||
|
|
||||||
prompt: str = InputField(
|
prompt: str = InputField(
|
||||||
default="",
|
default="",
|
||||||
description=FieldDescriptions.compel_prompt,
|
description=FieldDescriptions.compel_prompt,
|
||||||
@ -267,14 +262,15 @@ class SDXLPromptInvocationBase:
|
|||||||
return c, c_pooled, ec
|
return c, c_pooled, ec
|
||||||
|
|
||||||
|
|
||||||
@title("SDXL Prompt")
|
@invocation(
|
||||||
@tags("sdxl", "compel", "prompt")
|
"sdxl_compel_prompt",
|
||||||
@category("conditioning")
|
title="SDXL Prompt",
|
||||||
|
tags=["sdxl", "compel", "prompt"],
|
||||||
|
category="conditioning",
|
||||||
|
)
|
||||||
class SDXLCompelPromptInvocation(BaseInvocation, SDXLPromptInvocationBase):
|
class SDXLCompelPromptInvocation(BaseInvocation, SDXLPromptInvocationBase):
|
||||||
"""Parse prompt using compel package to conditioning."""
|
"""Parse prompt using compel package to conditioning."""
|
||||||
|
|
||||||
type: Literal["sdxl_compel_prompt"] = "sdxl_compel_prompt"
|
|
||||||
|
|
||||||
prompt: str = InputField(default="", description=FieldDescriptions.compel_prompt, ui_component=UIComponent.Textarea)
|
prompt: str = InputField(default="", description=FieldDescriptions.compel_prompt, ui_component=UIComponent.Textarea)
|
||||||
style: str = InputField(default="", description=FieldDescriptions.compel_prompt, ui_component=UIComponent.Textarea)
|
style: str = InputField(default="", description=FieldDescriptions.compel_prompt, ui_component=UIComponent.Textarea)
|
||||||
original_width: int = InputField(default=1024, description="")
|
original_width: int = InputField(default=1024, description="")
|
||||||
@ -327,14 +323,15 @@ class SDXLCompelPromptInvocation(BaseInvocation, SDXLPromptInvocationBase):
|
|||||||
)
|
)
|
||||||
|
|
||||||
|
|
||||||
@title("SDXL Refiner Prompt")
|
@invocation(
|
||||||
@tags("sdxl", "compel", "prompt")
|
"sdxl_refiner_compel_prompt",
|
||||||
@category("conditioning")
|
title="SDXL Refiner Prompt",
|
||||||
|
tags=["sdxl", "compel", "prompt"],
|
||||||
|
category="conditioning",
|
||||||
|
)
|
||||||
class SDXLRefinerCompelPromptInvocation(BaseInvocation, SDXLPromptInvocationBase):
|
class SDXLRefinerCompelPromptInvocation(BaseInvocation, SDXLPromptInvocationBase):
|
||||||
"""Parse prompt using compel package to conditioning."""
|
"""Parse prompt using compel package to conditioning."""
|
||||||
|
|
||||||
type: Literal["sdxl_refiner_compel_prompt"] = "sdxl_refiner_compel_prompt"
|
|
||||||
|
|
||||||
style: str = InputField(
|
style: str = InputField(
|
||||||
default="", description=FieldDescriptions.compel_prompt, ui_component=UIComponent.Textarea
|
default="", description=FieldDescriptions.compel_prompt, ui_component=UIComponent.Textarea
|
||||||
) # TODO: ?
|
) # TODO: ?
|
||||||
@ -376,21 +373,17 @@ class SDXLRefinerCompelPromptInvocation(BaseInvocation, SDXLPromptInvocationBase
|
|||||||
)
|
)
|
||||||
|
|
||||||
|
|
||||||
|
@invocation_output("clip_skip_output")
|
||||||
class ClipSkipInvocationOutput(BaseInvocationOutput):
|
class ClipSkipInvocationOutput(BaseInvocationOutput):
|
||||||
"""Clip skip node output"""
|
"""Clip skip node output"""
|
||||||
|
|
||||||
type: Literal["clip_skip_output"] = "clip_skip_output"
|
|
||||||
clip: ClipField = OutputField(default=None, description=FieldDescriptions.clip, title="CLIP")
|
clip: ClipField = OutputField(default=None, description=FieldDescriptions.clip, title="CLIP")
|
||||||
|
|
||||||
|
|
||||||
@title("CLIP Skip")
|
@invocation("clip_skip", title="CLIP Skip", tags=["clipskip", "clip", "skip"], category="conditioning")
|
||||||
@tags("clipskip", "clip", "skip")
|
|
||||||
@category("conditioning")
|
|
||||||
class ClipSkipInvocation(BaseInvocation):
|
class ClipSkipInvocation(BaseInvocation):
|
||||||
"""Skip layers in clip text_encoder model."""
|
"""Skip layers in clip text_encoder model."""
|
||||||
|
|
||||||
type: Literal["clip_skip"] = "clip_skip"
|
|
||||||
|
|
||||||
clip: ClipField = InputField(description=FieldDescriptions.clip, input=Input.Connection, title="CLIP")
|
clip: ClipField = InputField(description=FieldDescriptions.clip, input=Input.Connection, title="CLIP")
|
||||||
skipped_layers: int = InputField(default=0, description=FieldDescriptions.skipped_layers)
|
skipped_layers: int = InputField(default=0, description=FieldDescriptions.skipped_layers)
|
||||||
|
|
||||||
|
@ -40,10 +40,8 @@ from .baseinvocation import (
|
|||||||
InvocationContext,
|
InvocationContext,
|
||||||
OutputField,
|
OutputField,
|
||||||
UIType,
|
UIType,
|
||||||
category,
|
invocation,
|
||||||
node,
|
invocation_output,
|
||||||
tags,
|
|
||||||
title,
|
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|
||||||
@ -89,22 +87,18 @@ class ControlField(BaseModel):
|
|||||||
return v
|
return v
|
||||||
|
|
||||||
|
|
||||||
|
@invocation_output("control_output")
|
||||||
class ControlOutput(BaseInvocationOutput):
|
class ControlOutput(BaseInvocationOutput):
|
||||||
"""node output for ControlNet info"""
|
"""node output for ControlNet info"""
|
||||||
|
|
||||||
type: Literal["control_output"] = "control_output"
|
|
||||||
|
|
||||||
# Outputs
|
# Outputs
|
||||||
control: ControlField = OutputField(description=FieldDescriptions.control)
|
control: ControlField = OutputField(description=FieldDescriptions.control)
|
||||||
|
|
||||||
|
|
||||||
@node(title="ControlNet", tags=["controlnet"], category="controlnet")
|
@invocation("controlnet", title="ControlNet", tags=["controlnet"], category="controlnet")
|
||||||
class ControlNetInvocation(BaseInvocation):
|
class ControlNetInvocation(BaseInvocation):
|
||||||
"""Collects ControlNet info to pass to other nodes"""
|
"""Collects ControlNet info to pass to other nodes"""
|
||||||
|
|
||||||
type: Literal["controlnet"] = "controlnet"
|
|
||||||
|
|
||||||
# Inputs
|
|
||||||
image: ImageField = InputField(description="The control image")
|
image: ImageField = InputField(description="The control image")
|
||||||
control_model: ControlNetModelField = InputField(
|
control_model: ControlNetModelField = InputField(
|
||||||
default="lllyasviel/sd-controlnet-canny", description=FieldDescriptions.controlnet_model, input=Input.Direct
|
default="lllyasviel/sd-controlnet-canny", description=FieldDescriptions.controlnet_model, input=Input.Direct
|
||||||
@ -135,12 +129,10 @@ class ControlNetInvocation(BaseInvocation):
|
|||||||
)
|
)
|
||||||
|
|
||||||
|
|
||||||
|
@invocation("image_processor", title="Base Image Processor", tags=["controlnet"], category="controlnet")
|
||||||
class ImageProcessorInvocation(BaseInvocation):
|
class ImageProcessorInvocation(BaseInvocation):
|
||||||
"""Base class for invocations that preprocess images for ControlNet"""
|
"""Base class for invocations that preprocess images for ControlNet"""
|
||||||
|
|
||||||
type: Literal["image_processor"] = "image_processor"
|
|
||||||
|
|
||||||
# Inputs
|
|
||||||
image: ImageField = InputField(description="The image to process")
|
image: ImageField = InputField(description="The image to process")
|
||||||
|
|
||||||
def run_processor(self, image):
|
def run_processor(self, image):
|
||||||
@ -176,15 +168,15 @@ class ImageProcessorInvocation(BaseInvocation):
|
|||||||
)
|
)
|
||||||
|
|
||||||
|
|
||||||
@title("Canny Processor")
|
@invocation(
|
||||||
@tags("controlnet", "canny")
|
"canny_image_processor",
|
||||||
@category("controlnet")
|
title="Canny Processor",
|
||||||
|
tags=["controlnet", "canny"],
|
||||||
|
category="controlnet",
|
||||||
|
)
|
||||||
class CannyImageProcessorInvocation(ImageProcessorInvocation):
|
class CannyImageProcessorInvocation(ImageProcessorInvocation):
|
||||||
"""Canny edge detection for ControlNet"""
|
"""Canny edge detection for ControlNet"""
|
||||||
|
|
||||||
type: Literal["canny_image_processor"] = "canny_image_processor"
|
|
||||||
|
|
||||||
# Input
|
|
||||||
low_threshold: int = InputField(
|
low_threshold: int = InputField(
|
||||||
default=100, ge=0, le=255, description="The low threshold of the Canny pixel gradient (0-255)"
|
default=100, ge=0, le=255, description="The low threshold of the Canny pixel gradient (0-255)"
|
||||||
)
|
)
|
||||||
@ -198,15 +190,15 @@ class CannyImageProcessorInvocation(ImageProcessorInvocation):
|
|||||||
return processed_image
|
return processed_image
|
||||||
|
|
||||||
|
|
||||||
@title("HED (softedge) Processor")
|
@invocation(
|
||||||
@tags("controlnet", "hed", "softedge")
|
"hed_image_processor",
|
||||||
@category("controlnet")
|
title="HED (softedge) Processor",
|
||||||
|
tags=["controlnet", "hed", "softedge"],
|
||||||
|
category="controlnet",
|
||||||
|
)
|
||||||
class HedImageProcessorInvocation(ImageProcessorInvocation):
|
class HedImageProcessorInvocation(ImageProcessorInvocation):
|
||||||
"""Applies HED edge detection to image"""
|
"""Applies HED edge detection to image"""
|
||||||
|
|
||||||
type: Literal["hed_image_processor"] = "hed_image_processor"
|
|
||||||
|
|
||||||
# Inputs
|
|
||||||
detect_resolution: int = InputField(default=512, ge=0, description=FieldDescriptions.detect_res)
|
detect_resolution: int = InputField(default=512, ge=0, description=FieldDescriptions.detect_res)
|
||||||
image_resolution: int = InputField(default=512, ge=0, description=FieldDescriptions.image_res)
|
image_resolution: int = InputField(default=512, ge=0, description=FieldDescriptions.image_res)
|
||||||
# safe not supported in controlnet_aux v0.0.3
|
# safe not supported in controlnet_aux v0.0.3
|
||||||
@ -226,15 +218,15 @@ class HedImageProcessorInvocation(ImageProcessorInvocation):
|
|||||||
return processed_image
|
return processed_image
|
||||||
|
|
||||||
|
|
||||||
@title("Lineart Processor")
|
@invocation(
|
||||||
@tags("controlnet", "lineart")
|
"lineart_image_processor",
|
||||||
@category("controlnet")
|
title="Lineart Processor",
|
||||||
|
tags=["controlnet", "lineart"],
|
||||||
|
category="controlnet",
|
||||||
|
)
|
||||||
class LineartImageProcessorInvocation(ImageProcessorInvocation):
|
class LineartImageProcessorInvocation(ImageProcessorInvocation):
|
||||||
"""Applies line art processing to image"""
|
"""Applies line art processing to image"""
|
||||||
|
|
||||||
type: Literal["lineart_image_processor"] = "lineart_image_processor"
|
|
||||||
|
|
||||||
# Inputs
|
|
||||||
detect_resolution: int = InputField(default=512, ge=0, description=FieldDescriptions.detect_res)
|
detect_resolution: int = InputField(default=512, ge=0, description=FieldDescriptions.detect_res)
|
||||||
image_resolution: int = InputField(default=512, ge=0, description=FieldDescriptions.image_res)
|
image_resolution: int = InputField(default=512, ge=0, description=FieldDescriptions.image_res)
|
||||||
coarse: bool = InputField(default=False, description="Whether to use coarse mode")
|
coarse: bool = InputField(default=False, description="Whether to use coarse mode")
|
||||||
@ -247,15 +239,15 @@ class LineartImageProcessorInvocation(ImageProcessorInvocation):
|
|||||||
return processed_image
|
return processed_image
|
||||||
|
|
||||||
|
|
||||||
@title("Lineart Anime Processor")
|
@invocation(
|
||||||
@tags("controlnet", "lineart", "anime")
|
"lineart_anime_image_processor",
|
||||||
@category("controlnet")
|
title="Lineart Anime Processor",
|
||||||
|
tags=["controlnet", "lineart", "anime"],
|
||||||
|
category="controlnet",
|
||||||
|
)
|
||||||
class LineartAnimeImageProcessorInvocation(ImageProcessorInvocation):
|
class LineartAnimeImageProcessorInvocation(ImageProcessorInvocation):
|
||||||
"""Applies line art anime processing to image"""
|
"""Applies line art anime processing to image"""
|
||||||
|
|
||||||
type: Literal["lineart_anime_image_processor"] = "lineart_anime_image_processor"
|
|
||||||
|
|
||||||
# Inputs
|
|
||||||
detect_resolution: int = InputField(default=512, ge=0, description=FieldDescriptions.detect_res)
|
detect_resolution: int = InputField(default=512, ge=0, description=FieldDescriptions.detect_res)
|
||||||
image_resolution: int = InputField(default=512, ge=0, description=FieldDescriptions.image_res)
|
image_resolution: int = InputField(default=512, ge=0, description=FieldDescriptions.image_res)
|
||||||
|
|
||||||
@ -269,15 +261,15 @@ class LineartAnimeImageProcessorInvocation(ImageProcessorInvocation):
|
|||||||
return processed_image
|
return processed_image
|
||||||
|
|
||||||
|
|
||||||
@title("Openpose Processor")
|
@invocation(
|
||||||
@tags("controlnet", "openpose", "pose")
|
"openpose_image_processor",
|
||||||
@category("controlnet")
|
title="Openpose Processor",
|
||||||
|
tags=["controlnet", "openpose", "pose"],
|
||||||
|
category="controlnet",
|
||||||
|
)
|
||||||
class OpenposeImageProcessorInvocation(ImageProcessorInvocation):
|
class OpenposeImageProcessorInvocation(ImageProcessorInvocation):
|
||||||
"""Applies Openpose processing to image"""
|
"""Applies Openpose processing to image"""
|
||||||
|
|
||||||
type: Literal["openpose_image_processor"] = "openpose_image_processor"
|
|
||||||
|
|
||||||
# Inputs
|
|
||||||
hand_and_face: bool = InputField(default=False, description="Whether to use hands and face mode")
|
hand_and_face: bool = InputField(default=False, description="Whether to use hands and face mode")
|
||||||
detect_resolution: int = InputField(default=512, ge=0, description=FieldDescriptions.detect_res)
|
detect_resolution: int = InputField(default=512, ge=0, description=FieldDescriptions.detect_res)
|
||||||
image_resolution: int = InputField(default=512, ge=0, description=FieldDescriptions.image_res)
|
image_resolution: int = InputField(default=512, ge=0, description=FieldDescriptions.image_res)
|
||||||
@ -293,15 +285,15 @@ class OpenposeImageProcessorInvocation(ImageProcessorInvocation):
|
|||||||
return processed_image
|
return processed_image
|
||||||
|
|
||||||
|
|
||||||
@title("Midas (Depth) Processor")
|
@invocation(
|
||||||
@tags("controlnet", "midas", "depth")
|
"midas_depth_image_processor",
|
||||||
@category("controlnet")
|
title="Midas Depth Processor",
|
||||||
|
tags=["controlnet", "midas"],
|
||||||
|
category="controlnet",
|
||||||
|
)
|
||||||
class MidasDepthImageProcessorInvocation(ImageProcessorInvocation):
|
class MidasDepthImageProcessorInvocation(ImageProcessorInvocation):
|
||||||
"""Applies Midas depth processing to image"""
|
"""Applies Midas depth processing to image"""
|
||||||
|
|
||||||
type: Literal["midas_depth_image_processor"] = "midas_depth_image_processor"
|
|
||||||
|
|
||||||
# Inputs
|
|
||||||
a_mult: float = InputField(default=2.0, ge=0, description="Midas parameter `a_mult` (a = a_mult * PI)")
|
a_mult: float = InputField(default=2.0, ge=0, description="Midas parameter `a_mult` (a = a_mult * PI)")
|
||||||
bg_th: float = InputField(default=0.1, ge=0, description="Midas parameter `bg_th`")
|
bg_th: float = InputField(default=0.1, ge=0, description="Midas parameter `bg_th`")
|
||||||
# depth_and_normal not supported in controlnet_aux v0.0.3
|
# depth_and_normal not supported in controlnet_aux v0.0.3
|
||||||
@ -319,15 +311,15 @@ class MidasDepthImageProcessorInvocation(ImageProcessorInvocation):
|
|||||||
return processed_image
|
return processed_image
|
||||||
|
|
||||||
|
|
||||||
@title("Normal BAE Processor")
|
@invocation(
|
||||||
@tags("controlnet", "normal", "bae")
|
"normalbae_image_processor",
|
||||||
@category("controlnet")
|
title="Normal BAE Processor",
|
||||||
|
tags=["controlnet"],
|
||||||
|
category="controlnet",
|
||||||
|
)
|
||||||
class NormalbaeImageProcessorInvocation(ImageProcessorInvocation):
|
class NormalbaeImageProcessorInvocation(ImageProcessorInvocation):
|
||||||
"""Applies NormalBae processing to image"""
|
"""Applies NormalBae processing to image"""
|
||||||
|
|
||||||
type: Literal["normalbae_image_processor"] = "normalbae_image_processor"
|
|
||||||
|
|
||||||
# Inputs
|
|
||||||
detect_resolution: int = InputField(default=512, ge=0, description=FieldDescriptions.detect_res)
|
detect_resolution: int = InputField(default=512, ge=0, description=FieldDescriptions.detect_res)
|
||||||
image_resolution: int = InputField(default=512, ge=0, description=FieldDescriptions.image_res)
|
image_resolution: int = InputField(default=512, ge=0, description=FieldDescriptions.image_res)
|
||||||
|
|
||||||
@ -339,15 +331,10 @@ class NormalbaeImageProcessorInvocation(ImageProcessorInvocation):
|
|||||||
return processed_image
|
return processed_image
|
||||||
|
|
||||||
|
|
||||||
@title("MLSD Processor")
|
@invocation("mlsd_image_processor", title="MLSD Processor", tags=["controlnet", "mlsd"], category="controlnet")
|
||||||
@tags("controlnet", "mlsd")
|
|
||||||
@category("controlnet")
|
|
||||||
class MlsdImageProcessorInvocation(ImageProcessorInvocation):
|
class MlsdImageProcessorInvocation(ImageProcessorInvocation):
|
||||||
"""Applies MLSD processing to image"""
|
"""Applies MLSD processing to image"""
|
||||||
|
|
||||||
type: Literal["mlsd_image_processor"] = "mlsd_image_processor"
|
|
||||||
|
|
||||||
# Inputs
|
|
||||||
detect_resolution: int = InputField(default=512, ge=0, description=FieldDescriptions.detect_res)
|
detect_resolution: int = InputField(default=512, ge=0, description=FieldDescriptions.detect_res)
|
||||||
image_resolution: int = InputField(default=512, ge=0, description=FieldDescriptions.image_res)
|
image_resolution: int = InputField(default=512, ge=0, description=FieldDescriptions.image_res)
|
||||||
thr_v: float = InputField(default=0.1, ge=0, description="MLSD parameter `thr_v`")
|
thr_v: float = InputField(default=0.1, ge=0, description="MLSD parameter `thr_v`")
|
||||||
@ -365,15 +352,10 @@ class MlsdImageProcessorInvocation(ImageProcessorInvocation):
|
|||||||
return processed_image
|
return processed_image
|
||||||
|
|
||||||
|
|
||||||
@title("PIDI Processor")
|
@invocation("pidi_image_processor", title="PIDI Processor", tags=["controlnet", "pidi"], category="controlnet")
|
||||||
@tags("controlnet", "pidi")
|
|
||||||
@category("controlnet")
|
|
||||||
class PidiImageProcessorInvocation(ImageProcessorInvocation):
|
class PidiImageProcessorInvocation(ImageProcessorInvocation):
|
||||||
"""Applies PIDI processing to image"""
|
"""Applies PIDI processing to image"""
|
||||||
|
|
||||||
type: Literal["pidi_image_processor"] = "pidi_image_processor"
|
|
||||||
|
|
||||||
# Inputs
|
|
||||||
detect_resolution: int = InputField(default=512, ge=0, description=FieldDescriptions.detect_res)
|
detect_resolution: int = InputField(default=512, ge=0, description=FieldDescriptions.detect_res)
|
||||||
image_resolution: int = InputField(default=512, ge=0, description=FieldDescriptions.image_res)
|
image_resolution: int = InputField(default=512, ge=0, description=FieldDescriptions.image_res)
|
||||||
safe: bool = InputField(default=False, description=FieldDescriptions.safe_mode)
|
safe: bool = InputField(default=False, description=FieldDescriptions.safe_mode)
|
||||||
@ -391,15 +373,15 @@ class PidiImageProcessorInvocation(ImageProcessorInvocation):
|
|||||||
return processed_image
|
return processed_image
|
||||||
|
|
||||||
|
|
||||||
@title("Content Shuffle Processor")
|
@invocation(
|
||||||
@tags("controlnet", "contentshuffle")
|
"content_shuffle_image_processor",
|
||||||
@category("controlnet")
|
title="Content Shuffle Processor",
|
||||||
|
tags=["controlnet", "contentshuffle"],
|
||||||
|
category="controlnet",
|
||||||
|
)
|
||||||
class ContentShuffleImageProcessorInvocation(ImageProcessorInvocation):
|
class ContentShuffleImageProcessorInvocation(ImageProcessorInvocation):
|
||||||
"""Applies content shuffle processing to image"""
|
"""Applies content shuffle processing to image"""
|
||||||
|
|
||||||
type: Literal["content_shuffle_image_processor"] = "content_shuffle_image_processor"
|
|
||||||
|
|
||||||
# Inputs
|
|
||||||
detect_resolution: int = InputField(default=512, ge=0, description=FieldDescriptions.detect_res)
|
detect_resolution: int = InputField(default=512, ge=0, description=FieldDescriptions.detect_res)
|
||||||
image_resolution: int = InputField(default=512, ge=0, description=FieldDescriptions.image_res)
|
image_resolution: int = InputField(default=512, ge=0, description=FieldDescriptions.image_res)
|
||||||
h: Optional[int] = InputField(default=512, ge=0, description="Content shuffle `h` parameter")
|
h: Optional[int] = InputField(default=512, ge=0, description="Content shuffle `h` parameter")
|
||||||
@ -420,29 +402,30 @@ class ContentShuffleImageProcessorInvocation(ImageProcessorInvocation):
|
|||||||
|
|
||||||
|
|
||||||
# should work with controlnet_aux >= 0.0.4 and timm <= 0.6.13
|
# should work with controlnet_aux >= 0.0.4 and timm <= 0.6.13
|
||||||
@title("Zoe (Depth) Processor")
|
@invocation(
|
||||||
@tags("controlnet", "zoe", "depth")
|
"zoe_depth_image_processor",
|
||||||
@category("controlnet")
|
title="Zoe (Depth) Processor",
|
||||||
|
tags=["controlnet", "zoe", "depth"],
|
||||||
|
category="controlnet",
|
||||||
|
)
|
||||||
class ZoeDepthImageProcessorInvocation(ImageProcessorInvocation):
|
class ZoeDepthImageProcessorInvocation(ImageProcessorInvocation):
|
||||||
"""Applies Zoe depth processing to image"""
|
"""Applies Zoe depth processing to image"""
|
||||||
|
|
||||||
type: Literal["zoe_depth_image_processor"] = "zoe_depth_image_processor"
|
|
||||||
|
|
||||||
def run_processor(self, image):
|
def run_processor(self, image):
|
||||||
zoe_depth_processor = ZoeDetector.from_pretrained("lllyasviel/Annotators")
|
zoe_depth_processor = ZoeDetector.from_pretrained("lllyasviel/Annotators")
|
||||||
processed_image = zoe_depth_processor(image)
|
processed_image = zoe_depth_processor(image)
|
||||||
return processed_image
|
return processed_image
|
||||||
|
|
||||||
|
|
||||||
@title("Mediapipe Face Processor")
|
@invocation(
|
||||||
@tags("controlnet", "mediapipe", "face")
|
"mediapipe_face_processor",
|
||||||
@category("controlnet")
|
title="Mediapipe Face Processor",
|
||||||
|
tags=["controlnet", "mediapipe", "face"],
|
||||||
|
category="controlnet",
|
||||||
|
)
|
||||||
class MediapipeFaceProcessorInvocation(ImageProcessorInvocation):
|
class MediapipeFaceProcessorInvocation(ImageProcessorInvocation):
|
||||||
"""Applies mediapipe face processing to image"""
|
"""Applies mediapipe face processing to image"""
|
||||||
|
|
||||||
type: Literal["mediapipe_face_processor"] = "mediapipe_face_processor"
|
|
||||||
|
|
||||||
# Inputs
|
|
||||||
max_faces: int = InputField(default=1, ge=1, description="Maximum number of faces to detect")
|
max_faces: int = InputField(default=1, ge=1, description="Maximum number of faces to detect")
|
||||||
min_confidence: float = InputField(default=0.5, ge=0, le=1, description="Minimum confidence for face detection")
|
min_confidence: float = InputField(default=0.5, ge=0, le=1, description="Minimum confidence for face detection")
|
||||||
|
|
||||||
@ -456,15 +439,15 @@ class MediapipeFaceProcessorInvocation(ImageProcessorInvocation):
|
|||||||
return processed_image
|
return processed_image
|
||||||
|
|
||||||
|
|
||||||
@title("Leres (Depth) Processor")
|
@invocation(
|
||||||
@tags("controlnet", "leres", "depth")
|
"leres_image_processor",
|
||||||
@category("controlnet")
|
title="Leres (Depth) Processor",
|
||||||
|
tags=["controlnet", "leres", "depth"],
|
||||||
|
category="controlnet",
|
||||||
|
)
|
||||||
class LeresImageProcessorInvocation(ImageProcessorInvocation):
|
class LeresImageProcessorInvocation(ImageProcessorInvocation):
|
||||||
"""Applies leres processing to image"""
|
"""Applies leres processing to image"""
|
||||||
|
|
||||||
type: Literal["leres_image_processor"] = "leres_image_processor"
|
|
||||||
|
|
||||||
# Inputs
|
|
||||||
thr_a: float = InputField(default=0, description="Leres parameter `thr_a`")
|
thr_a: float = InputField(default=0, description="Leres parameter `thr_a`")
|
||||||
thr_b: float = InputField(default=0, description="Leres parameter `thr_b`")
|
thr_b: float = InputField(default=0, description="Leres parameter `thr_b`")
|
||||||
boost: bool = InputField(default=False, description="Whether to use boost mode")
|
boost: bool = InputField(default=False, description="Whether to use boost mode")
|
||||||
@ -484,15 +467,15 @@ class LeresImageProcessorInvocation(ImageProcessorInvocation):
|
|||||||
return processed_image
|
return processed_image
|
||||||
|
|
||||||
|
|
||||||
@title("Tile Resample Processor")
|
@invocation(
|
||||||
@tags("controlnet", "tile")
|
"tile_image_processor",
|
||||||
@category("controlnet")
|
title="Tile Resample Processor",
|
||||||
|
tags=["controlnet", "tile"],
|
||||||
|
category="controlnet",
|
||||||
|
)
|
||||||
class TileResamplerProcessorInvocation(ImageProcessorInvocation):
|
class TileResamplerProcessorInvocation(ImageProcessorInvocation):
|
||||||
"""Tile resampler processor"""
|
"""Tile resampler processor"""
|
||||||
|
|
||||||
type: Literal["tile_image_processor"] = "tile_image_processor"
|
|
||||||
|
|
||||||
# Inputs
|
|
||||||
# res: int = InputField(default=512, ge=0, le=1024, description="The pixel resolution for each tile")
|
# res: int = InputField(default=512, ge=0, le=1024, description="The pixel resolution for each tile")
|
||||||
down_sampling_rate: float = InputField(default=1.0, ge=1.0, le=8.0, description="Down sampling rate")
|
down_sampling_rate: float = InputField(default=1.0, ge=1.0, le=8.0, description="Down sampling rate")
|
||||||
|
|
||||||
@ -523,14 +506,15 @@ class TileResamplerProcessorInvocation(ImageProcessorInvocation):
|
|||||||
return processed_image
|
return processed_image
|
||||||
|
|
||||||
|
|
||||||
@title("Segment Anything Processor")
|
@invocation(
|
||||||
@tags("controlnet", "segmentanything")
|
"segment_anything_processor",
|
||||||
@category("controlnet")
|
title="Segment Anything Processor",
|
||||||
|
tags=["controlnet", "segmentanything"],
|
||||||
|
category="controlnet",
|
||||||
|
)
|
||||||
class SegmentAnythingProcessorInvocation(ImageProcessorInvocation):
|
class SegmentAnythingProcessorInvocation(ImageProcessorInvocation):
|
||||||
"""Applies segment anything processing to image"""
|
"""Applies segment anything processing to image"""
|
||||||
|
|
||||||
type: Literal["segment_anything_processor"] = "segment_anything_processor"
|
|
||||||
|
|
||||||
def run_processor(self, image):
|
def run_processor(self, image):
|
||||||
# segment_anything_processor = SamDetector.from_pretrained("ybelkada/segment-anything", subfolder="checkpoints")
|
# segment_anything_processor = SamDetector.from_pretrained("ybelkada/segment-anything", subfolder="checkpoints")
|
||||||
segment_anything_processor = SamDetectorReproducibleColors.from_pretrained(
|
segment_anything_processor = SamDetectorReproducibleColors.from_pretrained(
|
||||||
|
@ -1,6 +1,5 @@
|
|||||||
# Copyright (c) 2022 Kyle Schouviller (https://github.com/kyle0654)
|
# Copyright (c) 2022 Kyle Schouviller (https://github.com/kyle0654)
|
||||||
|
|
||||||
from typing import Literal
|
|
||||||
|
|
||||||
import cv2 as cv
|
import cv2 as cv
|
||||||
import numpy
|
import numpy
|
||||||
@ -8,18 +7,18 @@ from PIL import Image, ImageOps
|
|||||||
from invokeai.app.invocations.primitives import ImageField, ImageOutput
|
from invokeai.app.invocations.primitives import ImageField, ImageOutput
|
||||||
|
|
||||||
from invokeai.app.models.image import ImageCategory, ResourceOrigin
|
from invokeai.app.models.image import ImageCategory, ResourceOrigin
|
||||||
from .baseinvocation import BaseInvocation, InputField, InvocationContext, category, tags, title
|
from .baseinvocation import BaseInvocation, InputField, InvocationContext, invocation
|
||||||
|
|
||||||
|
|
||||||
@title("OpenCV Inpaint")
|
@invocation(
|
||||||
@tags("opencv", "inpaint")
|
"cv_inpaint",
|
||||||
@category("inpaint")
|
title="OpenCV Inpaint",
|
||||||
|
tags=["opencv", "inpaint"],
|
||||||
|
category="inpaint",
|
||||||
|
)
|
||||||
class CvInpaintInvocation(BaseInvocation):
|
class CvInpaintInvocation(BaseInvocation):
|
||||||
"""Simple inpaint using opencv."""
|
"""Simple inpaint using opencv."""
|
||||||
|
|
||||||
type: Literal["cv_inpaint"] = "cv_inpaint"
|
|
||||||
|
|
||||||
# Inputs
|
|
||||||
image: ImageField = InputField(description="The image to inpaint")
|
image: ImageField = InputField(description="The image to inpaint")
|
||||||
mask: ImageField = InputField(description="The mask to use when inpainting")
|
mask: ImageField = InputField(description="The mask to use when inpainting")
|
||||||
|
|
||||||
|
@ -13,18 +13,13 @@ from invokeai.backend.image_util.invisible_watermark import InvisibleWatermark
|
|||||||
from invokeai.backend.image_util.safety_checker import SafetyChecker
|
from invokeai.backend.image_util.safety_checker import SafetyChecker
|
||||||
|
|
||||||
from ..models.image import ImageCategory, ResourceOrigin
|
from ..models.image import ImageCategory, ResourceOrigin
|
||||||
from .baseinvocation import BaseInvocation, FieldDescriptions, InputField, InvocationContext, tags, title
|
from .baseinvocation import BaseInvocation, FieldDescriptions, InputField, InvocationContext, invocation
|
||||||
|
|
||||||
|
|
||||||
@title("Show Image")
|
@invocation("show_image", title="Show Image", tags=["image"], category="image")
|
||||||
@tags("image")
|
|
||||||
class ShowImageInvocation(BaseInvocation):
|
class ShowImageInvocation(BaseInvocation):
|
||||||
"""Displays a provided image, and passes it forward in the pipeline."""
|
"""Displays a provided image using the OS image viewer, and passes it forward in the pipeline."""
|
||||||
|
|
||||||
# Metadata
|
|
||||||
type: Literal["show_image"] = "show_image"
|
|
||||||
|
|
||||||
# Inputs
|
|
||||||
image: ImageField = InputField(description="The image to show")
|
image: ImageField = InputField(description="The image to show")
|
||||||
|
|
||||||
def invoke(self, context: InvocationContext) -> ImageOutput:
|
def invoke(self, context: InvocationContext) -> ImageOutput:
|
||||||
@ -41,15 +36,10 @@ class ShowImageInvocation(BaseInvocation):
|
|||||||
)
|
)
|
||||||
|
|
||||||
|
|
||||||
@title("Blank Image")
|
@invocation("blank_image", title="Blank Image", tags=["image"], category="image")
|
||||||
@tags("image")
|
|
||||||
class BlankImageInvocation(BaseInvocation):
|
class BlankImageInvocation(BaseInvocation):
|
||||||
"""Creates a blank image and forwards it to the pipeline"""
|
"""Creates a blank image and forwards it to the pipeline"""
|
||||||
|
|
||||||
# Metadata
|
|
||||||
type: Literal["blank_image"] = "blank_image"
|
|
||||||
|
|
||||||
# Inputs
|
|
||||||
width: int = InputField(default=512, description="The width of the image")
|
width: int = InputField(default=512, description="The width of the image")
|
||||||
height: int = InputField(default=512, description="The height of the image")
|
height: int = InputField(default=512, description="The height of the image")
|
||||||
mode: Literal["RGB", "RGBA"] = InputField(default="RGB", description="The mode of the image")
|
mode: Literal["RGB", "RGBA"] = InputField(default="RGB", description="The mode of the image")
|
||||||
@ -75,15 +65,10 @@ class BlankImageInvocation(BaseInvocation):
|
|||||||
)
|
)
|
||||||
|
|
||||||
|
|
||||||
@title("Crop Image")
|
@invocation("img_crop", title="Crop Image", tags=["image", "crop"], category="image")
|
||||||
@tags("image", "crop")
|
|
||||||
class ImageCropInvocation(BaseInvocation):
|
class ImageCropInvocation(BaseInvocation):
|
||||||
"""Crops an image to a specified box. The box can be outside of the image."""
|
"""Crops an image to a specified box. The box can be outside of the image."""
|
||||||
|
|
||||||
# Metadata
|
|
||||||
type: Literal["img_crop"] = "img_crop"
|
|
||||||
|
|
||||||
# Inputs
|
|
||||||
image: ImageField = InputField(description="The image to crop")
|
image: ImageField = InputField(description="The image to crop")
|
||||||
x: int = InputField(default=0, description="The left x coordinate of the crop rectangle")
|
x: int = InputField(default=0, description="The left x coordinate of the crop rectangle")
|
||||||
y: int = InputField(default=0, description="The top y coordinate of the crop rectangle")
|
y: int = InputField(default=0, description="The top y coordinate of the crop rectangle")
|
||||||
@ -113,15 +98,10 @@ class ImageCropInvocation(BaseInvocation):
|
|||||||
)
|
)
|
||||||
|
|
||||||
|
|
||||||
@title("Paste Image")
|
@invocation("img_paste", title="Paste Image", tags=["image", "paste"], category="image")
|
||||||
@tags("image", "paste")
|
|
||||||
class ImagePasteInvocation(BaseInvocation):
|
class ImagePasteInvocation(BaseInvocation):
|
||||||
"""Pastes an image into another image."""
|
"""Pastes an image into another image."""
|
||||||
|
|
||||||
# Metadata
|
|
||||||
type: Literal["img_paste"] = "img_paste"
|
|
||||||
|
|
||||||
# Inputs
|
|
||||||
base_image: ImageField = InputField(description="The base image")
|
base_image: ImageField = InputField(description="The base image")
|
||||||
image: ImageField = InputField(description="The image to paste")
|
image: ImageField = InputField(description="The image to paste")
|
||||||
mask: Optional[ImageField] = InputField(
|
mask: Optional[ImageField] = InputField(
|
||||||
@ -166,15 +146,10 @@ class ImagePasteInvocation(BaseInvocation):
|
|||||||
)
|
)
|
||||||
|
|
||||||
|
|
||||||
@title("Mask from Alpha")
|
@invocation("tomask", title="Mask from Alpha", tags=["image", "mask"], category="image")
|
||||||
@tags("image", "mask")
|
|
||||||
class MaskFromAlphaInvocation(BaseInvocation):
|
class MaskFromAlphaInvocation(BaseInvocation):
|
||||||
"""Extracts the alpha channel of an image as a mask."""
|
"""Extracts the alpha channel of an image as a mask."""
|
||||||
|
|
||||||
# Metadata
|
|
||||||
type: Literal["tomask"] = "tomask"
|
|
||||||
|
|
||||||
# Inputs
|
|
||||||
image: ImageField = InputField(description="The image to create the mask from")
|
image: ImageField = InputField(description="The image to create the mask from")
|
||||||
invert: bool = InputField(default=False, description="Whether or not to invert the mask")
|
invert: bool = InputField(default=False, description="Whether or not to invert the mask")
|
||||||
|
|
||||||
@ -202,15 +177,10 @@ class MaskFromAlphaInvocation(BaseInvocation):
|
|||||||
)
|
)
|
||||||
|
|
||||||
|
|
||||||
@title("Multiply Images")
|
@invocation("img_mul", title="Multiply Images", tags=["image", "multiply"], category="image")
|
||||||
@tags("image", "multiply")
|
|
||||||
class ImageMultiplyInvocation(BaseInvocation):
|
class ImageMultiplyInvocation(BaseInvocation):
|
||||||
"""Multiplies two images together using `PIL.ImageChops.multiply()`."""
|
"""Multiplies two images together using `PIL.ImageChops.multiply()`."""
|
||||||
|
|
||||||
# Metadata
|
|
||||||
type: Literal["img_mul"] = "img_mul"
|
|
||||||
|
|
||||||
# Inputs
|
|
||||||
image1: ImageField = InputField(description="The first image to multiply")
|
image1: ImageField = InputField(description="The first image to multiply")
|
||||||
image2: ImageField = InputField(description="The second image to multiply")
|
image2: ImageField = InputField(description="The second image to multiply")
|
||||||
|
|
||||||
@ -240,15 +210,10 @@ class ImageMultiplyInvocation(BaseInvocation):
|
|||||||
IMAGE_CHANNELS = Literal["A", "R", "G", "B"]
|
IMAGE_CHANNELS = Literal["A", "R", "G", "B"]
|
||||||
|
|
||||||
|
|
||||||
@title("Extract Image Channel")
|
@invocation("img_chan", title="Extract Image Channel", tags=["image", "channel"], category="image")
|
||||||
@tags("image", "channel")
|
|
||||||
class ImageChannelInvocation(BaseInvocation):
|
class ImageChannelInvocation(BaseInvocation):
|
||||||
"""Gets a channel from an image."""
|
"""Gets a channel from an image."""
|
||||||
|
|
||||||
# Metadata
|
|
||||||
type: Literal["img_chan"] = "img_chan"
|
|
||||||
|
|
||||||
# Inputs
|
|
||||||
image: ImageField = InputField(description="The image to get the channel from")
|
image: ImageField = InputField(description="The image to get the channel from")
|
||||||
channel: IMAGE_CHANNELS = InputField(default="A", description="The channel to get")
|
channel: IMAGE_CHANNELS = InputField(default="A", description="The channel to get")
|
||||||
|
|
||||||
@ -277,15 +242,10 @@ class ImageChannelInvocation(BaseInvocation):
|
|||||||
IMAGE_MODES = Literal["L", "RGB", "RGBA", "CMYK", "YCbCr", "LAB", "HSV", "I", "F"]
|
IMAGE_MODES = Literal["L", "RGB", "RGBA", "CMYK", "YCbCr", "LAB", "HSV", "I", "F"]
|
||||||
|
|
||||||
|
|
||||||
@title("Convert Image Mode")
|
@invocation("img_conv", title="Convert Image Mode", tags=["image", "convert"], category="image")
|
||||||
@tags("image", "convert")
|
|
||||||
class ImageConvertInvocation(BaseInvocation):
|
class ImageConvertInvocation(BaseInvocation):
|
||||||
"""Converts an image to a different mode."""
|
"""Converts an image to a different mode."""
|
||||||
|
|
||||||
# Metadata
|
|
||||||
type: Literal["img_conv"] = "img_conv"
|
|
||||||
|
|
||||||
# Inputs
|
|
||||||
image: ImageField = InputField(description="The image to convert")
|
image: ImageField = InputField(description="The image to convert")
|
||||||
mode: IMAGE_MODES = InputField(default="L", description="The mode to convert to")
|
mode: IMAGE_MODES = InputField(default="L", description="The mode to convert to")
|
||||||
|
|
||||||
@ -311,15 +271,10 @@ class ImageConvertInvocation(BaseInvocation):
|
|||||||
)
|
)
|
||||||
|
|
||||||
|
|
||||||
@title("Blur Image")
|
@invocation("img_blur", title="Blur Image", tags=["image", "blur"], category="image")
|
||||||
@tags("image", "blur")
|
|
||||||
class ImageBlurInvocation(BaseInvocation):
|
class ImageBlurInvocation(BaseInvocation):
|
||||||
"""Blurs an image"""
|
"""Blurs an image"""
|
||||||
|
|
||||||
# Metadata
|
|
||||||
type: Literal["img_blur"] = "img_blur"
|
|
||||||
|
|
||||||
# Inputs
|
|
||||||
image: ImageField = InputField(description="The image to blur")
|
image: ImageField = InputField(description="The image to blur")
|
||||||
radius: float = InputField(default=8.0, ge=0, description="The blur radius")
|
radius: float = InputField(default=8.0, ge=0, description="The blur radius")
|
||||||
# Metadata
|
# Metadata
|
||||||
@ -370,15 +325,10 @@ PIL_RESAMPLING_MAP = {
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@title("Resize Image")
|
@invocation("img_resize", title="Resize Image", tags=["image", "resize"], category="image")
|
||||||
@tags("image", "resize")
|
|
||||||
class ImageResizeInvocation(BaseInvocation):
|
class ImageResizeInvocation(BaseInvocation):
|
||||||
"""Resizes an image to specific dimensions"""
|
"""Resizes an image to specific dimensions"""
|
||||||
|
|
||||||
# Metadata
|
|
||||||
type: Literal["img_resize"] = "img_resize"
|
|
||||||
|
|
||||||
# Inputs
|
|
||||||
image: ImageField = InputField(description="The image to resize")
|
image: ImageField = InputField(description="The image to resize")
|
||||||
width: int = InputField(default=512, ge=64, multiple_of=8, description="The width to resize to (px)")
|
width: int = InputField(default=512, ge=64, multiple_of=8, description="The width to resize to (px)")
|
||||||
height: int = InputField(default=512, ge=64, multiple_of=8, description="The height to resize to (px)")
|
height: int = InputField(default=512, ge=64, multiple_of=8, description="The height to resize to (px)")
|
||||||
@ -415,15 +365,10 @@ class ImageResizeInvocation(BaseInvocation):
|
|||||||
)
|
)
|
||||||
|
|
||||||
|
|
||||||
@title("Scale Image")
|
@invocation("img_scale", title="Scale Image", tags=["image", "scale"], category="image")
|
||||||
@tags("image", "scale")
|
|
||||||
class ImageScaleInvocation(BaseInvocation):
|
class ImageScaleInvocation(BaseInvocation):
|
||||||
"""Scales an image by a factor"""
|
"""Scales an image by a factor"""
|
||||||
|
|
||||||
# Metadata
|
|
||||||
type: Literal["img_scale"] = "img_scale"
|
|
||||||
|
|
||||||
# Inputs
|
|
||||||
image: ImageField = InputField(description="The image to scale")
|
image: ImageField = InputField(description="The image to scale")
|
||||||
scale_factor: float = InputField(
|
scale_factor: float = InputField(
|
||||||
default=2.0,
|
default=2.0,
|
||||||
@ -461,15 +406,10 @@ class ImageScaleInvocation(BaseInvocation):
|
|||||||
)
|
)
|
||||||
|
|
||||||
|
|
||||||
@title("Lerp Image")
|
@invocation("img_lerp", title="Lerp Image", tags=["image", "lerp"], category="image")
|
||||||
@tags("image", "lerp")
|
|
||||||
class ImageLerpInvocation(BaseInvocation):
|
class ImageLerpInvocation(BaseInvocation):
|
||||||
"""Linear interpolation of all pixels of an image"""
|
"""Linear interpolation of all pixels of an image"""
|
||||||
|
|
||||||
# Metadata
|
|
||||||
type: Literal["img_lerp"] = "img_lerp"
|
|
||||||
|
|
||||||
# Inputs
|
|
||||||
image: ImageField = InputField(description="The image to lerp")
|
image: ImageField = InputField(description="The image to lerp")
|
||||||
min: int = InputField(default=0, ge=0, le=255, description="The minimum output value")
|
min: int = InputField(default=0, ge=0, le=255, description="The minimum output value")
|
||||||
max: int = InputField(default=255, ge=0, le=255, description="The maximum output value")
|
max: int = InputField(default=255, ge=0, le=255, description="The maximum output value")
|
||||||
@ -499,15 +439,10 @@ class ImageLerpInvocation(BaseInvocation):
|
|||||||
)
|
)
|
||||||
|
|
||||||
|
|
||||||
@title("Inverse Lerp Image")
|
@invocation("img_ilerp", title="Inverse Lerp Image", tags=["image", "ilerp"], category="image")
|
||||||
@tags("image", "ilerp")
|
|
||||||
class ImageInverseLerpInvocation(BaseInvocation):
|
class ImageInverseLerpInvocation(BaseInvocation):
|
||||||
"""Inverse linear interpolation of all pixels of an image"""
|
"""Inverse linear interpolation of all pixels of an image"""
|
||||||
|
|
||||||
# Metadata
|
|
||||||
type: Literal["img_ilerp"] = "img_ilerp"
|
|
||||||
|
|
||||||
# Inputs
|
|
||||||
image: ImageField = InputField(description="The image to lerp")
|
image: ImageField = InputField(description="The image to lerp")
|
||||||
min: int = InputField(default=0, ge=0, le=255, description="The minimum input value")
|
min: int = InputField(default=0, ge=0, le=255, description="The minimum input value")
|
||||||
max: int = InputField(default=255, ge=0, le=255, description="The maximum input value")
|
max: int = InputField(default=255, ge=0, le=255, description="The maximum input value")
|
||||||
@ -537,15 +472,10 @@ class ImageInverseLerpInvocation(BaseInvocation):
|
|||||||
)
|
)
|
||||||
|
|
||||||
|
|
||||||
@title("Blur NSFW Image")
|
@invocation("img_nsfw", title="Blur NSFW Image", tags=["image", "nsfw"], category="image")
|
||||||
@tags("image", "nsfw")
|
|
||||||
class ImageNSFWBlurInvocation(BaseInvocation):
|
class ImageNSFWBlurInvocation(BaseInvocation):
|
||||||
"""Add blur to NSFW-flagged images"""
|
"""Add blur to NSFW-flagged images"""
|
||||||
|
|
||||||
# Metadata
|
|
||||||
type: Literal["img_nsfw"] = "img_nsfw"
|
|
||||||
|
|
||||||
# Inputs
|
|
||||||
image: ImageField = InputField(description="The image to check")
|
image: ImageField = InputField(description="The image to check")
|
||||||
metadata: Optional[CoreMetadata] = InputField(
|
metadata: Optional[CoreMetadata] = InputField(
|
||||||
default=None, description=FieldDescriptions.core_metadata, ui_hidden=True
|
default=None, description=FieldDescriptions.core_metadata, ui_hidden=True
|
||||||
@ -587,15 +517,10 @@ class ImageNSFWBlurInvocation(BaseInvocation):
|
|||||||
return caution.resize((caution.width // 2, caution.height // 2))
|
return caution.resize((caution.width // 2, caution.height // 2))
|
||||||
|
|
||||||
|
|
||||||
@title("Add Invisible Watermark")
|
@invocation("img_watermark", title="Add Invisible Watermark", tags=["image", "watermark"], category="image")
|
||||||
@tags("image", "watermark")
|
|
||||||
class ImageWatermarkInvocation(BaseInvocation):
|
class ImageWatermarkInvocation(BaseInvocation):
|
||||||
"""Add an invisible watermark to an image"""
|
"""Add an invisible watermark to an image"""
|
||||||
|
|
||||||
# Metadata
|
|
||||||
type: Literal["img_watermark"] = "img_watermark"
|
|
||||||
|
|
||||||
# Inputs
|
|
||||||
image: ImageField = InputField(description="The image to check")
|
image: ImageField = InputField(description="The image to check")
|
||||||
text: str = InputField(default="InvokeAI", description="Watermark text")
|
text: str = InputField(default="InvokeAI", description="Watermark text")
|
||||||
metadata: Optional[CoreMetadata] = InputField(
|
metadata: Optional[CoreMetadata] = InputField(
|
||||||
@ -623,14 +548,10 @@ class ImageWatermarkInvocation(BaseInvocation):
|
|||||||
)
|
)
|
||||||
|
|
||||||
|
|
||||||
@title("Mask Edge")
|
@invocation("mask_edge", title="Mask Edge", tags=["image", "mask", "inpaint"], category="image")
|
||||||
@tags("image", "mask", "inpaint")
|
|
||||||
class MaskEdgeInvocation(BaseInvocation):
|
class MaskEdgeInvocation(BaseInvocation):
|
||||||
"""Applies an edge mask to an image"""
|
"""Applies an edge mask to an image"""
|
||||||
|
|
||||||
type: Literal["mask_edge"] = "mask_edge"
|
|
||||||
|
|
||||||
# Inputs
|
|
||||||
image: ImageField = InputField(description="The image to apply the mask to")
|
image: ImageField = InputField(description="The image to apply the mask to")
|
||||||
edge_size: int = InputField(description="The size of the edge")
|
edge_size: int = InputField(description="The size of the edge")
|
||||||
edge_blur: int = InputField(description="The amount of blur on the edge")
|
edge_blur: int = InputField(description="The amount of blur on the edge")
|
||||||
@ -672,14 +593,10 @@ class MaskEdgeInvocation(BaseInvocation):
|
|||||||
)
|
)
|
||||||
|
|
||||||
|
|
||||||
@title("Combine Mask")
|
@invocation("mask_combine", title="Combine Masks", tags=["image", "mask", "multiply"], category="image")
|
||||||
@tags("image", "mask", "multiply")
|
|
||||||
class MaskCombineInvocation(BaseInvocation):
|
class MaskCombineInvocation(BaseInvocation):
|
||||||
"""Combine two masks together by multiplying them using `PIL.ImageChops.multiply()`."""
|
"""Combine two masks together by multiplying them using `PIL.ImageChops.multiply()`."""
|
||||||
|
|
||||||
type: Literal["mask_combine"] = "mask_combine"
|
|
||||||
|
|
||||||
# Inputs
|
|
||||||
mask1: ImageField = InputField(description="The first mask to combine")
|
mask1: ImageField = InputField(description="The first mask to combine")
|
||||||
mask2: ImageField = InputField(description="The second image to combine")
|
mask2: ImageField = InputField(description="The second image to combine")
|
||||||
|
|
||||||
@ -706,17 +623,13 @@ class MaskCombineInvocation(BaseInvocation):
|
|||||||
)
|
)
|
||||||
|
|
||||||
|
|
||||||
@title("Color Correct")
|
@invocation("color_correct", title="Color Correct", tags=["image", "color"], category="image")
|
||||||
@tags("image", "color")
|
|
||||||
class ColorCorrectInvocation(BaseInvocation):
|
class ColorCorrectInvocation(BaseInvocation):
|
||||||
"""
|
"""
|
||||||
Shifts the colors of a target image to match the reference image, optionally
|
Shifts the colors of a target image to match the reference image, optionally
|
||||||
using a mask to only color-correct certain regions of the target image.
|
using a mask to only color-correct certain regions of the target image.
|
||||||
"""
|
"""
|
||||||
|
|
||||||
type: Literal["color_correct"] = "color_correct"
|
|
||||||
|
|
||||||
# Inputs
|
|
||||||
image: ImageField = InputField(description="The image to color-correct")
|
image: ImageField = InputField(description="The image to color-correct")
|
||||||
reference: ImageField = InputField(description="Reference image for color-correction")
|
reference: ImageField = InputField(description="Reference image for color-correction")
|
||||||
mask: Optional[ImageField] = InputField(default=None, description="Mask to use when applying color-correction")
|
mask: Optional[ImageField] = InputField(default=None, description="Mask to use when applying color-correction")
|
||||||
@ -815,14 +728,10 @@ class ColorCorrectInvocation(BaseInvocation):
|
|||||||
)
|
)
|
||||||
|
|
||||||
|
|
||||||
@title("Image Hue Adjustment")
|
@invocation("img_hue_adjust", title="Adjust Image Hue", tags=["image", "hue"], category="image")
|
||||||
@tags("image", "hue", "hsl")
|
|
||||||
class ImageHueAdjustmentInvocation(BaseInvocation):
|
class ImageHueAdjustmentInvocation(BaseInvocation):
|
||||||
"""Adjusts the Hue of an image."""
|
"""Adjusts the Hue of an image."""
|
||||||
|
|
||||||
type: Literal["img_hue_adjust"] = "img_hue_adjust"
|
|
||||||
|
|
||||||
# Inputs
|
|
||||||
image: ImageField = InputField(description="The image to adjust")
|
image: ImageField = InputField(description="The image to adjust")
|
||||||
hue: int = InputField(default=0, description="The degrees by which to rotate the hue, 0-360")
|
hue: int = InputField(default=0, description="The degrees by which to rotate the hue, 0-360")
|
||||||
|
|
||||||
@ -860,14 +769,15 @@ class ImageHueAdjustmentInvocation(BaseInvocation):
|
|||||||
)
|
)
|
||||||
|
|
||||||
|
|
||||||
@title("Image Luminosity Adjustment")
|
@invocation(
|
||||||
@tags("image", "luminosity", "hsl")
|
"img_luminosity_adjust",
|
||||||
|
title="Adjust Image Luminosity",
|
||||||
|
tags=["image", "luminosity", "hsl"],
|
||||||
|
category="image",
|
||||||
|
)
|
||||||
class ImageLuminosityAdjustmentInvocation(BaseInvocation):
|
class ImageLuminosityAdjustmentInvocation(BaseInvocation):
|
||||||
"""Adjusts the Luminosity (Value) of an image."""
|
"""Adjusts the Luminosity (Value) of an image."""
|
||||||
|
|
||||||
type: Literal["img_luminosity_adjust"] = "img_luminosity_adjust"
|
|
||||||
|
|
||||||
# Inputs
|
|
||||||
image: ImageField = InputField(description="The image to adjust")
|
image: ImageField = InputField(description="The image to adjust")
|
||||||
luminosity: float = InputField(
|
luminosity: float = InputField(
|
||||||
default=1.0, ge=0, le=1, description="The factor by which to adjust the luminosity (value)"
|
default=1.0, ge=0, le=1, description="The factor by which to adjust the luminosity (value)"
|
||||||
@ -911,14 +821,15 @@ class ImageLuminosityAdjustmentInvocation(BaseInvocation):
|
|||||||
)
|
)
|
||||||
|
|
||||||
|
|
||||||
@title("Image Saturation Adjustment")
|
@invocation(
|
||||||
@tags("image", "saturation", "hsl")
|
"img_saturation_adjust",
|
||||||
|
title="Adjust Image Saturation",
|
||||||
|
tags=["image", "saturation", "hsl"],
|
||||||
|
category="image",
|
||||||
|
)
|
||||||
class ImageSaturationAdjustmentInvocation(BaseInvocation):
|
class ImageSaturationAdjustmentInvocation(BaseInvocation):
|
||||||
"""Adjusts the Saturation of an image."""
|
"""Adjusts the Saturation of an image."""
|
||||||
|
|
||||||
type: Literal["img_saturation_adjust"] = "img_saturation_adjust"
|
|
||||||
|
|
||||||
# Inputs
|
|
||||||
image: ImageField = InputField(description="The image to adjust")
|
image: ImageField = InputField(description="The image to adjust")
|
||||||
saturation: float = InputField(default=1.0, ge=0, le=1, description="The factor by which to adjust the saturation")
|
saturation: float = InputField(default=1.0, ge=0, le=1, description="The factor by which to adjust the saturation")
|
||||||
|
|
||||||
|
@ -12,7 +12,7 @@ from invokeai.backend.image_util.lama import LaMA
|
|||||||
from invokeai.backend.image_util.patchmatch import PatchMatch
|
from invokeai.backend.image_util.patchmatch import PatchMatch
|
||||||
|
|
||||||
from ..models.image import ImageCategory, ResourceOrigin
|
from ..models.image import ImageCategory, ResourceOrigin
|
||||||
from .baseinvocation import BaseInvocation, InputField, InvocationContext, tags, title
|
from .baseinvocation import BaseInvocation, InputField, InvocationContext, invocation
|
||||||
|
|
||||||
|
|
||||||
def infill_methods() -> list[str]:
|
def infill_methods() -> list[str]:
|
||||||
@ -116,14 +116,10 @@ def tile_fill_missing(im: Image.Image, tile_size: int = 16, seed: Optional[int]
|
|||||||
return si
|
return si
|
||||||
|
|
||||||
|
|
||||||
@title("Solid Color Infill")
|
@invocation("infill_rgba", title="Solid Color Infill", tags=["image", "inpaint"], category="inpaint")
|
||||||
@tags("image", "inpaint")
|
|
||||||
class InfillColorInvocation(BaseInvocation):
|
class InfillColorInvocation(BaseInvocation):
|
||||||
"""Infills transparent areas of an image with a solid color"""
|
"""Infills transparent areas of an image with a solid color"""
|
||||||
|
|
||||||
type: Literal["infill_rgba"] = "infill_rgba"
|
|
||||||
|
|
||||||
# Inputs
|
|
||||||
image: ImageField = InputField(description="The image to infill")
|
image: ImageField = InputField(description="The image to infill")
|
||||||
color: ColorField = InputField(
|
color: ColorField = InputField(
|
||||||
default=ColorField(r=127, g=127, b=127, a=255),
|
default=ColorField(r=127, g=127, b=127, a=255),
|
||||||
@ -155,14 +151,10 @@ class InfillColorInvocation(BaseInvocation):
|
|||||||
)
|
)
|
||||||
|
|
||||||
|
|
||||||
@title("Tile Infill")
|
@invocation("infill_tile", title="Tile Infill", tags=["image", "inpaint"], category="inpaint")
|
||||||
@tags("image", "inpaint")
|
|
||||||
class InfillTileInvocation(BaseInvocation):
|
class InfillTileInvocation(BaseInvocation):
|
||||||
"""Infills transparent areas of an image with tiles of the image"""
|
"""Infills transparent areas of an image with tiles of the image"""
|
||||||
|
|
||||||
type: Literal["infill_tile"] = "infill_tile"
|
|
||||||
|
|
||||||
# Input
|
|
||||||
image: ImageField = InputField(description="The image to infill")
|
image: ImageField = InputField(description="The image to infill")
|
||||||
tile_size: int = InputField(default=32, ge=1, description="The tile size (px)")
|
tile_size: int = InputField(default=32, ge=1, description="The tile size (px)")
|
||||||
seed: int = InputField(
|
seed: int = InputField(
|
||||||
@ -195,14 +187,10 @@ class InfillTileInvocation(BaseInvocation):
|
|||||||
)
|
)
|
||||||
|
|
||||||
|
|
||||||
@title("PatchMatch Infill")
|
@invocation("infill_patchmatch", title="PatchMatch Infill", tags=["image", "inpaint"], category="inpaint")
|
||||||
@tags("image", "inpaint")
|
|
||||||
class InfillPatchMatchInvocation(BaseInvocation):
|
class InfillPatchMatchInvocation(BaseInvocation):
|
||||||
"""Infills transparent areas of an image using the PatchMatch algorithm"""
|
"""Infills transparent areas of an image using the PatchMatch algorithm"""
|
||||||
|
|
||||||
type: Literal["infill_patchmatch"] = "infill_patchmatch"
|
|
||||||
|
|
||||||
# Inputs
|
|
||||||
image: ImageField = InputField(description="The image to infill")
|
image: ImageField = InputField(description="The image to infill")
|
||||||
|
|
||||||
def invoke(self, context: InvocationContext) -> ImageOutput:
|
def invoke(self, context: InvocationContext) -> ImageOutput:
|
||||||
@ -230,14 +218,10 @@ class InfillPatchMatchInvocation(BaseInvocation):
|
|||||||
)
|
)
|
||||||
|
|
||||||
|
|
||||||
@title("LaMa Infill")
|
@invocation("infill_lama", title="LaMa Infill", tags=["image", "inpaint"], category="inpaint")
|
||||||
@tags("image", "inpaint")
|
|
||||||
class LaMaInfillInvocation(BaseInvocation):
|
class LaMaInfillInvocation(BaseInvocation):
|
||||||
"""Infills transparent areas of an image using the LaMa model"""
|
"""Infills transparent areas of an image using the LaMa model"""
|
||||||
|
|
||||||
type: Literal["infill_lama"] = "infill_lama"
|
|
||||||
|
|
||||||
# Inputs
|
|
||||||
image: ImageField = InputField(description="The image to infill")
|
image: ImageField = InputField(description="The image to infill")
|
||||||
|
|
||||||
def invoke(self, context: InvocationContext) -> ImageOutput:
|
def invoke(self, context: InvocationContext) -> ImageOutput:
|
||||||
|
@ -47,7 +47,15 @@ from ...backend.stable_diffusion.diffusion.shared_invokeai_diffusion import Post
|
|||||||
from ...backend.stable_diffusion.schedulers import SCHEDULER_MAP
|
from ...backend.stable_diffusion.schedulers import SCHEDULER_MAP
|
||||||
from ...backend.util.devices import choose_precision, choose_torch_device
|
from ...backend.util.devices import choose_precision, choose_torch_device
|
||||||
from ..models.image import ImageCategory, ResourceOrigin
|
from ..models.image import ImageCategory, ResourceOrigin
|
||||||
from .baseinvocation import BaseInvocation, FieldDescriptions, Input, InputField, InvocationContext, UIType, tags, title
|
from .baseinvocation import (
|
||||||
|
BaseInvocation,
|
||||||
|
FieldDescriptions,
|
||||||
|
Input,
|
||||||
|
InputField,
|
||||||
|
InvocationContext,
|
||||||
|
UIType,
|
||||||
|
invocation,
|
||||||
|
)
|
||||||
from .compel import ConditioningField
|
from .compel import ConditioningField
|
||||||
from .controlnet_image_processors import ControlField
|
from .controlnet_image_processors import ControlField
|
||||||
from .model import ModelInfo, UNetField, VaeField
|
from .model import ModelInfo, UNetField, VaeField
|
||||||
@ -58,15 +66,10 @@ DEFAULT_PRECISION = choose_precision(choose_torch_device())
|
|||||||
SAMPLER_NAME_VALUES = Literal[tuple(list(SCHEDULER_MAP.keys()))]
|
SAMPLER_NAME_VALUES = Literal[tuple(list(SCHEDULER_MAP.keys()))]
|
||||||
|
|
||||||
|
|
||||||
@title("Create Denoise Mask")
|
@invocation("create_denoise_mask", title="Create Denoise Mask", tags=["mask", "denoise"], category="latents")
|
||||||
@tags("mask", "denoise")
|
|
||||||
class CreateDenoiseMaskInvocation(BaseInvocation):
|
class CreateDenoiseMaskInvocation(BaseInvocation):
|
||||||
"""Creates mask for denoising model run."""
|
"""Creates mask for denoising model run."""
|
||||||
|
|
||||||
# Metadata
|
|
||||||
type: Literal["create_denoise_mask"] = "create_denoise_mask"
|
|
||||||
|
|
||||||
# Inputs
|
|
||||||
vae: VaeField = InputField(description=FieldDescriptions.vae, input=Input.Connection, ui_order=0)
|
vae: VaeField = InputField(description=FieldDescriptions.vae, input=Input.Connection, ui_order=0)
|
||||||
image: Optional[ImageField] = InputField(default=None, description="Image which will be masked", ui_order=1)
|
image: Optional[ImageField] = InputField(default=None, description="Image which will be masked", ui_order=1)
|
||||||
mask: ImageField = InputField(description="The mask to use when pasting", ui_order=2)
|
mask: ImageField = InputField(description="The mask to use when pasting", ui_order=2)
|
||||||
@ -158,14 +161,15 @@ def get_scheduler(
|
|||||||
return scheduler
|
return scheduler
|
||||||
|
|
||||||
|
|
||||||
@title("Denoise Latents")
|
@invocation(
|
||||||
@tags("latents", "denoise", "txt2img", "t2i", "t2l", "img2img", "i2i", "l2l")
|
"denoise_latents",
|
||||||
|
title="Denoise Latents",
|
||||||
|
tags=["latents", "denoise", "txt2img", "t2i", "t2l", "img2img", "i2i", "l2l"],
|
||||||
|
category="latents",
|
||||||
|
)
|
||||||
class DenoiseLatentsInvocation(BaseInvocation):
|
class DenoiseLatentsInvocation(BaseInvocation):
|
||||||
"""Denoises noisy latents to decodable images"""
|
"""Denoises noisy latents to decodable images"""
|
||||||
|
|
||||||
type: Literal["denoise_latents"] = "denoise_latents"
|
|
||||||
|
|
||||||
# Inputs
|
|
||||||
positive_conditioning: ConditioningField = InputField(
|
positive_conditioning: ConditioningField = InputField(
|
||||||
description=FieldDescriptions.positive_cond, input=Input.Connection, ui_order=0
|
description=FieldDescriptions.positive_cond, input=Input.Connection, ui_order=0
|
||||||
)
|
)
|
||||||
@ -512,14 +516,10 @@ class DenoiseLatentsInvocation(BaseInvocation):
|
|||||||
return build_latents_output(latents_name=name, latents=result_latents, seed=seed)
|
return build_latents_output(latents_name=name, latents=result_latents, seed=seed)
|
||||||
|
|
||||||
|
|
||||||
@title("Latents to Image")
|
@invocation("l2i", title="Latents to Image", tags=["latents", "image", "vae", "l2i"], category="latents")
|
||||||
@tags("latents", "image", "vae", "l2i")
|
|
||||||
class LatentsToImageInvocation(BaseInvocation):
|
class LatentsToImageInvocation(BaseInvocation):
|
||||||
"""Generates an image from latents."""
|
"""Generates an image from latents."""
|
||||||
|
|
||||||
type: Literal["l2i"] = "l2i"
|
|
||||||
|
|
||||||
# Inputs
|
|
||||||
latents: LatentsField = InputField(
|
latents: LatentsField = InputField(
|
||||||
description=FieldDescriptions.latents,
|
description=FieldDescriptions.latents,
|
||||||
input=Input.Connection,
|
input=Input.Connection,
|
||||||
@ -613,14 +613,10 @@ class LatentsToImageInvocation(BaseInvocation):
|
|||||||
LATENTS_INTERPOLATION_MODE = Literal["nearest", "linear", "bilinear", "bicubic", "trilinear", "area", "nearest-exact"]
|
LATENTS_INTERPOLATION_MODE = Literal["nearest", "linear", "bilinear", "bicubic", "trilinear", "area", "nearest-exact"]
|
||||||
|
|
||||||
|
|
||||||
@title("Resize Latents")
|
@invocation("lresize", title="Resize Latents", tags=["latents", "resize"], category="latents")
|
||||||
@tags("latents", "resize")
|
|
||||||
class ResizeLatentsInvocation(BaseInvocation):
|
class ResizeLatentsInvocation(BaseInvocation):
|
||||||
"""Resizes latents to explicit width/height (in pixels). Provided dimensions are floor-divided by 8."""
|
"""Resizes latents to explicit width/height (in pixels). Provided dimensions are floor-divided by 8."""
|
||||||
|
|
||||||
type: Literal["lresize"] = "lresize"
|
|
||||||
|
|
||||||
# Inputs
|
|
||||||
latents: LatentsField = InputField(
|
latents: LatentsField = InputField(
|
||||||
description=FieldDescriptions.latents,
|
description=FieldDescriptions.latents,
|
||||||
input=Input.Connection,
|
input=Input.Connection,
|
||||||
@ -661,14 +657,10 @@ class ResizeLatentsInvocation(BaseInvocation):
|
|||||||
return build_latents_output(latents_name=name, latents=resized_latents, seed=self.latents.seed)
|
return build_latents_output(latents_name=name, latents=resized_latents, seed=self.latents.seed)
|
||||||
|
|
||||||
|
|
||||||
@title("Scale Latents")
|
@invocation("lscale", title="Scale Latents", tags=["latents", "resize"], category="latents")
|
||||||
@tags("latents", "resize")
|
|
||||||
class ScaleLatentsInvocation(BaseInvocation):
|
class ScaleLatentsInvocation(BaseInvocation):
|
||||||
"""Scales latents by a given factor."""
|
"""Scales latents by a given factor."""
|
||||||
|
|
||||||
type: Literal["lscale"] = "lscale"
|
|
||||||
|
|
||||||
# Inputs
|
|
||||||
latents: LatentsField = InputField(
|
latents: LatentsField = InputField(
|
||||||
description=FieldDescriptions.latents,
|
description=FieldDescriptions.latents,
|
||||||
input=Input.Connection,
|
input=Input.Connection,
|
||||||
@ -701,14 +693,10 @@ class ScaleLatentsInvocation(BaseInvocation):
|
|||||||
return build_latents_output(latents_name=name, latents=resized_latents, seed=self.latents.seed)
|
return build_latents_output(latents_name=name, latents=resized_latents, seed=self.latents.seed)
|
||||||
|
|
||||||
|
|
||||||
@title("Image to Latents")
|
@invocation("i2l", title="Image to Latents", tags=["latents", "image", "vae", "i2l"], category="latents")
|
||||||
@tags("latents", "image", "vae", "i2l")
|
|
||||||
class ImageToLatentsInvocation(BaseInvocation):
|
class ImageToLatentsInvocation(BaseInvocation):
|
||||||
"""Encodes an image into latents."""
|
"""Encodes an image into latents."""
|
||||||
|
|
||||||
type: Literal["i2l"] = "i2l"
|
|
||||||
|
|
||||||
# Inputs
|
|
||||||
image: ImageField = InputField(
|
image: ImageField = InputField(
|
||||||
description="The image to encode",
|
description="The image to encode",
|
||||||
)
|
)
|
||||||
@ -785,14 +773,10 @@ class ImageToLatentsInvocation(BaseInvocation):
|
|||||||
return build_latents_output(latents_name=name, latents=latents, seed=None)
|
return build_latents_output(latents_name=name, latents=latents, seed=None)
|
||||||
|
|
||||||
|
|
||||||
@title("Blend Latents")
|
@invocation("lblend", title="Blend Latents", tags=["latents", "blend"], category="latents")
|
||||||
@tags("latents", "blend")
|
|
||||||
class BlendLatentsInvocation(BaseInvocation):
|
class BlendLatentsInvocation(BaseInvocation):
|
||||||
"""Blend two latents using a given alpha. Latents must have same size."""
|
"""Blend two latents using a given alpha. Latents must have same size."""
|
||||||
|
|
||||||
type: Literal["lblend"] = "lblend"
|
|
||||||
|
|
||||||
# Inputs
|
|
||||||
latents_a: LatentsField = InputField(
|
latents_a: LatentsField = InputField(
|
||||||
description=FieldDescriptions.latents,
|
description=FieldDescriptions.latents,
|
||||||
input=Input.Connection,
|
input=Input.Connection,
|
||||||
|
@ -1,22 +1,16 @@
|
|||||||
# Copyright (c) 2023 Kyle Schouviller (https://github.com/kyle0654)
|
# Copyright (c) 2023 Kyle Schouviller (https://github.com/kyle0654)
|
||||||
|
|
||||||
from typing import Literal
|
|
||||||
|
|
||||||
import numpy as np
|
import numpy as np
|
||||||
|
|
||||||
from invokeai.app.invocations.primitives import IntegerOutput
|
from invokeai.app.invocations.primitives import IntegerOutput
|
||||||
|
|
||||||
from .baseinvocation import BaseInvocation, FieldDescriptions, InputField, InvocationContext, tags, title
|
from .baseinvocation import BaseInvocation, FieldDescriptions, InputField, InvocationContext, invocation
|
||||||
|
|
||||||
|
|
||||||
@title("Add Integers")
|
@invocation("add", title="Add Integers", tags=["math", "add"], category="math")
|
||||||
@tags("math")
|
|
||||||
class AddInvocation(BaseInvocation):
|
class AddInvocation(BaseInvocation):
|
||||||
"""Adds two numbers"""
|
"""Adds two numbers"""
|
||||||
|
|
||||||
type: Literal["add"] = "add"
|
|
||||||
|
|
||||||
# Inputs
|
|
||||||
a: int = InputField(default=0, description=FieldDescriptions.num_1)
|
a: int = InputField(default=0, description=FieldDescriptions.num_1)
|
||||||
b: int = InputField(default=0, description=FieldDescriptions.num_2)
|
b: int = InputField(default=0, description=FieldDescriptions.num_2)
|
||||||
|
|
||||||
@ -24,14 +18,10 @@ class AddInvocation(BaseInvocation):
|
|||||||
return IntegerOutput(value=self.a + self.b)
|
return IntegerOutput(value=self.a + self.b)
|
||||||
|
|
||||||
|
|
||||||
@title("Subtract Integers")
|
@invocation("sub", title="Subtract Integers", tags=["math", "subtract"], category="math")
|
||||||
@tags("math")
|
|
||||||
class SubtractInvocation(BaseInvocation):
|
class SubtractInvocation(BaseInvocation):
|
||||||
"""Subtracts two numbers"""
|
"""Subtracts two numbers"""
|
||||||
|
|
||||||
type: Literal["sub"] = "sub"
|
|
||||||
|
|
||||||
# Inputs
|
|
||||||
a: int = InputField(default=0, description=FieldDescriptions.num_1)
|
a: int = InputField(default=0, description=FieldDescriptions.num_1)
|
||||||
b: int = InputField(default=0, description=FieldDescriptions.num_2)
|
b: int = InputField(default=0, description=FieldDescriptions.num_2)
|
||||||
|
|
||||||
@ -39,14 +29,10 @@ class SubtractInvocation(BaseInvocation):
|
|||||||
return IntegerOutput(value=self.a - self.b)
|
return IntegerOutput(value=self.a - self.b)
|
||||||
|
|
||||||
|
|
||||||
@title("Multiply Integers")
|
@invocation("mul", title="Multiply Integers", tags=["math", "multiply"], category="math")
|
||||||
@tags("math")
|
|
||||||
class MultiplyInvocation(BaseInvocation):
|
class MultiplyInvocation(BaseInvocation):
|
||||||
"""Multiplies two numbers"""
|
"""Multiplies two numbers"""
|
||||||
|
|
||||||
type: Literal["mul"] = "mul"
|
|
||||||
|
|
||||||
# Inputs
|
|
||||||
a: int = InputField(default=0, description=FieldDescriptions.num_1)
|
a: int = InputField(default=0, description=FieldDescriptions.num_1)
|
||||||
b: int = InputField(default=0, description=FieldDescriptions.num_2)
|
b: int = InputField(default=0, description=FieldDescriptions.num_2)
|
||||||
|
|
||||||
@ -54,14 +40,10 @@ class MultiplyInvocation(BaseInvocation):
|
|||||||
return IntegerOutput(value=self.a * self.b)
|
return IntegerOutput(value=self.a * self.b)
|
||||||
|
|
||||||
|
|
||||||
@title("Divide Integers")
|
@invocation("div", title="Divide Integers", tags=["math", "divide"], category="math")
|
||||||
@tags("math")
|
|
||||||
class DivideInvocation(BaseInvocation):
|
class DivideInvocation(BaseInvocation):
|
||||||
"""Divides two numbers"""
|
"""Divides two numbers"""
|
||||||
|
|
||||||
type: Literal["div"] = "div"
|
|
||||||
|
|
||||||
# Inputs
|
|
||||||
a: int = InputField(default=0, description=FieldDescriptions.num_1)
|
a: int = InputField(default=0, description=FieldDescriptions.num_1)
|
||||||
b: int = InputField(default=0, description=FieldDescriptions.num_2)
|
b: int = InputField(default=0, description=FieldDescriptions.num_2)
|
||||||
|
|
||||||
@ -69,14 +51,10 @@ class DivideInvocation(BaseInvocation):
|
|||||||
return IntegerOutput(value=int(self.a / self.b))
|
return IntegerOutput(value=int(self.a / self.b))
|
||||||
|
|
||||||
|
|
||||||
@title("Random Integer")
|
@invocation("rand_int", title="Random Integer", tags=["math", "random"], category="math")
|
||||||
@tags("math")
|
|
||||||
class RandomIntInvocation(BaseInvocation):
|
class RandomIntInvocation(BaseInvocation):
|
||||||
"""Outputs a single random integer."""
|
"""Outputs a single random integer."""
|
||||||
|
|
||||||
type: Literal["rand_int"] = "rand_int"
|
|
||||||
|
|
||||||
# Inputs
|
|
||||||
low: int = InputField(default=0, description="The inclusive low value")
|
low: int = InputField(default=0, description="The inclusive low value")
|
||||||
high: int = InputField(default=np.iinfo(np.int32).max, description="The exclusive high value")
|
high: int = InputField(default=np.iinfo(np.int32).max, description="The exclusive high value")
|
||||||
|
|
||||||
|
@ -1,4 +1,4 @@
|
|||||||
from typing import Literal, Optional
|
from typing import Optional
|
||||||
|
|
||||||
from pydantic import Field
|
from pydantic import Field
|
||||||
|
|
||||||
@ -8,8 +8,8 @@ from invokeai.app.invocations.baseinvocation import (
|
|||||||
InputField,
|
InputField,
|
||||||
InvocationContext,
|
InvocationContext,
|
||||||
OutputField,
|
OutputField,
|
||||||
tags,
|
invocation,
|
||||||
title,
|
invocation_output,
|
||||||
)
|
)
|
||||||
from invokeai.app.invocations.controlnet_image_processors import ControlField
|
from invokeai.app.invocations.controlnet_image_processors import ControlField
|
||||||
from invokeai.app.invocations.model import LoRAModelField, MainModelField, VAEModelField
|
from invokeai.app.invocations.model import LoRAModelField, MainModelField, VAEModelField
|
||||||
@ -91,21 +91,17 @@ class ImageMetadata(BaseModelExcludeNull):
|
|||||||
graph: Optional[dict] = Field(default=None, description="The graph that created the image")
|
graph: Optional[dict] = Field(default=None, description="The graph that created the image")
|
||||||
|
|
||||||
|
|
||||||
|
@invocation_output("metadata_accumulator_output")
|
||||||
class MetadataAccumulatorOutput(BaseInvocationOutput):
|
class MetadataAccumulatorOutput(BaseInvocationOutput):
|
||||||
"""The output of the MetadataAccumulator node"""
|
"""The output of the MetadataAccumulator node"""
|
||||||
|
|
||||||
type: Literal["metadata_accumulator_output"] = "metadata_accumulator_output"
|
|
||||||
|
|
||||||
metadata: CoreMetadata = OutputField(description="The core metadata for the image")
|
metadata: CoreMetadata = OutputField(description="The core metadata for the image")
|
||||||
|
|
||||||
|
|
||||||
@title("Metadata Accumulator")
|
@invocation("metadata_accumulator", title="Metadata Accumulator", tags=["metadata"], category="metadata")
|
||||||
@tags("metadata")
|
|
||||||
class MetadataAccumulatorInvocation(BaseInvocation):
|
class MetadataAccumulatorInvocation(BaseInvocation):
|
||||||
"""Outputs a Core Metadata Object"""
|
"""Outputs a Core Metadata Object"""
|
||||||
|
|
||||||
type: Literal["metadata_accumulator"] = "metadata_accumulator"
|
|
||||||
|
|
||||||
generation_mode: str = InputField(
|
generation_mode: str = InputField(
|
||||||
description="The generation mode that output this image",
|
description="The generation mode that output this image",
|
||||||
)
|
)
|
||||||
|
@ -1,5 +1,5 @@
|
|||||||
import copy
|
import copy
|
||||||
from typing import List, Literal, Optional
|
from typing import List, Optional
|
||||||
|
|
||||||
from pydantic import BaseModel, Field
|
from pydantic import BaseModel, Field
|
||||||
|
|
||||||
@ -13,8 +13,8 @@ from .baseinvocation import (
|
|||||||
InvocationContext,
|
InvocationContext,
|
||||||
OutputField,
|
OutputField,
|
||||||
UIType,
|
UIType,
|
||||||
tags,
|
invocation,
|
||||||
title,
|
invocation_output,
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|
||||||
@ -49,11 +49,10 @@ class VaeField(BaseModel):
|
|||||||
seamless_axes: List[str] = Field(default_factory=list, description='Axes("x" and "y") to which apply seamless')
|
seamless_axes: List[str] = Field(default_factory=list, description='Axes("x" and "y") to which apply seamless')
|
||||||
|
|
||||||
|
|
||||||
|
@invocation_output("model_loader_output")
|
||||||
class ModelLoaderOutput(BaseInvocationOutput):
|
class ModelLoaderOutput(BaseInvocationOutput):
|
||||||
"""Model loader output"""
|
"""Model loader output"""
|
||||||
|
|
||||||
type: Literal["model_loader_output"] = "model_loader_output"
|
|
||||||
|
|
||||||
unet: UNetField = OutputField(description=FieldDescriptions.unet, title="UNet")
|
unet: UNetField = OutputField(description=FieldDescriptions.unet, title="UNet")
|
||||||
clip: ClipField = OutputField(description=FieldDescriptions.clip, title="CLIP")
|
clip: ClipField = OutputField(description=FieldDescriptions.clip, title="CLIP")
|
||||||
vae: VaeField = OutputField(description=FieldDescriptions.vae, title="VAE")
|
vae: VaeField = OutputField(description=FieldDescriptions.vae, title="VAE")
|
||||||
@ -74,14 +73,10 @@ class LoRAModelField(BaseModel):
|
|||||||
base_model: BaseModelType = Field(description="Base model")
|
base_model: BaseModelType = Field(description="Base model")
|
||||||
|
|
||||||
|
|
||||||
@title("Main Model")
|
@invocation("main_model_loader", title="Main Model", tags=["model"], category="model")
|
||||||
@tags("model")
|
|
||||||
class MainModelLoaderInvocation(BaseInvocation):
|
class MainModelLoaderInvocation(BaseInvocation):
|
||||||
"""Loads a main model, outputting its submodels."""
|
"""Loads a main model, outputting its submodels."""
|
||||||
|
|
||||||
type: Literal["main_model_loader"] = "main_model_loader"
|
|
||||||
|
|
||||||
# Inputs
|
|
||||||
model: MainModelField = InputField(description=FieldDescriptions.main_model, input=Input.Direct)
|
model: MainModelField = InputField(description=FieldDescriptions.main_model, input=Input.Direct)
|
||||||
# TODO: precision?
|
# TODO: precision?
|
||||||
|
|
||||||
@ -170,25 +165,18 @@ class MainModelLoaderInvocation(BaseInvocation):
|
|||||||
)
|
)
|
||||||
|
|
||||||
|
|
||||||
|
@invocation_output("lora_loader_output")
|
||||||
class LoraLoaderOutput(BaseInvocationOutput):
|
class LoraLoaderOutput(BaseInvocationOutput):
|
||||||
"""Model loader output"""
|
"""Model loader output"""
|
||||||
|
|
||||||
# fmt: off
|
|
||||||
type: Literal["lora_loader_output"] = "lora_loader_output"
|
|
||||||
|
|
||||||
unet: Optional[UNetField] = OutputField(default=None, description=FieldDescriptions.unet, title="UNet")
|
unet: Optional[UNetField] = OutputField(default=None, description=FieldDescriptions.unet, title="UNet")
|
||||||
clip: Optional[ClipField] = OutputField(default=None, description=FieldDescriptions.clip, title="CLIP")
|
clip: Optional[ClipField] = OutputField(default=None, description=FieldDescriptions.clip, title="CLIP")
|
||||||
# fmt: on
|
|
||||||
|
|
||||||
|
|
||||||
@title("LoRA")
|
@invocation("lora_loader", title="LoRA", tags=["model"], category="model")
|
||||||
@tags("lora", "model")
|
|
||||||
class LoraLoaderInvocation(BaseInvocation):
|
class LoraLoaderInvocation(BaseInvocation):
|
||||||
"""Apply selected lora to unet and text_encoder."""
|
"""Apply selected lora to unet and text_encoder."""
|
||||||
|
|
||||||
type: Literal["lora_loader"] = "lora_loader"
|
|
||||||
|
|
||||||
# Inputs
|
|
||||||
lora: LoRAModelField = InputField(description=FieldDescriptions.lora_model, input=Input.Direct, title="LoRA")
|
lora: LoRAModelField = InputField(description=FieldDescriptions.lora_model, input=Input.Direct, title="LoRA")
|
||||||
weight: float = InputField(default=0.75, description=FieldDescriptions.lora_weight)
|
weight: float = InputField(default=0.75, description=FieldDescriptions.lora_weight)
|
||||||
unet: Optional[UNetField] = InputField(
|
unet: Optional[UNetField] = InputField(
|
||||||
@ -247,25 +235,19 @@ class LoraLoaderInvocation(BaseInvocation):
|
|||||||
return output
|
return output
|
||||||
|
|
||||||
|
|
||||||
|
@invocation_output("sdxl_lora_loader_output")
|
||||||
class SDXLLoraLoaderOutput(BaseInvocationOutput):
|
class SDXLLoraLoaderOutput(BaseInvocationOutput):
|
||||||
"""SDXL LoRA Loader Output"""
|
"""SDXL LoRA Loader Output"""
|
||||||
|
|
||||||
# fmt: off
|
|
||||||
type: Literal["sdxl_lora_loader_output"] = "sdxl_lora_loader_output"
|
|
||||||
|
|
||||||
unet: Optional[UNetField] = OutputField(default=None, description=FieldDescriptions.unet, title="UNet")
|
unet: Optional[UNetField] = OutputField(default=None, description=FieldDescriptions.unet, title="UNet")
|
||||||
clip: Optional[ClipField] = OutputField(default=None, description=FieldDescriptions.clip, title="CLIP 1")
|
clip: Optional[ClipField] = OutputField(default=None, description=FieldDescriptions.clip, title="CLIP 1")
|
||||||
clip2: Optional[ClipField] = OutputField(default=None, description=FieldDescriptions.clip, title="CLIP 2")
|
clip2: Optional[ClipField] = OutputField(default=None, description=FieldDescriptions.clip, title="CLIP 2")
|
||||||
# fmt: on
|
|
||||||
|
|
||||||
|
|
||||||
@title("SDXL LoRA")
|
@invocation("sdxl_lora_loader", title="SDXL LoRA", tags=["lora", "model"], category="model")
|
||||||
@tags("sdxl", "lora", "model")
|
|
||||||
class SDXLLoraLoaderInvocation(BaseInvocation):
|
class SDXLLoraLoaderInvocation(BaseInvocation):
|
||||||
"""Apply selected lora to unet and text_encoder."""
|
"""Apply selected lora to unet and text_encoder."""
|
||||||
|
|
||||||
type: Literal["sdxl_lora_loader"] = "sdxl_lora_loader"
|
|
||||||
|
|
||||||
lora: LoRAModelField = InputField(description=FieldDescriptions.lora_model, input=Input.Direct, title="LoRA")
|
lora: LoRAModelField = InputField(description=FieldDescriptions.lora_model, input=Input.Direct, title="LoRA")
|
||||||
weight: float = Field(default=0.75, description=FieldDescriptions.lora_weight)
|
weight: float = Field(default=0.75, description=FieldDescriptions.lora_weight)
|
||||||
unet: Optional[UNetField] = Field(
|
unet: Optional[UNetField] = Field(
|
||||||
@ -349,23 +331,17 @@ class VAEModelField(BaseModel):
|
|||||||
base_model: BaseModelType = Field(description="Base model")
|
base_model: BaseModelType = Field(description="Base model")
|
||||||
|
|
||||||
|
|
||||||
|
@invocation_output("vae_loader_output")
|
||||||
class VaeLoaderOutput(BaseInvocationOutput):
|
class VaeLoaderOutput(BaseInvocationOutput):
|
||||||
"""Model loader output"""
|
"""VAE output"""
|
||||||
|
|
||||||
type: Literal["vae_loader_output"] = "vae_loader_output"
|
|
||||||
|
|
||||||
# Outputs
|
|
||||||
vae: VaeField = OutputField(description=FieldDescriptions.vae, title="VAE")
|
vae: VaeField = OutputField(description=FieldDescriptions.vae, title="VAE")
|
||||||
|
|
||||||
|
|
||||||
@title("VAE")
|
@invocation("vae_loader", title="VAE", tags=["vae", "model"], category="model")
|
||||||
@tags("vae", "model")
|
|
||||||
class VaeLoaderInvocation(BaseInvocation):
|
class VaeLoaderInvocation(BaseInvocation):
|
||||||
"""Loads a VAE model, outputting a VaeLoaderOutput"""
|
"""Loads a VAE model, outputting a VaeLoaderOutput"""
|
||||||
|
|
||||||
type: Literal["vae_loader"] = "vae_loader"
|
|
||||||
|
|
||||||
# Inputs
|
|
||||||
vae_model: VAEModelField = InputField(
|
vae_model: VAEModelField = InputField(
|
||||||
description=FieldDescriptions.vae_model, input=Input.Direct, ui_type=UIType.VaeModel, title="VAE"
|
description=FieldDescriptions.vae_model, input=Input.Direct, ui_type=UIType.VaeModel, title="VAE"
|
||||||
)
|
)
|
||||||
@ -392,24 +368,18 @@ class VaeLoaderInvocation(BaseInvocation):
|
|||||||
)
|
)
|
||||||
|
|
||||||
|
|
||||||
|
@invocation_output("seamless_output")
|
||||||
class SeamlessModeOutput(BaseInvocationOutput):
|
class SeamlessModeOutput(BaseInvocationOutput):
|
||||||
"""Modified Seamless Model output"""
|
"""Modified Seamless Model output"""
|
||||||
|
|
||||||
type: Literal["seamless_output"] = "seamless_output"
|
|
||||||
|
|
||||||
# Outputs
|
|
||||||
unet: Optional[UNetField] = OutputField(description=FieldDescriptions.unet, title="UNet")
|
unet: Optional[UNetField] = OutputField(description=FieldDescriptions.unet, title="UNet")
|
||||||
vae: Optional[VaeField] = OutputField(description=FieldDescriptions.vae, title="VAE")
|
vae: Optional[VaeField] = OutputField(description=FieldDescriptions.vae, title="VAE")
|
||||||
|
|
||||||
|
|
||||||
@title("Seamless")
|
@invocation("seamless", title="Seamless", tags=["seamless", "model"], category="model")
|
||||||
@tags("seamless", "model")
|
|
||||||
class SeamlessModeInvocation(BaseInvocation):
|
class SeamlessModeInvocation(BaseInvocation):
|
||||||
"""Applies the seamless transformation to the Model UNet and VAE."""
|
"""Applies the seamless transformation to the Model UNet and VAE."""
|
||||||
|
|
||||||
type: Literal["seamless"] = "seamless"
|
|
||||||
|
|
||||||
# Inputs
|
|
||||||
unet: Optional[UNetField] = InputField(
|
unet: Optional[UNetField] = InputField(
|
||||||
default=None, description=FieldDescriptions.unet, input=Input.Connection, title="UNet"
|
default=None, description=FieldDescriptions.unet, input=Input.Connection, title="UNet"
|
||||||
)
|
)
|
||||||
|
@ -1,6 +1,5 @@
|
|||||||
# Copyright (c) 2023 Kyle Schouviller (https://github.com/kyle0654) & the InvokeAI Team
|
# Copyright (c) 2023 Kyle Schouviller (https://github.com/kyle0654) & the InvokeAI Team
|
||||||
|
|
||||||
from typing import Literal
|
|
||||||
|
|
||||||
import torch
|
import torch
|
||||||
from pydantic import validator
|
from pydantic import validator
|
||||||
@ -16,8 +15,8 @@ from .baseinvocation import (
|
|||||||
InputField,
|
InputField,
|
||||||
InvocationContext,
|
InvocationContext,
|
||||||
OutputField,
|
OutputField,
|
||||||
tags,
|
invocation,
|
||||||
title,
|
invocation_output,
|
||||||
)
|
)
|
||||||
|
|
||||||
"""
|
"""
|
||||||
@ -62,12 +61,10 @@ Nodes
|
|||||||
"""
|
"""
|
||||||
|
|
||||||
|
|
||||||
|
@invocation_output("noise_output")
|
||||||
class NoiseOutput(BaseInvocationOutput):
|
class NoiseOutput(BaseInvocationOutput):
|
||||||
"""Invocation noise output"""
|
"""Invocation noise output"""
|
||||||
|
|
||||||
type: Literal["noise_output"] = "noise_output"
|
|
||||||
|
|
||||||
# Inputs
|
|
||||||
noise: LatentsField = OutputField(default=None, description=FieldDescriptions.noise)
|
noise: LatentsField = OutputField(default=None, description=FieldDescriptions.noise)
|
||||||
width: int = OutputField(description=FieldDescriptions.width)
|
width: int = OutputField(description=FieldDescriptions.width)
|
||||||
height: int = OutputField(description=FieldDescriptions.height)
|
height: int = OutputField(description=FieldDescriptions.height)
|
||||||
@ -81,14 +78,10 @@ def build_noise_output(latents_name: str, latents: torch.Tensor, seed: int):
|
|||||||
)
|
)
|
||||||
|
|
||||||
|
|
||||||
@title("Noise")
|
@invocation("noise", title="Noise", tags=["latents", "noise"], category="latents")
|
||||||
@tags("latents", "noise")
|
|
||||||
class NoiseInvocation(BaseInvocation):
|
class NoiseInvocation(BaseInvocation):
|
||||||
"""Generates latent noise."""
|
"""Generates latent noise."""
|
||||||
|
|
||||||
type: Literal["noise"] = "noise"
|
|
||||||
|
|
||||||
# Inputs
|
|
||||||
seed: int = InputField(
|
seed: int = InputField(
|
||||||
ge=0,
|
ge=0,
|
||||||
le=SEED_MAX,
|
le=SEED_MAX,
|
||||||
|
@ -31,8 +31,8 @@ from .baseinvocation import (
|
|||||||
OutputField,
|
OutputField,
|
||||||
UIComponent,
|
UIComponent,
|
||||||
UIType,
|
UIType,
|
||||||
tags,
|
invocation,
|
||||||
title,
|
invocation_output,
|
||||||
)
|
)
|
||||||
from .controlnet_image_processors import ControlField
|
from .controlnet_image_processors import ControlField
|
||||||
from .latent import SAMPLER_NAME_VALUES, LatentsField, LatentsOutput, build_latents_output, get_scheduler
|
from .latent import SAMPLER_NAME_VALUES, LatentsField, LatentsOutput, build_latents_output, get_scheduler
|
||||||
@ -56,11 +56,8 @@ ORT_TO_NP_TYPE = {
|
|||||||
PRECISION_VALUES = Literal[tuple(list(ORT_TO_NP_TYPE.keys()))]
|
PRECISION_VALUES = Literal[tuple(list(ORT_TO_NP_TYPE.keys()))]
|
||||||
|
|
||||||
|
|
||||||
@title("ONNX Prompt (Raw)")
|
@invocation("prompt_onnx", title="ONNX Prompt (Raw)", tags=["prompt", "onnx"], category="conditioning")
|
||||||
@tags("onnx", "prompt")
|
|
||||||
class ONNXPromptInvocation(BaseInvocation):
|
class ONNXPromptInvocation(BaseInvocation):
|
||||||
type: Literal["prompt_onnx"] = "prompt_onnx"
|
|
||||||
|
|
||||||
prompt: str = InputField(default="", description=FieldDescriptions.raw_prompt, ui_component=UIComponent.Textarea)
|
prompt: str = InputField(default="", description=FieldDescriptions.raw_prompt, ui_component=UIComponent.Textarea)
|
||||||
clip: ClipField = InputField(description=FieldDescriptions.clip, input=Input.Connection)
|
clip: ClipField = InputField(description=FieldDescriptions.clip, input=Input.Connection)
|
||||||
|
|
||||||
@ -141,14 +138,15 @@ class ONNXPromptInvocation(BaseInvocation):
|
|||||||
|
|
||||||
|
|
||||||
# Text to image
|
# Text to image
|
||||||
@title("ONNX Text to Latents")
|
@invocation(
|
||||||
@tags("latents", "inference", "txt2img", "onnx")
|
"t2l_onnx",
|
||||||
|
title="ONNX Text to Latents",
|
||||||
|
tags=["latents", "inference", "txt2img", "onnx"],
|
||||||
|
category="latents",
|
||||||
|
)
|
||||||
class ONNXTextToLatentsInvocation(BaseInvocation):
|
class ONNXTextToLatentsInvocation(BaseInvocation):
|
||||||
"""Generates latents from conditionings."""
|
"""Generates latents from conditionings."""
|
||||||
|
|
||||||
type: Literal["t2l_onnx"] = "t2l_onnx"
|
|
||||||
|
|
||||||
# Inputs
|
|
||||||
positive_conditioning: ConditioningField = InputField(
|
positive_conditioning: ConditioningField = InputField(
|
||||||
description=FieldDescriptions.positive_cond,
|
description=FieldDescriptions.positive_cond,
|
||||||
input=Input.Connection,
|
input=Input.Connection,
|
||||||
@ -316,14 +314,15 @@ class ONNXTextToLatentsInvocation(BaseInvocation):
|
|||||||
|
|
||||||
|
|
||||||
# Latent to image
|
# Latent to image
|
||||||
@title("ONNX Latents to Image")
|
@invocation(
|
||||||
@tags("latents", "image", "vae", "onnx")
|
"l2i_onnx",
|
||||||
|
title="ONNX Latents to Image",
|
||||||
|
tags=["latents", "image", "vae", "onnx"],
|
||||||
|
category="image",
|
||||||
|
)
|
||||||
class ONNXLatentsToImageInvocation(BaseInvocation):
|
class ONNXLatentsToImageInvocation(BaseInvocation):
|
||||||
"""Generates an image from latents."""
|
"""Generates an image from latents."""
|
||||||
|
|
||||||
type: Literal["l2i_onnx"] = "l2i_onnx"
|
|
||||||
|
|
||||||
# Inputs
|
|
||||||
latents: LatentsField = InputField(
|
latents: LatentsField = InputField(
|
||||||
description=FieldDescriptions.denoised_latents,
|
description=FieldDescriptions.denoised_latents,
|
||||||
input=Input.Connection,
|
input=Input.Connection,
|
||||||
@ -386,17 +385,14 @@ class ONNXLatentsToImageInvocation(BaseInvocation):
|
|||||||
)
|
)
|
||||||
|
|
||||||
|
|
||||||
|
@invocation_output("model_loader_output_onnx")
|
||||||
class ONNXModelLoaderOutput(BaseInvocationOutput):
|
class ONNXModelLoaderOutput(BaseInvocationOutput):
|
||||||
"""Model loader output"""
|
"""Model loader output"""
|
||||||
|
|
||||||
# fmt: off
|
|
||||||
type: Literal["model_loader_output_onnx"] = "model_loader_output_onnx"
|
|
||||||
|
|
||||||
unet: UNetField = OutputField(default=None, description=FieldDescriptions.unet, title="UNet")
|
unet: UNetField = OutputField(default=None, description=FieldDescriptions.unet, title="UNet")
|
||||||
clip: ClipField = OutputField(default=None, description=FieldDescriptions.clip, title="CLIP")
|
clip: ClipField = OutputField(default=None, description=FieldDescriptions.clip, title="CLIP")
|
||||||
vae_decoder: VaeField = OutputField(default=None, description=FieldDescriptions.vae, title="VAE Decoder")
|
vae_decoder: VaeField = OutputField(default=None, description=FieldDescriptions.vae, title="VAE Decoder")
|
||||||
vae_encoder: VaeField = OutputField(default=None, description=FieldDescriptions.vae, title="VAE Encoder")
|
vae_encoder: VaeField = OutputField(default=None, description=FieldDescriptions.vae, title="VAE Encoder")
|
||||||
# fmt: on
|
|
||||||
|
|
||||||
|
|
||||||
class OnnxModelField(BaseModel):
|
class OnnxModelField(BaseModel):
|
||||||
@ -407,14 +403,10 @@ class OnnxModelField(BaseModel):
|
|||||||
model_type: ModelType = Field(description="Model Type")
|
model_type: ModelType = Field(description="Model Type")
|
||||||
|
|
||||||
|
|
||||||
@title("ONNX Main Model")
|
@invocation("onnx_model_loader", title="ONNX Main Model", tags=["onnx", "model"], category="model")
|
||||||
@tags("onnx", "model")
|
|
||||||
class OnnxModelLoaderInvocation(BaseInvocation):
|
class OnnxModelLoaderInvocation(BaseInvocation):
|
||||||
"""Loads a main model, outputting its submodels."""
|
"""Loads a main model, outputting its submodels."""
|
||||||
|
|
||||||
type: Literal["onnx_model_loader"] = "onnx_model_loader"
|
|
||||||
|
|
||||||
# Inputs
|
|
||||||
model: OnnxModelField = InputField(
|
model: OnnxModelField = InputField(
|
||||||
description=FieldDescriptions.onnx_main_model, input=Input.Direct, ui_type=UIType.ONNXModel
|
description=FieldDescriptions.onnx_main_model, input=Input.Direct, ui_type=UIType.ONNXModel
|
||||||
)
|
)
|
||||||
|
@ -42,17 +42,13 @@ from matplotlib.ticker import MaxNLocator
|
|||||||
|
|
||||||
from invokeai.app.invocations.primitives import FloatCollectionOutput
|
from invokeai.app.invocations.primitives import FloatCollectionOutput
|
||||||
|
|
||||||
from .baseinvocation import BaseInvocation, InputField, InvocationContext, tags, title
|
from .baseinvocation import BaseInvocation, InputField, InvocationContext, invocation
|
||||||
|
|
||||||
|
|
||||||
@title("Float Range")
|
@invocation("float_range", title="Float Range", tags=["math", "range"], category="math")
|
||||||
@tags("math", "range")
|
|
||||||
class FloatLinearRangeInvocation(BaseInvocation):
|
class FloatLinearRangeInvocation(BaseInvocation):
|
||||||
"""Creates a range"""
|
"""Creates a range"""
|
||||||
|
|
||||||
type: Literal["float_range"] = "float_range"
|
|
||||||
|
|
||||||
# Inputs
|
|
||||||
start: float = InputField(default=5, description="The first value of the range")
|
start: float = InputField(default=5, description="The first value of the range")
|
||||||
stop: float = InputField(default=10, description="The last value of the range")
|
stop: float = InputField(default=10, description="The last value of the range")
|
||||||
steps: int = InputField(default=30, description="number of values to interpolate over (including start and stop)")
|
steps: int = InputField(default=30, description="number of values to interpolate over (including start and stop)")
|
||||||
@ -100,14 +96,10 @@ EASING_FUNCTION_KEYS = Literal[tuple(list(EASING_FUNCTIONS_MAP.keys()))]
|
|||||||
|
|
||||||
|
|
||||||
# actually I think for now could just use CollectionOutput (which is list[Any]
|
# actually I think for now could just use CollectionOutput (which is list[Any]
|
||||||
@title("Step Param Easing")
|
@invocation("step_param_easing", title="Step Param Easing", tags=["step", "easing"], category="step")
|
||||||
@tags("step", "easing")
|
|
||||||
class StepParamEasingInvocation(BaseInvocation):
|
class StepParamEasingInvocation(BaseInvocation):
|
||||||
"""Experimental per-step parameter easing for denoising steps"""
|
"""Experimental per-step parameter easing for denoising steps"""
|
||||||
|
|
||||||
type: Literal["step_param_easing"] = "step_param_easing"
|
|
||||||
|
|
||||||
# Inputs
|
|
||||||
easing: EASING_FUNCTION_KEYS = InputField(default="Linear", description="The easing function to use")
|
easing: EASING_FUNCTION_KEYS = InputField(default="Linear", description="The easing function to use")
|
||||||
num_steps: int = InputField(default=20, description="number of denoising steps")
|
num_steps: int = InputField(default=20, description="number of denoising steps")
|
||||||
start_value: float = InputField(default=0.0, description="easing starting value")
|
start_value: float = InputField(default=0.0, description="easing starting value")
|
||||||
|
@ -1,6 +1,6 @@
|
|||||||
# Copyright (c) 2023 Kyle Schouviller (https://github.com/kyle0654)
|
# Copyright (c) 2023 Kyle Schouviller (https://github.com/kyle0654)
|
||||||
|
|
||||||
from typing import Literal, Optional, Tuple
|
from typing import Optional, Tuple
|
||||||
|
|
||||||
import torch
|
import torch
|
||||||
from pydantic import BaseModel, Field
|
from pydantic import BaseModel, Field
|
||||||
@ -15,8 +15,8 @@ from .baseinvocation import (
|
|||||||
OutputField,
|
OutputField,
|
||||||
UIComponent,
|
UIComponent,
|
||||||
UIType,
|
UIType,
|
||||||
tags,
|
invocation,
|
||||||
title,
|
invocation_output,
|
||||||
)
|
)
|
||||||
|
|
||||||
"""
|
"""
|
||||||
@ -29,44 +29,39 @@ Primitives: Boolean, Integer, Float, String, Image, Latents, Conditioning, Color
|
|||||||
# region Boolean
|
# region Boolean
|
||||||
|
|
||||||
|
|
||||||
|
@invocation_output("boolean_output")
|
||||||
class BooleanOutput(BaseInvocationOutput):
|
class BooleanOutput(BaseInvocationOutput):
|
||||||
"""Base class for nodes that output a single boolean"""
|
"""Base class for nodes that output a single boolean"""
|
||||||
|
|
||||||
type: Literal["boolean_output"] = "boolean_output"
|
|
||||||
value: bool = OutputField(description="The output boolean")
|
value: bool = OutputField(description="The output boolean")
|
||||||
|
|
||||||
|
|
||||||
|
@invocation_output("boolean_collection_output")
|
||||||
class BooleanCollectionOutput(BaseInvocationOutput):
|
class BooleanCollectionOutput(BaseInvocationOutput):
|
||||||
"""Base class for nodes that output a collection of booleans"""
|
"""Base class for nodes that output a collection of booleans"""
|
||||||
|
|
||||||
type: Literal["boolean_collection_output"] = "boolean_collection_output"
|
|
||||||
|
|
||||||
# Outputs
|
|
||||||
collection: list[bool] = OutputField(description="The output boolean collection", ui_type=UIType.BooleanCollection)
|
collection: list[bool] = OutputField(description="The output boolean collection", ui_type=UIType.BooleanCollection)
|
||||||
|
|
||||||
|
|
||||||
@title("Boolean Primitive")
|
@invocation("boolean", title="Boolean Primitive", tags=["primitives", "boolean"], category="primitives")
|
||||||
@tags("primitives", "boolean")
|
|
||||||
class BooleanInvocation(BaseInvocation):
|
class BooleanInvocation(BaseInvocation):
|
||||||
"""A boolean primitive value"""
|
"""A boolean primitive value"""
|
||||||
|
|
||||||
type: Literal["boolean"] = "boolean"
|
|
||||||
|
|
||||||
# Inputs
|
|
||||||
value: bool = InputField(default=False, description="The boolean value")
|
value: bool = InputField(default=False, description="The boolean value")
|
||||||
|
|
||||||
def invoke(self, context: InvocationContext) -> BooleanOutput:
|
def invoke(self, context: InvocationContext) -> BooleanOutput:
|
||||||
return BooleanOutput(value=self.value)
|
return BooleanOutput(value=self.value)
|
||||||
|
|
||||||
|
|
||||||
@title("Boolean Primitive Collection")
|
@invocation(
|
||||||
@tags("primitives", "boolean", "collection")
|
"boolean_collection",
|
||||||
|
title="Boolean Collection Primitive",
|
||||||
|
tags=["primitives", "boolean", "collection"],
|
||||||
|
category="primitives",
|
||||||
|
)
|
||||||
class BooleanCollectionInvocation(BaseInvocation):
|
class BooleanCollectionInvocation(BaseInvocation):
|
||||||
"""A collection of boolean primitive values"""
|
"""A collection of boolean primitive values"""
|
||||||
|
|
||||||
type: Literal["boolean_collection"] = "boolean_collection"
|
|
||||||
|
|
||||||
# Inputs
|
|
||||||
collection: list[bool] = InputField(
|
collection: list[bool] = InputField(
|
||||||
default_factory=list, description="The collection of boolean values", ui_type=UIType.BooleanCollection
|
default_factory=list, description="The collection of boolean values", ui_type=UIType.BooleanCollection
|
||||||
)
|
)
|
||||||
@ -80,44 +75,39 @@ class BooleanCollectionInvocation(BaseInvocation):
|
|||||||
# region Integer
|
# region Integer
|
||||||
|
|
||||||
|
|
||||||
|
@invocation_output("integer_output")
|
||||||
class IntegerOutput(BaseInvocationOutput):
|
class IntegerOutput(BaseInvocationOutput):
|
||||||
"""Base class for nodes that output a single integer"""
|
"""Base class for nodes that output a single integer"""
|
||||||
|
|
||||||
type: Literal["integer_output"] = "integer_output"
|
|
||||||
value: int = OutputField(description="The output integer")
|
value: int = OutputField(description="The output integer")
|
||||||
|
|
||||||
|
|
||||||
|
@invocation_output("integer_collection_output")
|
||||||
class IntegerCollectionOutput(BaseInvocationOutput):
|
class IntegerCollectionOutput(BaseInvocationOutput):
|
||||||
"""Base class for nodes that output a collection of integers"""
|
"""Base class for nodes that output a collection of integers"""
|
||||||
|
|
||||||
type: Literal["integer_collection_output"] = "integer_collection_output"
|
|
||||||
|
|
||||||
# Outputs
|
|
||||||
collection: list[int] = OutputField(description="The int collection", ui_type=UIType.IntegerCollection)
|
collection: list[int] = OutputField(description="The int collection", ui_type=UIType.IntegerCollection)
|
||||||
|
|
||||||
|
|
||||||
@title("Integer Primitive")
|
@invocation("integer", title="Integer Primitive", tags=["primitives", "integer"], category="primitives")
|
||||||
@tags("primitives", "integer")
|
|
||||||
class IntegerInvocation(BaseInvocation):
|
class IntegerInvocation(BaseInvocation):
|
||||||
"""An integer primitive value"""
|
"""An integer primitive value"""
|
||||||
|
|
||||||
type: Literal["integer"] = "integer"
|
|
||||||
|
|
||||||
# Inputs
|
|
||||||
value: int = InputField(default=0, description="The integer value")
|
value: int = InputField(default=0, description="The integer value")
|
||||||
|
|
||||||
def invoke(self, context: InvocationContext) -> IntegerOutput:
|
def invoke(self, context: InvocationContext) -> IntegerOutput:
|
||||||
return IntegerOutput(value=self.value)
|
return IntegerOutput(value=self.value)
|
||||||
|
|
||||||
|
|
||||||
@title("Integer Primitive Collection")
|
@invocation(
|
||||||
@tags("primitives", "integer", "collection")
|
"integer_collection",
|
||||||
|
title="Integer Collection Primitive",
|
||||||
|
tags=["primitives", "integer", "collection"],
|
||||||
|
category="primitives",
|
||||||
|
)
|
||||||
class IntegerCollectionInvocation(BaseInvocation):
|
class IntegerCollectionInvocation(BaseInvocation):
|
||||||
"""A collection of integer primitive values"""
|
"""A collection of integer primitive values"""
|
||||||
|
|
||||||
type: Literal["integer_collection"] = "integer_collection"
|
|
||||||
|
|
||||||
# Inputs
|
|
||||||
collection: list[int] = InputField(
|
collection: list[int] = InputField(
|
||||||
default=0, description="The collection of integer values", ui_type=UIType.IntegerCollection
|
default=0, description="The collection of integer values", ui_type=UIType.IntegerCollection
|
||||||
)
|
)
|
||||||
@ -131,44 +121,39 @@ class IntegerCollectionInvocation(BaseInvocation):
|
|||||||
# region Float
|
# region Float
|
||||||
|
|
||||||
|
|
||||||
|
@invocation_output("float_output")
|
||||||
class FloatOutput(BaseInvocationOutput):
|
class FloatOutput(BaseInvocationOutput):
|
||||||
"""Base class for nodes that output a single float"""
|
"""Base class for nodes that output a single float"""
|
||||||
|
|
||||||
type: Literal["float_output"] = "float_output"
|
|
||||||
value: float = OutputField(description="The output float")
|
value: float = OutputField(description="The output float")
|
||||||
|
|
||||||
|
|
||||||
|
@invocation_output("float_collection_output")
|
||||||
class FloatCollectionOutput(BaseInvocationOutput):
|
class FloatCollectionOutput(BaseInvocationOutput):
|
||||||
"""Base class for nodes that output a collection of floats"""
|
"""Base class for nodes that output a collection of floats"""
|
||||||
|
|
||||||
type: Literal["float_collection_output"] = "float_collection_output"
|
|
||||||
|
|
||||||
# Outputs
|
|
||||||
collection: list[float] = OutputField(description="The float collection", ui_type=UIType.FloatCollection)
|
collection: list[float] = OutputField(description="The float collection", ui_type=UIType.FloatCollection)
|
||||||
|
|
||||||
|
|
||||||
@title("Float Primitive")
|
@invocation("float", title="Float Primitive", tags=["primitives", "float"], category="primitives")
|
||||||
@tags("primitives", "float")
|
|
||||||
class FloatInvocation(BaseInvocation):
|
class FloatInvocation(BaseInvocation):
|
||||||
"""A float primitive value"""
|
"""A float primitive value"""
|
||||||
|
|
||||||
type: Literal["float"] = "float"
|
|
||||||
|
|
||||||
# Inputs
|
|
||||||
value: float = InputField(default=0.0, description="The float value")
|
value: float = InputField(default=0.0, description="The float value")
|
||||||
|
|
||||||
def invoke(self, context: InvocationContext) -> FloatOutput:
|
def invoke(self, context: InvocationContext) -> FloatOutput:
|
||||||
return FloatOutput(value=self.value)
|
return FloatOutput(value=self.value)
|
||||||
|
|
||||||
|
|
||||||
@title("Float Primitive Collection")
|
@invocation(
|
||||||
@tags("primitives", "float", "collection")
|
"float_collection",
|
||||||
|
title="Float Collection Primitive",
|
||||||
|
tags=["primitives", "float", "collection"],
|
||||||
|
category="primitives",
|
||||||
|
)
|
||||||
class FloatCollectionInvocation(BaseInvocation):
|
class FloatCollectionInvocation(BaseInvocation):
|
||||||
"""A collection of float primitive values"""
|
"""A collection of float primitive values"""
|
||||||
|
|
||||||
type: Literal["float_collection"] = "float_collection"
|
|
||||||
|
|
||||||
# Inputs
|
|
||||||
collection: list[float] = InputField(
|
collection: list[float] = InputField(
|
||||||
default_factory=list, description="The collection of float values", ui_type=UIType.FloatCollection
|
default_factory=list, description="The collection of float values", ui_type=UIType.FloatCollection
|
||||||
)
|
)
|
||||||
@ -182,44 +167,39 @@ class FloatCollectionInvocation(BaseInvocation):
|
|||||||
# region String
|
# region String
|
||||||
|
|
||||||
|
|
||||||
|
@invocation_output("string_output")
|
||||||
class StringOutput(BaseInvocationOutput):
|
class StringOutput(BaseInvocationOutput):
|
||||||
"""Base class for nodes that output a single string"""
|
"""Base class for nodes that output a single string"""
|
||||||
|
|
||||||
type: Literal["string_output"] = "string_output"
|
|
||||||
value: str = OutputField(description="The output string")
|
value: str = OutputField(description="The output string")
|
||||||
|
|
||||||
|
|
||||||
|
@invocation_output("string_collection_output")
|
||||||
class StringCollectionOutput(BaseInvocationOutput):
|
class StringCollectionOutput(BaseInvocationOutput):
|
||||||
"""Base class for nodes that output a collection of strings"""
|
"""Base class for nodes that output a collection of strings"""
|
||||||
|
|
||||||
type: Literal["string_collection_output"] = "string_collection_output"
|
|
||||||
|
|
||||||
# Outputs
|
|
||||||
collection: list[str] = OutputField(description="The output strings", ui_type=UIType.StringCollection)
|
collection: list[str] = OutputField(description="The output strings", ui_type=UIType.StringCollection)
|
||||||
|
|
||||||
|
|
||||||
@title("String Primitive")
|
@invocation("string", title="String Primitive", tags=["primitives", "string"], category="primitives")
|
||||||
@tags("primitives", "string")
|
|
||||||
class StringInvocation(BaseInvocation):
|
class StringInvocation(BaseInvocation):
|
||||||
"""A string primitive value"""
|
"""A string primitive value"""
|
||||||
|
|
||||||
type: Literal["string"] = "string"
|
|
||||||
|
|
||||||
# Inputs
|
|
||||||
value: str = InputField(default="", description="The string value", ui_component=UIComponent.Textarea)
|
value: str = InputField(default="", description="The string value", ui_component=UIComponent.Textarea)
|
||||||
|
|
||||||
def invoke(self, context: InvocationContext) -> StringOutput:
|
def invoke(self, context: InvocationContext) -> StringOutput:
|
||||||
return StringOutput(value=self.value)
|
return StringOutput(value=self.value)
|
||||||
|
|
||||||
|
|
||||||
@title("String Primitive Collection")
|
@invocation(
|
||||||
@tags("primitives", "string", "collection")
|
"string_collection",
|
||||||
|
title="String Collection Primitive",
|
||||||
|
tags=["primitives", "string", "collection"],
|
||||||
|
category="primitives",
|
||||||
|
)
|
||||||
class StringCollectionInvocation(BaseInvocation):
|
class StringCollectionInvocation(BaseInvocation):
|
||||||
"""A collection of string primitive values"""
|
"""A collection of string primitive values"""
|
||||||
|
|
||||||
type: Literal["string_collection"] = "string_collection"
|
|
||||||
|
|
||||||
# Inputs
|
|
||||||
collection: list[str] = InputField(
|
collection: list[str] = InputField(
|
||||||
default_factory=list, description="The collection of string values", ui_type=UIType.StringCollection
|
default_factory=list, description="The collection of string values", ui_type=UIType.StringCollection
|
||||||
)
|
)
|
||||||
@ -239,33 +219,26 @@ class ImageField(BaseModel):
|
|||||||
image_name: str = Field(description="The name of the image")
|
image_name: str = Field(description="The name of the image")
|
||||||
|
|
||||||
|
|
||||||
|
@invocation_output("image_output")
|
||||||
class ImageOutput(BaseInvocationOutput):
|
class ImageOutput(BaseInvocationOutput):
|
||||||
"""Base class for nodes that output a single image"""
|
"""Base class for nodes that output a single image"""
|
||||||
|
|
||||||
type: Literal["image_output"] = "image_output"
|
|
||||||
image: ImageField = OutputField(description="The output image")
|
image: ImageField = OutputField(description="The output image")
|
||||||
width: int = OutputField(description="The width of the image in pixels")
|
width: int = OutputField(description="The width of the image in pixels")
|
||||||
height: int = OutputField(description="The height of the image in pixels")
|
height: int = OutputField(description="The height of the image in pixels")
|
||||||
|
|
||||||
|
|
||||||
|
@invocation_output("image_collection_output")
|
||||||
class ImageCollectionOutput(BaseInvocationOutput):
|
class ImageCollectionOutput(BaseInvocationOutput):
|
||||||
"""Base class for nodes that output a collection of images"""
|
"""Base class for nodes that output a collection of images"""
|
||||||
|
|
||||||
type: Literal["image_collection_output"] = "image_collection_output"
|
|
||||||
|
|
||||||
# Outputs
|
|
||||||
collection: list[ImageField] = OutputField(description="The output images", ui_type=UIType.ImageCollection)
|
collection: list[ImageField] = OutputField(description="The output images", ui_type=UIType.ImageCollection)
|
||||||
|
|
||||||
|
|
||||||
@title("Image Primitive")
|
@invocation("image", title="Image Primitive", tags=["primitives", "image"], category="primitives")
|
||||||
@tags("primitives", "image")
|
|
||||||
class ImageInvocation(BaseInvocation):
|
class ImageInvocation(BaseInvocation):
|
||||||
"""An image primitive value"""
|
"""An image primitive value"""
|
||||||
|
|
||||||
# Metadata
|
|
||||||
type: Literal["image"] = "image"
|
|
||||||
|
|
||||||
# Inputs
|
|
||||||
image: ImageField = InputField(description="The image to load")
|
image: ImageField = InputField(description="The image to load")
|
||||||
|
|
||||||
def invoke(self, context: InvocationContext) -> ImageOutput:
|
def invoke(self, context: InvocationContext) -> ImageOutput:
|
||||||
@ -278,14 +251,15 @@ class ImageInvocation(BaseInvocation):
|
|||||||
)
|
)
|
||||||
|
|
||||||
|
|
||||||
@title("Image Primitive Collection")
|
@invocation(
|
||||||
@tags("primitives", "image", "collection")
|
"image_collection",
|
||||||
|
title="Image Collection Primitive",
|
||||||
|
tags=["primitives", "image", "collection"],
|
||||||
|
category="primitives",
|
||||||
|
)
|
||||||
class ImageCollectionInvocation(BaseInvocation):
|
class ImageCollectionInvocation(BaseInvocation):
|
||||||
"""A collection of image primitive values"""
|
"""A collection of image primitive values"""
|
||||||
|
|
||||||
type: Literal["image_collection"] = "image_collection"
|
|
||||||
|
|
||||||
# Inputs
|
|
||||||
collection: list[ImageField] = InputField(
|
collection: list[ImageField] = InputField(
|
||||||
default=0, description="The collection of image values", ui_type=UIType.ImageCollection
|
default=0, description="The collection of image values", ui_type=UIType.ImageCollection
|
||||||
)
|
)
|
||||||
@ -306,10 +280,10 @@ class DenoiseMaskField(BaseModel):
|
|||||||
masked_latents_name: Optional[str] = Field(description="The name of the masked image latents")
|
masked_latents_name: Optional[str] = Field(description="The name of the masked image latents")
|
||||||
|
|
||||||
|
|
||||||
|
@invocation_output("denoise_mask_output")
|
||||||
class DenoiseMaskOutput(BaseInvocationOutput):
|
class DenoiseMaskOutput(BaseInvocationOutput):
|
||||||
"""Base class for nodes that output a single image"""
|
"""Base class for nodes that output a single image"""
|
||||||
|
|
||||||
type: Literal["denoise_mask_output"] = "denoise_mask_output"
|
|
||||||
denoise_mask: DenoiseMaskField = OutputField(description="Mask for denoise model run")
|
denoise_mask: DenoiseMaskField = OutputField(description="Mask for denoise model run")
|
||||||
|
|
||||||
|
|
||||||
@ -325,11 +299,10 @@ class LatentsField(BaseModel):
|
|||||||
seed: Optional[int] = Field(default=None, description="Seed used to generate this latents")
|
seed: Optional[int] = Field(default=None, description="Seed used to generate this latents")
|
||||||
|
|
||||||
|
|
||||||
|
@invocation_output("latents_output")
|
||||||
class LatentsOutput(BaseInvocationOutput):
|
class LatentsOutput(BaseInvocationOutput):
|
||||||
"""Base class for nodes that output a single latents tensor"""
|
"""Base class for nodes that output a single latents tensor"""
|
||||||
|
|
||||||
type: Literal["latents_output"] = "latents_output"
|
|
||||||
|
|
||||||
latents: LatentsField = OutputField(
|
latents: LatentsField = OutputField(
|
||||||
description=FieldDescriptions.latents,
|
description=FieldDescriptions.latents,
|
||||||
)
|
)
|
||||||
@ -337,25 +310,20 @@ class LatentsOutput(BaseInvocationOutput):
|
|||||||
height: int = OutputField(description=FieldDescriptions.height)
|
height: int = OutputField(description=FieldDescriptions.height)
|
||||||
|
|
||||||
|
|
||||||
|
@invocation_output("latents_collection_output")
|
||||||
class LatentsCollectionOutput(BaseInvocationOutput):
|
class LatentsCollectionOutput(BaseInvocationOutput):
|
||||||
"""Base class for nodes that output a collection of latents tensors"""
|
"""Base class for nodes that output a collection of latents tensors"""
|
||||||
|
|
||||||
type: Literal["latents_collection_output"] = "latents_collection_output"
|
|
||||||
|
|
||||||
collection: list[LatentsField] = OutputField(
|
collection: list[LatentsField] = OutputField(
|
||||||
description=FieldDescriptions.latents,
|
description=FieldDescriptions.latents,
|
||||||
ui_type=UIType.LatentsCollection,
|
ui_type=UIType.LatentsCollection,
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|
||||||
@title("Latents Primitive")
|
@invocation("latents", title="Latents Primitive", tags=["primitives", "latents"], category="primitives")
|
||||||
@tags("primitives", "latents")
|
|
||||||
class LatentsInvocation(BaseInvocation):
|
class LatentsInvocation(BaseInvocation):
|
||||||
"""A latents tensor primitive value"""
|
"""A latents tensor primitive value"""
|
||||||
|
|
||||||
type: Literal["latents"] = "latents"
|
|
||||||
|
|
||||||
# Inputs
|
|
||||||
latents: LatentsField = InputField(description="The latents tensor", input=Input.Connection)
|
latents: LatentsField = InputField(description="The latents tensor", input=Input.Connection)
|
||||||
|
|
||||||
def invoke(self, context: InvocationContext) -> LatentsOutput:
|
def invoke(self, context: InvocationContext) -> LatentsOutput:
|
||||||
@ -364,14 +332,15 @@ class LatentsInvocation(BaseInvocation):
|
|||||||
return build_latents_output(self.latents.latents_name, latents)
|
return build_latents_output(self.latents.latents_name, latents)
|
||||||
|
|
||||||
|
|
||||||
@title("Latents Primitive Collection")
|
@invocation(
|
||||||
@tags("primitives", "latents", "collection")
|
"latents_collection",
|
||||||
|
title="Latents Collection Primitive",
|
||||||
|
tags=["primitives", "latents", "collection"],
|
||||||
|
category="primitives",
|
||||||
|
)
|
||||||
class LatentsCollectionInvocation(BaseInvocation):
|
class LatentsCollectionInvocation(BaseInvocation):
|
||||||
"""A collection of latents tensor primitive values"""
|
"""A collection of latents tensor primitive values"""
|
||||||
|
|
||||||
type: Literal["latents_collection"] = "latents_collection"
|
|
||||||
|
|
||||||
# Inputs
|
|
||||||
collection: list[LatentsField] = InputField(
|
collection: list[LatentsField] = InputField(
|
||||||
description="The collection of latents tensors", ui_type=UIType.LatentsCollection
|
description="The collection of latents tensors", ui_type=UIType.LatentsCollection
|
||||||
)
|
)
|
||||||
@ -405,30 +374,24 @@ class ColorField(BaseModel):
|
|||||||
return (self.r, self.g, self.b, self.a)
|
return (self.r, self.g, self.b, self.a)
|
||||||
|
|
||||||
|
|
||||||
|
@invocation_output("color_output")
|
||||||
class ColorOutput(BaseInvocationOutput):
|
class ColorOutput(BaseInvocationOutput):
|
||||||
"""Base class for nodes that output a single color"""
|
"""Base class for nodes that output a single color"""
|
||||||
|
|
||||||
type: Literal["color_output"] = "color_output"
|
|
||||||
color: ColorField = OutputField(description="The output color")
|
color: ColorField = OutputField(description="The output color")
|
||||||
|
|
||||||
|
|
||||||
|
@invocation_output("color_collection_output")
|
||||||
class ColorCollectionOutput(BaseInvocationOutput):
|
class ColorCollectionOutput(BaseInvocationOutput):
|
||||||
"""Base class for nodes that output a collection of colors"""
|
"""Base class for nodes that output a collection of colors"""
|
||||||
|
|
||||||
type: Literal["color_collection_output"] = "color_collection_output"
|
|
||||||
|
|
||||||
# Outputs
|
|
||||||
collection: list[ColorField] = OutputField(description="The output colors", ui_type=UIType.ColorCollection)
|
collection: list[ColorField] = OutputField(description="The output colors", ui_type=UIType.ColorCollection)
|
||||||
|
|
||||||
|
|
||||||
@title("Color Primitive")
|
@invocation("color", title="Color Primitive", tags=["primitives", "color"], category="primitives")
|
||||||
@tags("primitives", "color")
|
|
||||||
class ColorInvocation(BaseInvocation):
|
class ColorInvocation(BaseInvocation):
|
||||||
"""A color primitive value"""
|
"""A color primitive value"""
|
||||||
|
|
||||||
type: Literal["color"] = "color"
|
|
||||||
|
|
||||||
# Inputs
|
|
||||||
color: ColorField = InputField(default=ColorField(r=0, g=0, b=0, a=255), description="The color value")
|
color: ColorField = InputField(default=ColorField(r=0, g=0, b=0, a=255), description="The color value")
|
||||||
|
|
||||||
def invoke(self, context: InvocationContext) -> ColorOutput:
|
def invoke(self, context: InvocationContext) -> ColorOutput:
|
||||||
@ -446,47 +409,47 @@ class ConditioningField(BaseModel):
|
|||||||
conditioning_name: str = Field(description="The name of conditioning tensor")
|
conditioning_name: str = Field(description="The name of conditioning tensor")
|
||||||
|
|
||||||
|
|
||||||
|
@invocation_output("conditioning_output")
|
||||||
class ConditioningOutput(BaseInvocationOutput):
|
class ConditioningOutput(BaseInvocationOutput):
|
||||||
"""Base class for nodes that output a single conditioning tensor"""
|
"""Base class for nodes that output a single conditioning tensor"""
|
||||||
|
|
||||||
type: Literal["conditioning_output"] = "conditioning_output"
|
|
||||||
|
|
||||||
conditioning: ConditioningField = OutputField(description=FieldDescriptions.cond)
|
conditioning: ConditioningField = OutputField(description=FieldDescriptions.cond)
|
||||||
|
|
||||||
|
|
||||||
|
@invocation_output("conditioning_collection_output")
|
||||||
class ConditioningCollectionOutput(BaseInvocationOutput):
|
class ConditioningCollectionOutput(BaseInvocationOutput):
|
||||||
"""Base class for nodes that output a collection of conditioning tensors"""
|
"""Base class for nodes that output a collection of conditioning tensors"""
|
||||||
|
|
||||||
type: Literal["conditioning_collection_output"] = "conditioning_collection_output"
|
|
||||||
|
|
||||||
# Outputs
|
|
||||||
collection: list[ConditioningField] = OutputField(
|
collection: list[ConditioningField] = OutputField(
|
||||||
description="The output conditioning tensors",
|
description="The output conditioning tensors",
|
||||||
ui_type=UIType.ConditioningCollection,
|
ui_type=UIType.ConditioningCollection,
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|
||||||
@title("Conditioning Primitive")
|
@invocation(
|
||||||
@tags("primitives", "conditioning")
|
"conditioning",
|
||||||
|
title="Conditioning Primitive",
|
||||||
|
tags=["primitives", "conditioning"],
|
||||||
|
category="primitives",
|
||||||
|
)
|
||||||
class ConditioningInvocation(BaseInvocation):
|
class ConditioningInvocation(BaseInvocation):
|
||||||
"""A conditioning tensor primitive value"""
|
"""A conditioning tensor primitive value"""
|
||||||
|
|
||||||
type: Literal["conditioning"] = "conditioning"
|
|
||||||
|
|
||||||
conditioning: ConditioningField = InputField(description=FieldDescriptions.cond, input=Input.Connection)
|
conditioning: ConditioningField = InputField(description=FieldDescriptions.cond, input=Input.Connection)
|
||||||
|
|
||||||
def invoke(self, context: InvocationContext) -> ConditioningOutput:
|
def invoke(self, context: InvocationContext) -> ConditioningOutput:
|
||||||
return ConditioningOutput(conditioning=self.conditioning)
|
return ConditioningOutput(conditioning=self.conditioning)
|
||||||
|
|
||||||
|
|
||||||
@title("Conditioning Primitive Collection")
|
@invocation(
|
||||||
@tags("primitives", "conditioning", "collection")
|
"conditioning_collection",
|
||||||
|
title="Conditioning Collection Primitive",
|
||||||
|
tags=["primitives", "conditioning", "collection"],
|
||||||
|
category="primitives",
|
||||||
|
)
|
||||||
class ConditioningCollectionInvocation(BaseInvocation):
|
class ConditioningCollectionInvocation(BaseInvocation):
|
||||||
"""A collection of conditioning tensor primitive values"""
|
"""A collection of conditioning tensor primitive values"""
|
||||||
|
|
||||||
type: Literal["conditioning_collection"] = "conditioning_collection"
|
|
||||||
|
|
||||||
# Inputs
|
|
||||||
collection: list[ConditioningField] = InputField(
|
collection: list[ConditioningField] = InputField(
|
||||||
default=0, description="The collection of conditioning tensors", ui_type=UIType.ConditioningCollection
|
default=0, description="The collection of conditioning tensors", ui_type=UIType.ConditioningCollection
|
||||||
)
|
)
|
||||||
|
@ -1,5 +1,5 @@
|
|||||||
from os.path import exists
|
from os.path import exists
|
||||||
from typing import Literal, Optional, Union
|
from typing import Optional, Union
|
||||||
|
|
||||||
import numpy as np
|
import numpy as np
|
||||||
from dynamicprompts.generators import CombinatorialPromptGenerator, RandomPromptGenerator
|
from dynamicprompts.generators import CombinatorialPromptGenerator, RandomPromptGenerator
|
||||||
@ -7,17 +7,13 @@ from pydantic import validator
|
|||||||
|
|
||||||
from invokeai.app.invocations.primitives import StringCollectionOutput
|
from invokeai.app.invocations.primitives import StringCollectionOutput
|
||||||
|
|
||||||
from .baseinvocation import BaseInvocation, InputField, InvocationContext, UIComponent, tags, title
|
from .baseinvocation import BaseInvocation, InputField, InvocationContext, UIComponent, invocation
|
||||||
|
|
||||||
|
|
||||||
@title("Dynamic Prompt")
|
@invocation("dynamic_prompt", title="Dynamic Prompt", tags=["prompt", "collection"], category="prompt")
|
||||||
@tags("prompt", "collection")
|
|
||||||
class DynamicPromptInvocation(BaseInvocation):
|
class DynamicPromptInvocation(BaseInvocation):
|
||||||
"""Parses a prompt using adieyal/dynamicprompts' random or combinatorial generator"""
|
"""Parses a prompt using adieyal/dynamicprompts' random or combinatorial generator"""
|
||||||
|
|
||||||
type: Literal["dynamic_prompt"] = "dynamic_prompt"
|
|
||||||
|
|
||||||
# Inputs
|
|
||||||
prompt: str = InputField(description="The prompt to parse with dynamicprompts", ui_component=UIComponent.Textarea)
|
prompt: str = InputField(description="The prompt to parse with dynamicprompts", ui_component=UIComponent.Textarea)
|
||||||
max_prompts: int = InputField(default=1, description="The number of prompts to generate")
|
max_prompts: int = InputField(default=1, description="The number of prompts to generate")
|
||||||
combinatorial: bool = InputField(default=False, description="Whether to use the combinatorial generator")
|
combinatorial: bool = InputField(default=False, description="Whether to use the combinatorial generator")
|
||||||
@ -33,14 +29,10 @@ class DynamicPromptInvocation(BaseInvocation):
|
|||||||
return StringCollectionOutput(collection=prompts)
|
return StringCollectionOutput(collection=prompts)
|
||||||
|
|
||||||
|
|
||||||
@title("Prompts from File")
|
@invocation("prompt_from_file", title="Prompts from File", tags=["prompt", "file"], category="prompt")
|
||||||
@tags("prompt", "file")
|
|
||||||
class PromptsFromFileInvocation(BaseInvocation):
|
class PromptsFromFileInvocation(BaseInvocation):
|
||||||
"""Loads prompts from a text file"""
|
"""Loads prompts from a text file"""
|
||||||
|
|
||||||
type: Literal["prompt_from_file"] = "prompt_from_file"
|
|
||||||
|
|
||||||
# Inputs
|
|
||||||
file_path: str = InputField(description="Path to prompt text file")
|
file_path: str = InputField(description="Path to prompt text file")
|
||||||
pre_prompt: Optional[str] = InputField(
|
pre_prompt: Optional[str] = InputField(
|
||||||
default=None, description="String to prepend to each prompt", ui_component=UIComponent.Textarea
|
default=None, description="String to prepend to each prompt", ui_component=UIComponent.Textarea
|
||||||
|
@ -1,5 +1,3 @@
|
|||||||
from typing import Literal
|
|
||||||
|
|
||||||
from ...backend.model_management import ModelType, SubModelType
|
from ...backend.model_management import ModelType, SubModelType
|
||||||
from .baseinvocation import (
|
from .baseinvocation import (
|
||||||
BaseInvocation,
|
BaseInvocation,
|
||||||
@ -10,41 +8,35 @@ from .baseinvocation import (
|
|||||||
InvocationContext,
|
InvocationContext,
|
||||||
OutputField,
|
OutputField,
|
||||||
UIType,
|
UIType,
|
||||||
tags,
|
invocation,
|
||||||
title,
|
invocation_output,
|
||||||
)
|
)
|
||||||
from .model import ClipField, MainModelField, ModelInfo, UNetField, VaeField
|
from .model import ClipField, MainModelField, ModelInfo, UNetField, VaeField
|
||||||
|
|
||||||
|
|
||||||
|
@invocation_output("sdxl_model_loader_output")
|
||||||
class SDXLModelLoaderOutput(BaseInvocationOutput):
|
class SDXLModelLoaderOutput(BaseInvocationOutput):
|
||||||
"""SDXL base model loader output"""
|
"""SDXL base model loader output"""
|
||||||
|
|
||||||
type: Literal["sdxl_model_loader_output"] = "sdxl_model_loader_output"
|
|
||||||
|
|
||||||
unet: UNetField = OutputField(description=FieldDescriptions.unet, title="UNet")
|
unet: UNetField = OutputField(description=FieldDescriptions.unet, title="UNet")
|
||||||
clip: ClipField = OutputField(description=FieldDescriptions.clip, title="CLIP 1")
|
clip: ClipField = OutputField(description=FieldDescriptions.clip, title="CLIP 1")
|
||||||
clip2: ClipField = OutputField(description=FieldDescriptions.clip, title="CLIP 2")
|
clip2: ClipField = OutputField(description=FieldDescriptions.clip, title="CLIP 2")
|
||||||
vae: VaeField = OutputField(description=FieldDescriptions.vae, title="VAE")
|
vae: VaeField = OutputField(description=FieldDescriptions.vae, title="VAE")
|
||||||
|
|
||||||
|
|
||||||
|
@invocation_output("sdxl_refiner_model_loader_output")
|
||||||
class SDXLRefinerModelLoaderOutput(BaseInvocationOutput):
|
class SDXLRefinerModelLoaderOutput(BaseInvocationOutput):
|
||||||
"""SDXL refiner model loader output"""
|
"""SDXL refiner model loader output"""
|
||||||
|
|
||||||
type: Literal["sdxl_refiner_model_loader_output"] = "sdxl_refiner_model_loader_output"
|
|
||||||
|
|
||||||
unet: UNetField = OutputField(description=FieldDescriptions.unet, title="UNet")
|
unet: UNetField = OutputField(description=FieldDescriptions.unet, title="UNet")
|
||||||
clip2: ClipField = OutputField(description=FieldDescriptions.clip, title="CLIP 2")
|
clip2: ClipField = OutputField(description=FieldDescriptions.clip, title="CLIP 2")
|
||||||
vae: VaeField = OutputField(description=FieldDescriptions.vae, title="VAE")
|
vae: VaeField = OutputField(description=FieldDescriptions.vae, title="VAE")
|
||||||
|
|
||||||
|
|
||||||
@title("SDXL Main Model")
|
@invocation("sdxl_model_loader", title="SDXL Main Model", tags=["model", "sdxl"], category="model")
|
||||||
@tags("model", "sdxl")
|
|
||||||
class SDXLModelLoaderInvocation(BaseInvocation):
|
class SDXLModelLoaderInvocation(BaseInvocation):
|
||||||
"""Loads an sdxl base model, outputting its submodels."""
|
"""Loads an sdxl base model, outputting its submodels."""
|
||||||
|
|
||||||
type: Literal["sdxl_model_loader"] = "sdxl_model_loader"
|
|
||||||
|
|
||||||
# Inputs
|
|
||||||
model: MainModelField = InputField(
|
model: MainModelField = InputField(
|
||||||
description=FieldDescriptions.sdxl_main_model, input=Input.Direct, ui_type=UIType.SDXLMainModel
|
description=FieldDescriptions.sdxl_main_model, input=Input.Direct, ui_type=UIType.SDXLMainModel
|
||||||
)
|
)
|
||||||
@ -122,14 +114,15 @@ class SDXLModelLoaderInvocation(BaseInvocation):
|
|||||||
)
|
)
|
||||||
|
|
||||||
|
|
||||||
@title("SDXL Refiner Model")
|
@invocation(
|
||||||
@tags("model", "sdxl", "refiner")
|
"sdxl_refiner_model_loader",
|
||||||
|
title="SDXL Refiner Model",
|
||||||
|
tags=["model", "sdxl", "refiner"],
|
||||||
|
category="model",
|
||||||
|
)
|
||||||
class SDXLRefinerModelLoaderInvocation(BaseInvocation):
|
class SDXLRefinerModelLoaderInvocation(BaseInvocation):
|
||||||
"""Loads an sdxl refiner model, outputting its submodels."""
|
"""Loads an sdxl refiner model, outputting its submodels."""
|
||||||
|
|
||||||
type: Literal["sdxl_refiner_model_loader"] = "sdxl_refiner_model_loader"
|
|
||||||
|
|
||||||
# Inputs
|
|
||||||
model: MainModelField = InputField(
|
model: MainModelField = InputField(
|
||||||
description=FieldDescriptions.sdxl_refiner_model,
|
description=FieldDescriptions.sdxl_refiner_model,
|
||||||
input=Input.Direct,
|
input=Input.Direct,
|
||||||
|
@ -11,7 +11,7 @@ from invokeai.app.invocations.primitives import ImageField, ImageOutput
|
|||||||
|
|
||||||
from invokeai.app.models.image import ImageCategory, ResourceOrigin
|
from invokeai.app.models.image import ImageCategory, ResourceOrigin
|
||||||
|
|
||||||
from .baseinvocation import BaseInvocation, InputField, InvocationContext, title, tags
|
from .baseinvocation import BaseInvocation, InputField, InvocationContext, invocation
|
||||||
|
|
||||||
# TODO: Populate this from disk?
|
# TODO: Populate this from disk?
|
||||||
# TODO: Use model manager to load?
|
# TODO: Use model manager to load?
|
||||||
@ -23,14 +23,10 @@ ESRGAN_MODELS = Literal[
|
|||||||
]
|
]
|
||||||
|
|
||||||
|
|
||||||
@title("Upscale (RealESRGAN)")
|
@invocation("esrgan", title="Upscale (RealESRGAN)", tags=["esrgan", "upscale"], category="esrgan")
|
||||||
@tags("esrgan", "upscale")
|
|
||||||
class ESRGANInvocation(BaseInvocation):
|
class ESRGANInvocation(BaseInvocation):
|
||||||
"""Upscales an image using RealESRGAN."""
|
"""Upscales an image using RealESRGAN."""
|
||||||
|
|
||||||
type: Literal["esrgan"] = "esrgan"
|
|
||||||
|
|
||||||
# Inputs
|
|
||||||
image: ImageField = InputField(description="The input image")
|
image: ImageField = InputField(description="The input image")
|
||||||
model_name: ESRGAN_MODELS = InputField(default="RealESRGAN_x4plus.pth", description="The Real-ESRGAN model to use")
|
model_name: ESRGAN_MODELS = InputField(default="RealESRGAN_x4plus.pth", description="The Real-ESRGAN model to use")
|
||||||
|
|
||||||
|
@ -3,7 +3,7 @@
|
|||||||
import copy
|
import copy
|
||||||
import itertools
|
import itertools
|
||||||
import uuid
|
import uuid
|
||||||
from typing import Annotated, Any, Literal, Optional, Union, get_args, get_origin, get_type_hints
|
from typing import Annotated, Any, Optional, Union, get_args, get_origin, get_type_hints
|
||||||
|
|
||||||
import networkx as nx
|
import networkx as nx
|
||||||
from pydantic import BaseModel, root_validator, validator
|
from pydantic import BaseModel, root_validator, validator
|
||||||
@ -14,11 +14,13 @@ from ..invocations import * # noqa: F401 F403
|
|||||||
from ..invocations.baseinvocation import (
|
from ..invocations.baseinvocation import (
|
||||||
BaseInvocation,
|
BaseInvocation,
|
||||||
BaseInvocationOutput,
|
BaseInvocationOutput,
|
||||||
|
invocation,
|
||||||
Input,
|
Input,
|
||||||
InputField,
|
InputField,
|
||||||
InvocationContext,
|
InvocationContext,
|
||||||
OutputField,
|
OutputField,
|
||||||
UIType,
|
UIType,
|
||||||
|
invocation_output,
|
||||||
)
|
)
|
||||||
|
|
||||||
# in 3.10 this would be "from types import NoneType"
|
# in 3.10 this would be "from types import NoneType"
|
||||||
@ -148,24 +150,16 @@ class NodeAlreadyExecutedError(Exception):
|
|||||||
|
|
||||||
|
|
||||||
# TODO: Create and use an Empty output?
|
# TODO: Create and use an Empty output?
|
||||||
|
@invocation_output("graph_output")
|
||||||
class GraphInvocationOutput(BaseInvocationOutput):
|
class GraphInvocationOutput(BaseInvocationOutput):
|
||||||
type: Literal["graph_output"] = "graph_output"
|
pass
|
||||||
|
|
||||||
class Config:
|
|
||||||
schema_extra = {
|
|
||||||
"required": [
|
|
||||||
"type",
|
|
||||||
"image",
|
|
||||||
]
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
# TODO: Fill this out and move to invocations
|
# TODO: Fill this out and move to invocations
|
||||||
|
@invocation("graph")
|
||||||
class GraphInvocation(BaseInvocation):
|
class GraphInvocation(BaseInvocation):
|
||||||
"""Execute a graph"""
|
"""Execute a graph"""
|
||||||
|
|
||||||
type: Literal["graph"] = "graph"
|
|
||||||
|
|
||||||
# TODO: figure out how to create a default here
|
# TODO: figure out how to create a default here
|
||||||
graph: "Graph" = Field(description="The graph to run", default=None)
|
graph: "Graph" = Field(description="The graph to run", default=None)
|
||||||
|
|
||||||
@ -174,22 +168,20 @@ class GraphInvocation(BaseInvocation):
|
|||||||
return GraphInvocationOutput()
|
return GraphInvocationOutput()
|
||||||
|
|
||||||
|
|
||||||
|
@invocation_output("iterate_output")
|
||||||
class IterateInvocationOutput(BaseInvocationOutput):
|
class IterateInvocationOutput(BaseInvocationOutput):
|
||||||
"""Used to connect iteration outputs. Will be expanded to a specific output."""
|
"""Used to connect iteration outputs. Will be expanded to a specific output."""
|
||||||
|
|
||||||
type: Literal["iterate_output"] = "iterate_output"
|
|
||||||
|
|
||||||
item: Any = OutputField(
|
item: Any = OutputField(
|
||||||
description="The item being iterated over", title="Collection Item", ui_type=UIType.CollectionItem
|
description="The item being iterated over", title="Collection Item", ui_type=UIType.CollectionItem
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|
||||||
# TODO: Fill this out and move to invocations
|
# TODO: Fill this out and move to invocations
|
||||||
|
@invocation("iterate")
|
||||||
class IterateInvocation(BaseInvocation):
|
class IterateInvocation(BaseInvocation):
|
||||||
"""Iterates over a list of items"""
|
"""Iterates over a list of items"""
|
||||||
|
|
||||||
type: Literal["iterate"] = "iterate"
|
|
||||||
|
|
||||||
collection: list[Any] = InputField(
|
collection: list[Any] = InputField(
|
||||||
description="The list of items to iterate over", default_factory=list, ui_type=UIType.Collection
|
description="The list of items to iterate over", default_factory=list, ui_type=UIType.Collection
|
||||||
)
|
)
|
||||||
@ -200,19 +192,17 @@ class IterateInvocation(BaseInvocation):
|
|||||||
return IterateInvocationOutput(item=self.collection[self.index])
|
return IterateInvocationOutput(item=self.collection[self.index])
|
||||||
|
|
||||||
|
|
||||||
|
@invocation_output("collect_output")
|
||||||
class CollectInvocationOutput(BaseInvocationOutput):
|
class CollectInvocationOutput(BaseInvocationOutput):
|
||||||
type: Literal["collect_output"] = "collect_output"
|
|
||||||
|
|
||||||
collection: list[Any] = OutputField(
|
collection: list[Any] = OutputField(
|
||||||
description="The collection of input items", title="Collection", ui_type=UIType.Collection
|
description="The collection of input items", title="Collection", ui_type=UIType.Collection
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|
||||||
|
@invocation("collect")
|
||||||
class CollectInvocation(BaseInvocation):
|
class CollectInvocation(BaseInvocation):
|
||||||
"""Collects values into a collection"""
|
"""Collects values into a collection"""
|
||||||
|
|
||||||
type: Literal["collect"] = "collect"
|
|
||||||
|
|
||||||
item: Any = InputField(
|
item: Any = InputField(
|
||||||
description="The item to collect (all inputs must be of the same type)",
|
description="The item to collect (all inputs must be of the same type)",
|
||||||
ui_type=UIType.CollectionItem,
|
ui_type=UIType.CollectionItem,
|
||||||
|
@ -678,6 +678,7 @@ export type TypeHints = {
|
|||||||
export type InvocationSchemaExtra = {
|
export type InvocationSchemaExtra = {
|
||||||
output: OpenAPIV3.ReferenceObject; // the output of the invocation
|
output: OpenAPIV3.ReferenceObject; // the output of the invocation
|
||||||
title: string;
|
title: string;
|
||||||
|
category?: string;
|
||||||
tags?: string[];
|
tags?: string[];
|
||||||
properties: Omit<
|
properties: Omit<
|
||||||
NonNullable<OpenAPIV3.SchemaObject['properties']> &
|
NonNullable<OpenAPIV3.SchemaObject['properties']> &
|
||||||
|
1914
invokeai/frontend/web/src/services/api/schema.d.ts
vendored
1914
invokeai/frontend/web/src/services/api/schema.d.ts
vendored
File diff suppressed because one or more lines are too long
@ -1,65 +1,63 @@
|
|||||||
from typing import Any, Callable, Literal, Union
|
from typing import Any, Callable, Union
|
||||||
from pydantic import Field
|
from pydantic import Field
|
||||||
from invokeai.app.invocations.baseinvocation import BaseInvocation, BaseInvocationOutput, InvocationContext
|
from invokeai.app.invocations.baseinvocation import (
|
||||||
|
BaseInvocation,
|
||||||
|
BaseInvocationOutput,
|
||||||
|
InvocationContext,
|
||||||
|
invocation,
|
||||||
|
invocation_output,
|
||||||
|
)
|
||||||
from invokeai.app.invocations.image import ImageField
|
from invokeai.app.invocations.image import ImageField
|
||||||
|
|
||||||
|
|
||||||
# Define test invocations before importing anything that uses invocations
|
# Define test invocations before importing anything that uses invocations
|
||||||
|
@invocation_output("test_list_output")
|
||||||
class ListPassThroughInvocationOutput(BaseInvocationOutput):
|
class ListPassThroughInvocationOutput(BaseInvocationOutput):
|
||||||
type: Literal["test_list_output"] = "test_list_output"
|
|
||||||
|
|
||||||
collection: list[ImageField] = Field(default_factory=list)
|
collection: list[ImageField] = Field(default_factory=list)
|
||||||
|
|
||||||
|
|
||||||
|
@invocation("test_list")
|
||||||
class ListPassThroughInvocation(BaseInvocation):
|
class ListPassThroughInvocation(BaseInvocation):
|
||||||
type: Literal["test_list"] = "test_list"
|
|
||||||
|
|
||||||
collection: list[ImageField] = Field(default_factory=list)
|
collection: list[ImageField] = Field(default_factory=list)
|
||||||
|
|
||||||
def invoke(self, context: InvocationContext) -> ListPassThroughInvocationOutput:
|
def invoke(self, context: InvocationContext) -> ListPassThroughInvocationOutput:
|
||||||
return ListPassThroughInvocationOutput(collection=self.collection)
|
return ListPassThroughInvocationOutput(collection=self.collection)
|
||||||
|
|
||||||
|
|
||||||
|
@invocation_output("test_prompt_output")
|
||||||
class PromptTestInvocationOutput(BaseInvocationOutput):
|
class PromptTestInvocationOutput(BaseInvocationOutput):
|
||||||
type: Literal["test_prompt_output"] = "test_prompt_output"
|
|
||||||
|
|
||||||
prompt: str = Field(default="")
|
prompt: str = Field(default="")
|
||||||
|
|
||||||
|
|
||||||
|
@invocation("test_prompt")
|
||||||
class PromptTestInvocation(BaseInvocation):
|
class PromptTestInvocation(BaseInvocation):
|
||||||
type: Literal["test_prompt"] = "test_prompt"
|
|
||||||
|
|
||||||
prompt: str = Field(default="")
|
prompt: str = Field(default="")
|
||||||
|
|
||||||
def invoke(self, context: InvocationContext) -> PromptTestInvocationOutput:
|
def invoke(self, context: InvocationContext) -> PromptTestInvocationOutput:
|
||||||
return PromptTestInvocationOutput(prompt=self.prompt)
|
return PromptTestInvocationOutput(prompt=self.prompt)
|
||||||
|
|
||||||
|
|
||||||
|
@invocation("test_error")
|
||||||
class ErrorInvocation(BaseInvocation):
|
class ErrorInvocation(BaseInvocation):
|
||||||
type: Literal["test_error"] = "test_error"
|
|
||||||
|
|
||||||
def invoke(self, context: InvocationContext) -> PromptTestInvocationOutput:
|
def invoke(self, context: InvocationContext) -> PromptTestInvocationOutput:
|
||||||
raise Exception("This invocation is supposed to fail")
|
raise Exception("This invocation is supposed to fail")
|
||||||
|
|
||||||
|
|
||||||
|
@invocation_output("test_image_output")
|
||||||
class ImageTestInvocationOutput(BaseInvocationOutput):
|
class ImageTestInvocationOutput(BaseInvocationOutput):
|
||||||
type: Literal["test_image_output"] = "test_image_output"
|
|
||||||
|
|
||||||
image: ImageField = Field()
|
image: ImageField = Field()
|
||||||
|
|
||||||
|
|
||||||
|
@invocation("test_text_to_image")
|
||||||
class TextToImageTestInvocation(BaseInvocation):
|
class TextToImageTestInvocation(BaseInvocation):
|
||||||
type: Literal["test_text_to_image"] = "test_text_to_image"
|
|
||||||
|
|
||||||
prompt: str = Field(default="")
|
prompt: str = Field(default="")
|
||||||
|
|
||||||
def invoke(self, context: InvocationContext) -> ImageTestInvocationOutput:
|
def invoke(self, context: InvocationContext) -> ImageTestInvocationOutput:
|
||||||
return ImageTestInvocationOutput(image=ImageField(image_name=self.id))
|
return ImageTestInvocationOutput(image=ImageField(image_name=self.id))
|
||||||
|
|
||||||
|
|
||||||
|
@invocation("test_image_to_image")
|
||||||
class ImageToImageTestInvocation(BaseInvocation):
|
class ImageToImageTestInvocation(BaseInvocation):
|
||||||
type: Literal["test_image_to_image"] = "test_image_to_image"
|
|
||||||
|
|
||||||
prompt: str = Field(default="")
|
prompt: str = Field(default="")
|
||||||
image: Union[ImageField, None] = Field(default=None)
|
image: Union[ImageField, None] = Field(default=None)
|
||||||
|
|
||||||
@ -67,13 +65,13 @@ class ImageToImageTestInvocation(BaseInvocation):
|
|||||||
return ImageTestInvocationOutput(image=ImageField(image_name=self.id))
|
return ImageTestInvocationOutput(image=ImageField(image_name=self.id))
|
||||||
|
|
||||||
|
|
||||||
|
@invocation_output("test_prompt_collection_output")
|
||||||
class PromptCollectionTestInvocationOutput(BaseInvocationOutput):
|
class PromptCollectionTestInvocationOutput(BaseInvocationOutput):
|
||||||
type: Literal["test_prompt_collection_output"] = "test_prompt_collection_output"
|
|
||||||
collection: list[str] = Field(default_factory=list)
|
collection: list[str] = Field(default_factory=list)
|
||||||
|
|
||||||
|
|
||||||
|
@invocation("test_prompt_collection")
|
||||||
class PromptCollectionTestInvocation(BaseInvocation):
|
class PromptCollectionTestInvocation(BaseInvocation):
|
||||||
type: Literal["test_prompt_collection"] = "test_prompt_collection"
|
|
||||||
collection: list[str] = Field()
|
collection: list[str] = Field()
|
||||||
|
|
||||||
def invoke(self, context: InvocationContext) -> PromptCollectionTestInvocationOutput:
|
def invoke(self, context: InvocationContext) -> PromptCollectionTestInvocationOutput:
|
||||||
|
Loading…
Reference in New Issue
Block a user