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
|
||||
import os
|
||||
from types import ModuleType
|
||||
from invokeai.app.services.image_record_storage import SqliteImageRecordStorage
|
||||
from invokeai.app.services.images import ImageService
|
||||
from invokeai.app.services.urls import LocalUrlService
|
||||
@ -20,7 +19,6 @@ from ..services.invoker import Invoker
|
||||
from ..services.processor import DefaultInvocationProcessor
|
||||
from ..services.sqlite import SqliteItemStorage
|
||||
from ..services.metadata import PngMetadataService
|
||||
from ..services.results import SqliteResultsService
|
||||
from .events import FastAPIEventService
|
||||
|
||||
|
||||
@ -83,19 +81,15 @@ class ApiDependencies:
|
||||
image_file_storage=image_file_storage,
|
||||
metadata=metadata,
|
||||
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(
|
||||
model_manager=get_model_manager(config, logger),
|
||||
events=events,
|
||||
latents=latents,
|
||||
images=images,
|
||||
images=image_file_storage,
|
||||
images_new=images_new,
|
||||
metadata=metadata,
|
||||
urls=urls,
|
||||
queue=MemoryInvocationQueue(),
|
||||
graph_library=SqliteItemStorage[LibraryGraph](
|
||||
filename=db_location, table_name="graphs"
|
||||
|
@ -1,3 +1,4 @@
|
||||
from logging import Logger
|
||||
from typing import Optional, Union
|
||||
import uuid
|
||||
from PIL.Image import Image as PILImageType
|
||||
@ -28,6 +29,7 @@ class ImageServiceDependencies:
|
||||
files: ImageFileStorageBase
|
||||
metadata: MetadataServiceBase
|
||||
urls: UrlServiceBase
|
||||
logger: Logger
|
||||
|
||||
def __init__(
|
||||
self,
|
||||
@ -35,11 +37,13 @@ class ImageServiceDependencies:
|
||||
image_file_storage: ImageFileStorageBase,
|
||||
metadata: MetadataServiceBase,
|
||||
url: UrlServiceBase,
|
||||
logger: Logger,
|
||||
):
|
||||
self.records = image_record_storage
|
||||
self.files = image_file_storage
|
||||
self.metadata = metadata
|
||||
self.urls = url
|
||||
self.logger = logger
|
||||
|
||||
|
||||
class ImageService:
|
||||
@ -53,12 +57,14 @@ class ImageService:
|
||||
image_file_storage: ImageFileStorageBase,
|
||||
metadata: MetadataServiceBase,
|
||||
url: UrlServiceBase,
|
||||
logger: Logger,
|
||||
):
|
||||
self._services = ImageServiceDependencies(
|
||||
image_record_storage=image_record_storage,
|
||||
image_file_storage=image_file_storage,
|
||||
metadata=metadata,
|
||||
url=url,
|
||||
logger=logger,
|
||||
)
|
||||
|
||||
def _create_image_name(
|
||||
@ -117,7 +123,9 @@ class ImageService:
|
||||
)
|
||||
|
||||
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(
|
||||
image_name=image_name,
|
||||
@ -131,10 +139,10 @@ class ImageService:
|
||||
thumbnail_url=thumbnail_url,
|
||||
)
|
||||
except ImageRecordStorageBase.ImageRecordSaveException:
|
||||
# TODO: log this
|
||||
self._services.logger.error("Failed to save image record")
|
||||
raise
|
||||
except ImageFileStorageBase.ImageFileSaveException:
|
||||
# TODO: log this
|
||||
self._services.logger.error("Failed to save image file")
|
||||
raise
|
||||
|
||||
def get_pil_image(self, image_type: ImageType, image_name: str) -> PILImageType:
|
||||
@ -142,7 +150,7 @@ class ImageService:
|
||||
try:
|
||||
return self._services.files.get(image_type, image_name)
|
||||
except ImageFileStorageBase.ImageFileNotFoundException:
|
||||
# TODO: log this
|
||||
self._services.logger.error("Failed to get image file")
|
||||
raise
|
||||
|
||||
def get_record(self, image_type: ImageType, image_name: str) -> ImageRecord:
|
||||
@ -150,7 +158,7 @@ class ImageService:
|
||||
try:
|
||||
return self._services.records.get(image_type, image_name)
|
||||
except ImageRecordStorageBase.ImageRecordNotFoundException:
|
||||
# TODO: log this
|
||||
self._services.logger.error("Failed to get image record")
|
||||
raise
|
||||
|
||||
def get_dto(self, image_type: ImageType, image_name: str) -> ImageDTO:
|
||||
@ -166,7 +174,7 @@ class ImageService:
|
||||
|
||||
return image_dto
|
||||
except ImageRecordStorageBase.ImageRecordNotFoundException:
|
||||
# TODO: log this
|
||||
self._services.logger.error("Failed to get image DTO")
|
||||
raise
|
||||
|
||||
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.records.delete(image_type, image_name)
|
||||
except ImageRecordStorageBase.ImageRecordDeleteException:
|
||||
# TODO: log this
|
||||
self._services.logger.error(f"Failed to delete image record")
|
||||
raise
|
||||
except ImageFileStorageBase.ImageFileDeleteException:
|
||||
# TODO: log this
|
||||
self._services.logger.error(f"Failed to delete image file")
|
||||
raise
|
||||
|
||||
def get_many(
|
||||
@ -217,6 +225,7 @@ class ImageService:
|
||||
total=results.total,
|
||||
)
|
||||
except Exception as e:
|
||||
self._services.logger.error("Failed to get paginated image DTOs")
|
||||
raise e
|
||||
|
||||
def add_tag(self, image_type: ImageType, image_id: str, tag: str) -> None:
|
||||
|
@ -2,8 +2,6 @@
|
||||
|
||||
from logging import Logger
|
||||
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 .events import EventServiceBase
|
||||
@ -21,12 +19,10 @@ class InvocationServices:
|
||||
events: EventServiceBase
|
||||
latents: LatentsStorageBase
|
||||
images: ImageFileStorageBase
|
||||
metadata: MetadataServiceBase
|
||||
queue: InvocationQueueABC
|
||||
model_manager: ModelManager
|
||||
restoration: RestorationServices
|
||||
configuration: InvokeAISettings
|
||||
urls: UrlServiceBase
|
||||
images_new: ImageService
|
||||
|
||||
# NOTE: we must forward-declare any types that include invocations, since invocations can use services
|
||||
@ -41,10 +37,8 @@ class InvocationServices:
|
||||
logger: Logger,
|
||||
latents: LatentsStorageBase,
|
||||
images: ImageFileStorageBase,
|
||||
metadata: MetadataServiceBase,
|
||||
queue: InvocationQueueABC,
|
||||
images_new: ImageService,
|
||||
urls: UrlServiceBase,
|
||||
graph_library: ItemStorageABC["LibraryGraph"],
|
||||
graph_execution_manager: ItemStorageABC["GraphExecutionState"],
|
||||
processor: "InvocationProcessorABC",
|
||||
@ -56,10 +50,8 @@ class InvocationServices:
|
||||
self.logger = logger
|
||||
self.latents = latents
|
||||
self.images = images
|
||||
self.metadata = metadata
|
||||
self.queue = queue
|
||||
self.images_new = images_new
|
||||
self.urls = urls
|
||||
self.graph_library = graph_library
|
||||
self.graph_execution_manager = graph_execution_manager
|
||||
self.processor = processor
|
||||
|
Loading…
Reference in New Issue
Block a user