|
|
from typing import List |
|
|
|
|
|
from diffusers.modular_pipelines import ( |
|
|
ComponentSpec, |
|
|
InputParam, |
|
|
ModularPipelineBlocks, |
|
|
OutputParam, |
|
|
PipelineState, |
|
|
) |
|
|
|
|
|
|
|
|
class MyCustomBlock(ModularPipelineBlocks): |
|
|
""" |
|
|
A custom block for [describe what your block does]. |
|
|
|
|
|
Replace this with your implementation. |
|
|
""" |
|
|
|
|
|
@property |
|
|
def description(self) -> str: |
|
|
"""Description of the block.""" |
|
|
return "A template custom block - replace with your description" |
|
|
|
|
|
|
|
|
@property |
|
|
def expected_components(self) -> List[ComponentSpec]: |
|
|
"""Define model components your block needs (e.g., transformers, VAEs).""" |
|
|
return [ |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
] |
|
|
|
|
|
@property |
|
|
def inputs(self) -> List[InputParam]: |
|
|
"""Define input parameters for your block.""" |
|
|
return [ |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
] |
|
|
|
|
|
@property |
|
|
def intermediate_outputs(self) -> List[OutputParam]: |
|
|
"""Define output parameters for your block.""" |
|
|
return [ |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
] |
|
|
|
|
|
def __call__(self, components, state: PipelineState) -> PipelineState: |
|
|
"""Execute your block logic.""" |
|
|
block_state = self.get_block_state(state) |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
self.set_block_state(state, block_state) |
|
|
return components, state |