Create custom_blocks.py
Browse files- custom_blocks.py +42 -0
custom_blocks.py
ADDED
|
@@ -0,0 +1,42 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
from diffusers import FluxTransformer2DModel
|
| 2 |
+
from diffusers.modular_pipelines import ModularPipelineBlocks, ComponentSpec, InputParam, PipelineState, OutputParam
|
| 3 |
+
from typing import List
|
| 4 |
+
|
| 5 |
+
class DummyCustomBlockSimple(ModularPipelineBlocks):
|
| 6 |
+
def __init__(self, use_dummy_model_component=False):
|
| 7 |
+
self.use_dummy_model_component = use_dummy_model_component
|
| 8 |
+
super().__init__()
|
| 9 |
+
|
| 10 |
+
@property
|
| 11 |
+
def expected_components(self):
|
| 12 |
+
if self.use_dummy_model_component:
|
| 13 |
+
return [ComponentSpec("transformer", FluxTransformer2DModel)]
|
| 14 |
+
else:
|
| 15 |
+
return []
|
| 16 |
+
|
| 17 |
+
@property
|
| 18 |
+
def inputs(self) -> List[InputParam]:
|
| 19 |
+
return [InputParam("prompt", type_hint=str, required=True, description="Prompt to use")]
|
| 20 |
+
|
| 21 |
+
@property
|
| 22 |
+
def intermediate_inputs(self) -> List[InputParam]:
|
| 23 |
+
return []
|
| 24 |
+
|
| 25 |
+
@property
|
| 26 |
+
def intermediate_outputs(self) -> List[OutputParam]:
|
| 27 |
+
return [
|
| 28 |
+
OutputParam(
|
| 29 |
+
"output_prompt",
|
| 30 |
+
type_hint=str,
|
| 31 |
+
description="Modified prompt",
|
| 32 |
+
)
|
| 33 |
+
]
|
| 34 |
+
|
| 35 |
+
def __call__(self, components, state: PipelineState) -> PipelineState:
|
| 36 |
+
block_state = self.get_block_state(state)
|
| 37 |
+
|
| 38 |
+
old_prompt = block_state.prompt
|
| 39 |
+
block_state.output_prompt = "Modular diffusers + " + old_prompt
|
| 40 |
+
self.set_block_state(state, block_state)
|
| 41 |
+
|
| 42 |
+
return components, state
|