mirror of
https://github.com/invoke-ai/InvokeAI
synced 2024-08-30 20:32:17 +00:00
feat(nodes): add logger to images service
This commit is contained in:
parent
d14b02e93f
commit
f7804f6126
@ -2,7 +2,6 @@
|
|||||||
|
|
||||||
from logging import Logger
|
from logging import Logger
|
||||||
import os
|
import os
|
||||||
from types import ModuleType
|
|
||||||
from invokeai.app.services.image_record_storage import SqliteImageRecordStorage
|
from invokeai.app.services.image_record_storage import SqliteImageRecordStorage
|
||||||
from invokeai.app.services.images import ImageService
|
from invokeai.app.services.images import ImageService
|
||||||
from invokeai.app.services.urls import LocalUrlService
|
from invokeai.app.services.urls import LocalUrlService
|
||||||
@ -20,7 +19,6 @@ from ..services.invoker import Invoker
|
|||||||
from ..services.processor import DefaultInvocationProcessor
|
from ..services.processor import DefaultInvocationProcessor
|
||||||
from ..services.sqlite import SqliteItemStorage
|
from ..services.sqlite import SqliteItemStorage
|
||||||
from ..services.metadata import PngMetadataService
|
from ..services.metadata import PngMetadataService
|
||||||
from ..services.results import SqliteResultsService
|
|
||||||
from .events import FastAPIEventService
|
from .events import FastAPIEventService
|
||||||
|
|
||||||
|
|
||||||
@ -83,19 +81,15 @@ class ApiDependencies:
|
|||||||
image_file_storage=image_file_storage,
|
image_file_storage=image_file_storage,
|
||||||
metadata=metadata,
|
metadata=metadata,
|
||||||
url=urls,
|
url=urls,
|
||||||
|
logger=logger,
|
||||||
)
|
)
|
||||||
|
|
||||||
# register event handler to update the `results` table when a graph execution state is inserted or updated
|
|
||||||
# graph_execution_manager.on_changed(results.handle_graph_execution_state_change)
|
|
||||||
|
|
||||||
services = InvocationServices(
|
services = InvocationServices(
|
||||||
model_manager=get_model_manager(config, logger),
|
model_manager=get_model_manager(config, logger),
|
||||||
events=events,
|
events=events,
|
||||||
latents=latents,
|
latents=latents,
|
||||||
images=images,
|
images=image_file_storage,
|
||||||
images_new=images_new,
|
images_new=images_new,
|
||||||
metadata=metadata,
|
|
||||||
urls=urls,
|
|
||||||
queue=MemoryInvocationQueue(),
|
queue=MemoryInvocationQueue(),
|
||||||
graph_library=SqliteItemStorage[LibraryGraph](
|
graph_library=SqliteItemStorage[LibraryGraph](
|
||||||
filename=db_location, table_name="graphs"
|
filename=db_location, table_name="graphs"
|
||||||
|
@ -1,3 +1,4 @@
|
|||||||
|
from logging import Logger
|
||||||
from typing import Optional, Union
|
from typing import Optional, Union
|
||||||
import uuid
|
import uuid
|
||||||
from PIL.Image import Image as PILImageType
|
from PIL.Image import Image as PILImageType
|
||||||
@ -28,6 +29,7 @@ class ImageServiceDependencies:
|
|||||||
files: ImageFileStorageBase
|
files: ImageFileStorageBase
|
||||||
metadata: MetadataServiceBase
|
metadata: MetadataServiceBase
|
||||||
urls: UrlServiceBase
|
urls: UrlServiceBase
|
||||||
|
logger: Logger
|
||||||
|
|
||||||
def __init__(
|
def __init__(
|
||||||
self,
|
self,
|
||||||
@ -35,11 +37,13 @@ class ImageServiceDependencies:
|
|||||||
image_file_storage: ImageFileStorageBase,
|
image_file_storage: ImageFileStorageBase,
|
||||||
metadata: MetadataServiceBase,
|
metadata: MetadataServiceBase,
|
||||||
url: UrlServiceBase,
|
url: UrlServiceBase,
|
||||||
|
logger: Logger,
|
||||||
):
|
):
|
||||||
self.records = image_record_storage
|
self.records = image_record_storage
|
||||||
self.files = image_file_storage
|
self.files = image_file_storage
|
||||||
self.metadata = metadata
|
self.metadata = metadata
|
||||||
self.urls = url
|
self.urls = url
|
||||||
|
self.logger = logger
|
||||||
|
|
||||||
|
|
||||||
class ImageService:
|
class ImageService:
|
||||||
@ -53,12 +57,14 @@ class ImageService:
|
|||||||
image_file_storage: ImageFileStorageBase,
|
image_file_storage: ImageFileStorageBase,
|
||||||
metadata: MetadataServiceBase,
|
metadata: MetadataServiceBase,
|
||||||
url: UrlServiceBase,
|
url: UrlServiceBase,
|
||||||
|
logger: Logger,
|
||||||
):
|
):
|
||||||
self._services = ImageServiceDependencies(
|
self._services = ImageServiceDependencies(
|
||||||
image_record_storage=image_record_storage,
|
image_record_storage=image_record_storage,
|
||||||
image_file_storage=image_file_storage,
|
image_file_storage=image_file_storage,
|
||||||
metadata=metadata,
|
metadata=metadata,
|
||||||
url=url,
|
url=url,
|
||||||
|
logger=logger,
|
||||||
)
|
)
|
||||||
|
|
||||||
def _create_image_name(
|
def _create_image_name(
|
||||||
@ -117,7 +123,9 @@ class ImageService:
|
|||||||
)
|
)
|
||||||
|
|
||||||
image_url = self._services.urls.get_image_url(image_type, image_name)
|
image_url = self._services.urls.get_image_url(image_type, image_name)
|
||||||
thumbnail_url = self._services.urls.get_thumbnail_url(image_type, image_name)
|
thumbnail_url = self._services.urls.get_thumbnail_url(
|
||||||
|
image_type, image_name
|
||||||
|
)
|
||||||
|
|
||||||
return ImageDTO(
|
return ImageDTO(
|
||||||
image_name=image_name,
|
image_name=image_name,
|
||||||
@ -131,10 +139,10 @@ class ImageService:
|
|||||||
thumbnail_url=thumbnail_url,
|
thumbnail_url=thumbnail_url,
|
||||||
)
|
)
|
||||||
except ImageRecordStorageBase.ImageRecordSaveException:
|
except ImageRecordStorageBase.ImageRecordSaveException:
|
||||||
# TODO: log this
|
self._services.logger.error("Failed to save image record")
|
||||||
raise
|
raise
|
||||||
except ImageFileStorageBase.ImageFileSaveException:
|
except ImageFileStorageBase.ImageFileSaveException:
|
||||||
# TODO: log this
|
self._services.logger.error("Failed to save image file")
|
||||||
raise
|
raise
|
||||||
|
|
||||||
def get_pil_image(self, image_type: ImageType, image_name: str) -> PILImageType:
|
def get_pil_image(self, image_type: ImageType, image_name: str) -> PILImageType:
|
||||||
@ -142,7 +150,7 @@ class ImageService:
|
|||||||
try:
|
try:
|
||||||
return self._services.files.get(image_type, image_name)
|
return self._services.files.get(image_type, image_name)
|
||||||
except ImageFileStorageBase.ImageFileNotFoundException:
|
except ImageFileStorageBase.ImageFileNotFoundException:
|
||||||
# TODO: log this
|
self._services.logger.error("Failed to get image file")
|
||||||
raise
|
raise
|
||||||
|
|
||||||
def get_record(self, image_type: ImageType, image_name: str) -> ImageRecord:
|
def get_record(self, image_type: ImageType, image_name: str) -> ImageRecord:
|
||||||
@ -150,7 +158,7 @@ class ImageService:
|
|||||||
try:
|
try:
|
||||||
return self._services.records.get(image_type, image_name)
|
return self._services.records.get(image_type, image_name)
|
||||||
except ImageRecordStorageBase.ImageRecordNotFoundException:
|
except ImageRecordStorageBase.ImageRecordNotFoundException:
|
||||||
# TODO: log this
|
self._services.logger.error("Failed to get image record")
|
||||||
raise
|
raise
|
||||||
|
|
||||||
def get_dto(self, image_type: ImageType, image_name: str) -> ImageDTO:
|
def get_dto(self, image_type: ImageType, image_name: str) -> ImageDTO:
|
||||||
@ -166,7 +174,7 @@ class ImageService:
|
|||||||
|
|
||||||
return image_dto
|
return image_dto
|
||||||
except ImageRecordStorageBase.ImageRecordNotFoundException:
|
except ImageRecordStorageBase.ImageRecordNotFoundException:
|
||||||
# TODO: log this
|
self._services.logger.error("Failed to get image DTO")
|
||||||
raise
|
raise
|
||||||
|
|
||||||
def delete(self, image_type: ImageType, image_name: str):
|
def delete(self, image_type: ImageType, image_name: str):
|
||||||
@ -176,10 +184,10 @@ class ImageService:
|
|||||||
self._services.files.delete(image_type, image_name)
|
self._services.files.delete(image_type, image_name)
|
||||||
self._services.records.delete(image_type, image_name)
|
self._services.records.delete(image_type, image_name)
|
||||||
except ImageRecordStorageBase.ImageRecordDeleteException:
|
except ImageRecordStorageBase.ImageRecordDeleteException:
|
||||||
# TODO: log this
|
self._services.logger.error(f"Failed to delete image record")
|
||||||
raise
|
raise
|
||||||
except ImageFileStorageBase.ImageFileDeleteException:
|
except ImageFileStorageBase.ImageFileDeleteException:
|
||||||
# TODO: log this
|
self._services.logger.error(f"Failed to delete image file")
|
||||||
raise
|
raise
|
||||||
|
|
||||||
def get_many(
|
def get_many(
|
||||||
@ -217,6 +225,7 @@ class ImageService:
|
|||||||
total=results.total,
|
total=results.total,
|
||||||
)
|
)
|
||||||
except Exception as e:
|
except Exception as e:
|
||||||
|
self._services.logger.error("Failed to get paginated image DTOs")
|
||||||
raise e
|
raise e
|
||||||
|
|
||||||
def add_tag(self, image_type: ImageType, image_id: str, tag: str) -> None:
|
def add_tag(self, image_type: ImageType, image_id: str, tag: str) -> None:
|
||||||
|
@ -2,8 +2,6 @@
|
|||||||
|
|
||||||
from logging import Logger
|
from logging import Logger
|
||||||
from invokeai.app.services.images import ImageService
|
from invokeai.app.services.images import ImageService
|
||||||
from invokeai.app.services.metadata import MetadataServiceBase
|
|
||||||
from invokeai.app.services.urls import UrlServiceBase
|
|
||||||
from invokeai.backend import ModelManager
|
from invokeai.backend import ModelManager
|
||||||
|
|
||||||
from .events import EventServiceBase
|
from .events import EventServiceBase
|
||||||
@ -21,12 +19,10 @@ class InvocationServices:
|
|||||||
events: EventServiceBase
|
events: EventServiceBase
|
||||||
latents: LatentsStorageBase
|
latents: LatentsStorageBase
|
||||||
images: ImageFileStorageBase
|
images: ImageFileStorageBase
|
||||||
metadata: MetadataServiceBase
|
|
||||||
queue: InvocationQueueABC
|
queue: InvocationQueueABC
|
||||||
model_manager: ModelManager
|
model_manager: ModelManager
|
||||||
restoration: RestorationServices
|
restoration: RestorationServices
|
||||||
configuration: InvokeAISettings
|
configuration: InvokeAISettings
|
||||||
urls: UrlServiceBase
|
|
||||||
images_new: ImageService
|
images_new: ImageService
|
||||||
|
|
||||||
# NOTE: we must forward-declare any types that include invocations, since invocations can use services
|
# NOTE: we must forward-declare any types that include invocations, since invocations can use services
|
||||||
@ -41,10 +37,8 @@ class InvocationServices:
|
|||||||
logger: Logger,
|
logger: Logger,
|
||||||
latents: LatentsStorageBase,
|
latents: LatentsStorageBase,
|
||||||
images: ImageFileStorageBase,
|
images: ImageFileStorageBase,
|
||||||
metadata: MetadataServiceBase,
|
|
||||||
queue: InvocationQueueABC,
|
queue: InvocationQueueABC,
|
||||||
images_new: ImageService,
|
images_new: ImageService,
|
||||||
urls: UrlServiceBase,
|
|
||||||
graph_library: ItemStorageABC["LibraryGraph"],
|
graph_library: ItemStorageABC["LibraryGraph"],
|
||||||
graph_execution_manager: ItemStorageABC["GraphExecutionState"],
|
graph_execution_manager: ItemStorageABC["GraphExecutionState"],
|
||||||
processor: "InvocationProcessorABC",
|
processor: "InvocationProcessorABC",
|
||||||
@ -56,10 +50,8 @@ class InvocationServices:
|
|||||||
self.logger = logger
|
self.logger = logger
|
||||||
self.latents = latents
|
self.latents = latents
|
||||||
self.images = images
|
self.images = images
|
||||||
self.metadata = metadata
|
|
||||||
self.queue = queue
|
self.queue = queue
|
||||||
self.images_new = images_new
|
self.images_new = images_new
|
||||||
self.urls = urls
|
|
||||||
self.graph_library = graph_library
|
self.graph_library = graph_library
|
||||||
self.graph_execution_manager = graph_execution_manager
|
self.graph_execution_manager = graph_execution_manager
|
||||||
self.processor = processor
|
self.processor = processor
|
||||||
|
Loading…
Reference in New Issue
Block a user