Skip to content

Commit 5d55340

Browse files
feat(nodes): address feedback
- Address database feedback: - Remove all the extraneous tables. Only an `images` table now: - Image type and category are unrestricted strings. When creating images, the provided values are checked to ensure they are a valid type and category. - Add `updated_at` and `deleted_at` columns. `deleted_at` is currently unused. - Use SQLite's built-in timestamp features to populate these. Add a trigger to update `updated_at` when the row is updated. Currently no way to update a row. - Rename the `id` column in `images` to `image_name` - Rename `ImageCategory.IMAGE` to `ImageCategory.GENERAL` - Move all exceptions outside their base classes to make them more portable. - Add `width` and `height` columns to the database. These store the actual dimensions of the image file, whereas the metadata's `width` and `height` refer to the respective generation parameters and are nullable. - Make `deserialize_image_record` take a `dict` instead of `sqlite3.Row` - Improve comments throughout - Tidy up unused code/files and some minor organisation
1 parent ed49119 commit 5d55340

File tree

12 files changed

+267
-840
lines changed

12 files changed

+267
-840
lines changed

invokeai/app/api/routers/images.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ async def upload_image(
3030
image_type: ImageType,
3131
request: Request,
3232
response: Response,
33-
image_category: ImageCategory = ImageCategory.IMAGE,
33+
image_category: ImageCategory = ImageCategory.GENERAL,
3434
) -> ImageDTO:
3535
"""Uploads an image"""
3636
if not file.content_type.startswith("image"):

invokeai/app/invocations/generate.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -95,7 +95,7 @@ def invoke(self, context: InvocationContext) -> ImageOutput:
9595
image_dto = context.services.images_new.create(
9696
image=generate_output.image,
9797
image_type=ImageType.RESULT,
98-
image_category=ImageCategory.IMAGE,
98+
image_category=ImageCategory.GENERAL,
9999
session_id=context.graph_execution_state_id,
100100
node_id=self.id,
101101
)
@@ -119,7 +119,7 @@ def invoke(self, context: InvocationContext) -> ImageOutput:
119119
# context.services.images_db.set(
120120
# id=image_name,
121121
# image_type=ImageType.RESULT,
122-
# image_category=ImageCategory.IMAGE,
122+
# image_category=ImageCategory.GENERAL,
123123
# session_id=context.graph_execution_state_id,
124124
# node_id=self.id,
125125
# metadata=GeneratedImageOrLatentsMetadata(),

invokeai/app/invocations/latent.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -372,7 +372,7 @@ def invoke(self, context: InvocationContext) -> ImageOutput:
372372
image_dto = context.services.images_new.create(
373373
image=image,
374374
image_type=ImageType.RESULT,
375-
image_category=ImageCategory.IMAGE,
375+
image_category=ImageCategory.GENERAL,
376376
session_id=context.graph_execution_state_id,
377377
node_id=self.id,
378378
)

invokeai/app/models/image.py

Lines changed: 21 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
from typing import Optional, Tuple
33
from pydantic import BaseModel, Field
44

5-
from invokeai.app.util.enum import MetaEnum
5+
from invokeai.app.util.metaenum import MetaEnum
66

77

88
class ImageType(str, Enum, metaclass=MetaEnum):
@@ -13,20 +13,32 @@ class ImageType(str, Enum, metaclass=MetaEnum):
1313
INTERMEDIATE = "intermediates"
1414

1515

16+
class InvalidImageTypeException(ValueError):
17+
"""Raised when a provided value is not a valid ImageType.
18+
19+
Subclasses `ValueError`.
20+
"""
21+
22+
def __init__(self, message="Invalid image type."):
23+
super().__init__(message)
24+
25+
1626
class ImageCategory(str, Enum, metaclass=MetaEnum):
1727
"""The category of an image. Use ImageCategory.OTHER for non-default categories."""
1828

19-
IMAGE = "image"
20-
CONTROL_IMAGE = "control_image"
29+
GENERAL = "general"
30+
CONTROL = "control"
2131
OTHER = "other"
2232

2333

24-
def is_image_type(obj):
25-
try:
26-
ImageType(obj)
27-
except ValueError:
28-
return False
29-
return True
34+
class InvalidImageCategoryException(ValueError):
35+
"""Raised when a provided value is not a valid ImageCategory.
36+
37+
Subclasses `ValueError`.
38+
"""
39+
40+
def __init__(self, message="Invalid image category."):
41+
super().__init__(message)
3042

3143

3244
class ImageField(BaseModel):

invokeai/app/models/metadata.py

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,50 +26,66 @@ class Config:
2626
default=None,
2727
description="The type of the ancestor node of the image output node.",
2828
)
29+
"""The type of the ancestor node of the image output node."""
2930
positive_conditioning: Optional[StrictStr] = Field(
3031
default=None, description="The positive conditioning."
3132
)
33+
"""The positive conditioning"""
3234
negative_conditioning: Optional[StrictStr] = Field(
3335
default=None, description="The negative conditioning."
3436
)
37+
"""The negative conditioning"""
3538
width: Optional[StrictInt] = Field(
3639
default=None, description="Width of the image/latents in pixels."
3740
)
41+
"""Width of the image/latents in pixels"""
3842
height: Optional[StrictInt] = Field(
3943
default=None, description="Height of the image/latents in pixels."
4044
)
45+
"""Height of the image/latents in pixels"""
4146
seed: Optional[StrictInt] = Field(
4247
default=None, description="The seed used for noise generation."
4348
)
49+
"""The seed used for noise generation"""
4450
cfg_scale: Optional[StrictFloat] = Field(
4551
default=None, description="The classifier-free guidance scale."
4652
)
53+
"""The classifier-free guidance scale"""
4754
steps: Optional[StrictInt] = Field(
4855
default=None, description="The number of steps used for inference."
4956
)
57+
"""The number of steps used for inference"""
5058
scheduler: Optional[StrictStr] = Field(
5159
default=None, description="The scheduler used for inference."
5260
)
61+
"""The scheduler used for inference"""
5362
model: Optional[StrictStr] = Field(
5463
default=None, description="The model used for inference."
5564
)
65+
"""The model used for inference"""
5666
strength: Optional[StrictFloat] = Field(
5767
default=None,
5868
description="The strength used for image-to-image/latents-to-latents.",
5969
)
70+
"""The strength used for image-to-image/latents-to-latents."""
6071
latents: Optional[StrictStr] = Field(
6172
default=None, description="The ID of the initial latents."
6273
)
74+
"""The ID of the initial latents"""
6375
vae: Optional[StrictStr] = Field(
6476
default=None, description="The VAE used for decoding."
6577
)
78+
"""The VAE used for decoding"""
6679
unet: Optional[StrictStr] = Field(
6780
default=None, description="The UNet used dor inference."
6881
)
82+
"""The UNet used dor inference"""
6983
clip: Optional[StrictStr] = Field(
7084
default=None, description="The CLIP Encoder used for conditioning."
7185
)
86+
"""The CLIP Encoder used for conditioning"""
7287
extra: Optional[StrictStr] = Field(
7388
default=None,
7489
description="Uploaded image metadata, extracted from the PNG tEXt chunk.",
7590
)
91+
"""Uploaded image metadata, extracted from the PNG tEXt chunk."""

invokeai/app/models/resources.py

Lines changed: 0 additions & 28 deletions
This file was deleted.

0 commit comments

Comments
 (0)