2022-12-01 05:33:20 +00:00
|
|
|
# Copyright (c) 2022 Kyle Schouviller (https://github.com/kyle0654)
|
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
|
|
|
|
from .image_storage import ImageStorageBase
|
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
|
2022-12-01 05:33:20 +00:00
|
|
|
|
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
|
|
|
|
images: ImageStorageBase
|
2023-02-25 04:11:28 +00:00
|
|
|
queue: InvocationQueueABC
|
2023-03-11 22:00:00 +00:00
|
|
|
model_manager: ModelManager
|
|
|
|
restoration: RestorationServices
|
2023-02-25 04:11:28 +00:00
|
|
|
|
|
|
|
# NOTE: we must forward-declare any types that include invocations, since invocations can use services
|
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-03-09 05:18:29 +00:00
|
|
|
self,
|
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
|
|
|
model_manager: ModelManager,
|
2023-03-09 05:18:29 +00:00
|
|
|
events: EventServiceBase,
|
|
|
|
images: ImageStorageBase,
|
|
|
|
queue: InvocationQueueABC,
|
|
|
|
graph_execution_manager: ItemStorageABC["GraphExecutionState"],
|
|
|
|
processor: "InvocationProcessorABC",
|
2023-03-11 22:00:00 +00:00
|
|
|
restoration: RestorationServices,
|
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
|
|
|
|
self.images = images
|
2023-02-25 04:11:28 +00:00
|
|
|
self.queue = queue
|
|
|
|
self.graph_execution_manager = graph_execution_manager
|
|
|
|
self.processor = processor
|
2023-03-11 22:00:00 +00:00
|
|
|
self.restoration = restoration
|