mirror of
https://github.com/invoke-ai/InvokeAI
synced 2024-08-30 20:32:17 +00:00
a514c9e28b
Update workflows handling for Workflow Library. **Updated Workflow Storage** "Embedded Workflows" are workflows associated with images, and are now only stored in the image files. "Library Workflows" are not associated with images, and are stored only in DB. This works out nicely. We have always saved workflows to files, but recently began saving them to the DB in addition to in image files. When that happened, we stopped reading workflows from files, so all the workflows that only existed in images were inaccessible. With this change, access to those workflows is restored, and no workflows are lost. **Updated Workflow Handling in Nodes** Prior to this change, workflows were embedded in images by passing the whole workflow JSON to a special workflow field on a node. In the node's `invoke()` function, the node was able to access this workflow and save it with the image. This (inaccurately) models workflows as a property of an image and is rather awkward technically. A workflow is now a property of a batch/session queue item. It is available in the InvocationContext and therefore available to all nodes during `invoke()`. **Database Migrations** Added a `SQLiteMigrator` class to handle database migrations. Migrations were needed to accomodate the DB-related changes in this PR. See the code for details. The `images`, `workflows` and `session_queue` tables required migrations for this PR, and are using the new migrator. Other tables/services are still creating tables themselves. A followup PR will adapt them to use the migrator. **Other/Support Changes** - Add a `has_workflow` column to `images` table to indicate that the image has an embedded workflow. - Add handling for retrieving the workflow from an image in python. The image file must be fetched, the workflow extracted, and then sent to client, avoiding needing the browser to parse the image file. With the `has_workflow` column, the UI knows if there is a workflow to be fetched, and only fetches when the user requests to load the workflow. - Add route to get the workflow from an image - Add CRUD service/routes for the library workflows - `workflow_images` table and services removed (no longer needed now that embedded workflows are not in the DB)
114 lines
4.9 KiB
Python
114 lines
4.9 KiB
Python
# Copyright (c) 2022 Kyle Schouviller (https://github.com/kyle0654) and the InvokeAI Team
|
|
from __future__ import annotations
|
|
|
|
from typing import TYPE_CHECKING
|
|
|
|
if TYPE_CHECKING:
|
|
from logging import Logger
|
|
|
|
from .board_image_records.board_image_records_base import BoardImageRecordStorageBase
|
|
from .board_images.board_images_base import BoardImagesServiceABC
|
|
from .board_records.board_records_base import BoardRecordStorageBase
|
|
from .boards.boards_base import BoardServiceABC
|
|
from .config import InvokeAIAppConfig
|
|
from .events.events_base import EventServiceBase
|
|
from .image_files.image_files_base import ImageFileStorageBase
|
|
from .image_records.image_records_base import ImageRecordStorageBase
|
|
from .images.images_base import ImageServiceABC
|
|
from .invocation_cache.invocation_cache_base import InvocationCacheBase
|
|
from .invocation_processor.invocation_processor_base import InvocationProcessorABC
|
|
from .invocation_queue.invocation_queue_base import InvocationQueueABC
|
|
from .invocation_stats.invocation_stats_base import InvocationStatsServiceBase
|
|
from .item_storage.item_storage_base import ItemStorageABC
|
|
from .latents_storage.latents_storage_base import LatentsStorageBase
|
|
from .model_manager.model_manager_base import ModelManagerServiceBase
|
|
from .model_records import ModelRecordServiceBase
|
|
from .names.names_base import NameServiceBase
|
|
from .session_processor.session_processor_base import SessionProcessorBase
|
|
from .session_queue.session_queue_base import SessionQueueBase
|
|
from .shared.graph import GraphExecutionState, LibraryGraph
|
|
from .urls.urls_base import UrlServiceBase
|
|
from .workflow_records.workflow_records_base import WorkflowRecordsStorageBase
|
|
|
|
|
|
class InvocationServices:
|
|
"""Services that can be used by invocations"""
|
|
|
|
# TODO: Just forward-declared everything due to circular dependencies. Fix structure.
|
|
board_images: "BoardImagesServiceABC"
|
|
board_image_record_storage: "BoardImageRecordStorageBase"
|
|
boards: "BoardServiceABC"
|
|
board_records: "BoardRecordStorageBase"
|
|
configuration: "InvokeAIAppConfig"
|
|
events: "EventServiceBase"
|
|
graph_execution_manager: "ItemStorageABC[GraphExecutionState]"
|
|
graph_library: "ItemStorageABC[LibraryGraph]"
|
|
images: "ImageServiceABC"
|
|
image_records: "ImageRecordStorageBase"
|
|
image_files: "ImageFileStorageBase"
|
|
latents: "LatentsStorageBase"
|
|
logger: "Logger"
|
|
model_manager: "ModelManagerServiceBase"
|
|
model_records: "ModelRecordServiceBase"
|
|
processor: "InvocationProcessorABC"
|
|
performance_statistics: "InvocationStatsServiceBase"
|
|
queue: "InvocationQueueABC"
|
|
session_queue: "SessionQueueBase"
|
|
session_processor: "SessionProcessorBase"
|
|
invocation_cache: "InvocationCacheBase"
|
|
names: "NameServiceBase"
|
|
urls: "UrlServiceBase"
|
|
workflow_records: "WorkflowRecordsStorageBase"
|
|
|
|
def __init__(
|
|
self,
|
|
board_images: "BoardImagesServiceABC",
|
|
board_image_records: "BoardImageRecordStorageBase",
|
|
boards: "BoardServiceABC",
|
|
board_records: "BoardRecordStorageBase",
|
|
configuration: "InvokeAIAppConfig",
|
|
events: "EventServiceBase",
|
|
graph_execution_manager: "ItemStorageABC[GraphExecutionState]",
|
|
graph_library: "ItemStorageABC[LibraryGraph]",
|
|
images: "ImageServiceABC",
|
|
image_files: "ImageFileStorageBase",
|
|
image_records: "ImageRecordStorageBase",
|
|
latents: "LatentsStorageBase",
|
|
logger: "Logger",
|
|
model_manager: "ModelManagerServiceBase",
|
|
model_records: "ModelRecordServiceBase",
|
|
processor: "InvocationProcessorABC",
|
|
performance_statistics: "InvocationStatsServiceBase",
|
|
queue: "InvocationQueueABC",
|
|
session_queue: "SessionQueueBase",
|
|
session_processor: "SessionProcessorBase",
|
|
invocation_cache: "InvocationCacheBase",
|
|
names: "NameServiceBase",
|
|
urls: "UrlServiceBase",
|
|
workflow_records: "WorkflowRecordsStorageBase",
|
|
):
|
|
self.board_images = board_images
|
|
self.board_image_records = board_image_records
|
|
self.boards = boards
|
|
self.board_records = board_records
|
|
self.configuration = configuration
|
|
self.events = events
|
|
self.graph_execution_manager = graph_execution_manager
|
|
self.graph_library = graph_library
|
|
self.images = images
|
|
self.image_files = image_files
|
|
self.image_records = image_records
|
|
self.latents = latents
|
|
self.logger = logger
|
|
self.model_manager = model_manager
|
|
self.model_records = model_records
|
|
self.processor = processor
|
|
self.performance_statistics = performance_statistics
|
|
self.queue = queue
|
|
self.session_queue = session_queue
|
|
self.session_processor = session_processor
|
|
self.invocation_cache = invocation_cache
|
|
self.names = names
|
|
self.urls = urls
|
|
self.workflow_records = workflow_records
|