2023-04-29 14:48:50 +00:00
|
|
|
# Copyright (c) 2022 Kyle Schouviller (https://github.com/kyle0654) and the InvokeAI Team
|
2023-05-25 00:21:46 +00:00
|
|
|
from __future__ import annotations
|
2023-05-21 10:27:34 +00:00
|
|
|
from typing import TYPE_CHECKING
|
2023-05-17 09:13:53 +00:00
|
|
|
|
2023-05-21 10:27:34 +00:00
|
|
|
if TYPE_CHECKING:
|
2023-05-25 00:21:46 +00:00
|
|
|
from logging import Logger
|
|
|
|
from invokeai.app.services.images import ImageService
|
|
|
|
from invokeai.backend import ModelManager
|
|
|
|
from invokeai.app.services.events import EventServiceBase
|
|
|
|
from invokeai.app.services.latent_storage import LatentsStorageBase
|
|
|
|
from invokeai.app.services.restoration_services import RestorationServices
|
|
|
|
from invokeai.app.services.invocation_queue import InvocationQueueABC
|
|
|
|
from invokeai.app.services.item_storage import ItemStorageABC
|
|
|
|
from invokeai.app.services.config import InvokeAISettings
|
2023-05-21 10:27:34 +00:00
|
|
|
from invokeai.app.services.graph import GraphExecutionState, LibraryGraph
|
|
|
|
from invokeai.app.services.invoker import InvocationProcessorABC
|
|
|
|
|
|
|
|
|
2023-03-03 06:02:00 +00:00
|
|
|
class InvocationServices:
|
2022-12-01 05:33:20 +00:00
|
|
|
"""Services that can be used by invocations"""
|
2023-03-03 06:02:00 +00:00
|
|
|
|
2023-05-25 00:21:46 +00:00
|
|
|
# TODO: Just forward-declared everything due to circular dependencies. Fix structure.
|
|
|
|
events: "EventServiceBase"
|
|
|
|
latents: "LatentsStorageBase"
|
|
|
|
queue: "InvocationQueueABC"
|
|
|
|
model_manager: "ModelManager"
|
|
|
|
restoration: "RestorationServices"
|
|
|
|
configuration: "InvokeAISettings"
|
|
|
|
images: "ImageService"
|
2023-05-17 09:13:53 +00:00
|
|
|
|
2023-02-25 04:11:28 +00:00
|
|
|
# NOTE: we must forward-declare any types that include invocations, since invocations can use services
|
2023-05-25 00:21:46 +00:00
|
|
|
graph_library: "ItemStorageABC"["LibraryGraph"]
|
|
|
|
graph_execution_manager: "ItemStorageABC"["GraphExecutionState"]
|
2023-03-03 06:02:00 +00:00
|
|
|
processor: "InvocationProcessorABC"
|
2022-12-01 05:33:20 +00:00
|
|
|
|
2023-03-03 06:02:00 +00:00
|
|
|
def __init__(
|
2023-05-17 09:13:53 +00:00
|
|
|
self,
|
2023-05-25 00:21:46 +00:00
|
|
|
model_manager: "ModelManager",
|
|
|
|
events: "EventServiceBase",
|
|
|
|
logger: "Logger",
|
|
|
|
latents: "LatentsStorageBase",
|
|
|
|
images: "ImageService",
|
|
|
|
queue: "InvocationQueueABC",
|
|
|
|
graph_library: "ItemStorageABC"["LibraryGraph"],
|
|
|
|
graph_execution_manager: "ItemStorageABC"["GraphExecutionState"],
|
2023-05-17 09:13:53 +00:00
|
|
|
processor: "InvocationProcessorABC",
|
2023-05-25 00:21:46 +00:00
|
|
|
restoration: "RestorationServices",
|
|
|
|
configuration: "InvokeAISettings",
|
2022-12-01 05:33:20 +00:00
|
|
|
):
|
remove factory pattern
Factory pattern is now removed. Typical usage of the InvokeAIGenerator is now:
```
from invokeai.backend.generator import (
InvokeAIGeneratorBasicParams,
Txt2Img,
Img2Img,
Inpaint,
)
params = InvokeAIGeneratorBasicParams(
model_name = 'stable-diffusion-1.5',
steps = 30,
scheduler = 'k_lms',
cfg_scale = 8.0,
height = 640,
width = 640
)
print ('=== TXT2IMG TEST ===')
txt2img = Txt2Img(manager, params)
outputs = txt2img.generate(prompt='banana sushi', iterations=2)
for i in outputs:
print(f'image={output.image}, seed={output.seed}, model={output.params.model_name}, hash={output.model_hash}, steps={output.params.steps}')
```
The `params` argument is optional, so if you wish to accept default
parameters and selectively override them, just do this:
```
outputs = Txt2Img(manager).generate(prompt='banana sushi',
steps=50,
scheduler='k_heun',
model_name='stable-diffusion-2.1'
)
```
2023-03-11 00:33:04 +00:00
|
|
|
self.model_manager = model_manager
|
2022-12-01 05:33:20 +00:00
|
|
|
self.events = events
|
2023-04-29 14:48:50 +00:00
|
|
|
self.logger = logger
|
2023-04-06 04:06:05 +00:00
|
|
|
self.latents = latents
|
2022-12-01 05:33:20 +00:00
|
|
|
self.images = images
|
2023-02-25 04:11:28 +00:00
|
|
|
self.queue = queue
|
2023-04-14 06:41:06 +00:00
|
|
|
self.graph_library = graph_library
|
2023-02-25 04:11:28 +00:00
|
|
|
self.graph_execution_manager = graph_execution_manager
|
|
|
|
self.processor = processor
|
2023-03-11 22:00:00 +00:00
|
|
|
self.restoration = restoration
|
2023-05-04 02:30:30 +00:00
|
|
|
self.configuration = configuration
|