2023-04-29 14:48:50 +00:00
|
|
|
# Copyright (c) 2022 Kyle Schouviller (https://github.com/kyle0654) and the InvokeAI Team
|
2023-05-21 10:27:34 +00:00
|
|
|
from typing import TYPE_CHECKING
|
2023-05-21 10:24:37 +00:00
|
|
|
from logging import Logger
|
2023-05-21 10:27:34 +00:00
|
|
|
|
2023-05-17 09:13:53 +00:00
|
|
|
from invokeai.app.services.images import ImageService
|
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
|
|
|
from invokeai.backend import ModelManager
|
2023-03-03 06:02:00 +00:00
|
|
|
from .events import EventServiceBase
|
2023-04-06 04:06:05 +00:00
|
|
|
from .latent_storage import LatentsStorageBase
|
2023-03-11 22:00:00 +00:00
|
|
|
from .restoration_services import RestorationServices
|
2023-02-25 04:11:28 +00:00
|
|
|
from .invocation_queue import InvocationQueueABC
|
|
|
|
from .item_storage import ItemStorageABC
|
2023-05-04 02:30:30 +00:00
|
|
|
from .config import InvokeAISettings
|
2022-12-01 05:33:20 +00:00
|
|
|
|
2023-05-17 09:13:53 +00:00
|
|
|
|
2023-05-21 10:27:34 +00:00
|
|
|
if TYPE_CHECKING:
|
|
|
|
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
|
|
|
|
2022-12-01 05:33:20 +00:00
|
|
|
events: EventServiceBase
|
2023-04-06 04:06:05 +00:00
|
|
|
latents: LatentsStorageBase
|
2023-02-25 04:11:28 +00:00
|
|
|
queue: InvocationQueueABC
|
2023-03-11 22:00:00 +00:00
|
|
|
model_manager: ModelManager
|
|
|
|
restoration: RestorationServices
|
2023-05-04 02:30:30 +00:00
|
|
|
configuration: InvokeAISettings
|
2023-05-24 05:50:55 +00:00
|
|
|
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-04-14 06:41:06 +00:00
|
|
|
graph_library: ItemStorageABC["LibraryGraph"]
|
2023-03-03 06:02:00 +00:00
|
|
|
graph_execution_manager: ItemStorageABC["GraphExecutionState"]
|
|
|
|
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,
|
|
|
|
model_manager: ModelManager,
|
|
|
|
events: EventServiceBase,
|
2023-05-21 10:24:37 +00:00
|
|
|
logger: Logger,
|
2023-05-17 09:13:53 +00:00
|
|
|
latents: LatentsStorageBase,
|
2023-05-24 05:50:55 +00:00
|
|
|
images: ImageService,
|
2023-05-17 09:13:53 +00:00
|
|
|
queue: InvocationQueueABC,
|
|
|
|
graph_library: ItemStorageABC["LibraryGraph"],
|
|
|
|
graph_execution_manager: ItemStorageABC["GraphExecutionState"],
|
|
|
|
processor: "InvocationProcessorABC",
|
|
|
|
restoration: RestorationServices,
|
|
|
|
configuration: InvokeAISettings=None,
|
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
|
2023-05-17 09:13:53 +00:00
|
|
|
|
|
|
|
|