YiYiXu commited on
Commit
a8fae71
·
verified ·
1 Parent(s): 12be2f2

Create block.py

Browse files
Files changed (1) hide show
  1. block.py +67 -0
block.py ADDED
@@ -0,0 +1,67 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ from typing import List
2
+
3
+ from diffusers.modular_pipelines import (
4
+ ComponentSpec,
5
+ InputParam,
6
+ ModularPipelineBlocks,
7
+ OutputParam,
8
+ PipelineState,
9
+ )
10
+
11
+
12
+ class MyCustomBlock(ModularPipelineBlocks):
13
+ """
14
+ A custom block for [describe what your block does].
15
+
16
+ Replace this with your implementation.
17
+ """
18
+
19
+ @property
20
+ def expected_components(self) -> List[ComponentSpec]:
21
+ """Define model components your block needs (e.g., transformers, VAEs)."""
22
+ return [
23
+ # Example:
24
+ # ComponentSpec(
25
+ # name="model",
26
+ # type_hint=SomeModelClass,
27
+ # repo="organization/model-name",
28
+ # ),
29
+ ]
30
+
31
+ @property
32
+ def inputs(self) -> List[InputParam]:
33
+ """Define input parameters for your block."""
34
+ return [
35
+ # Example:
36
+ # InputParam(
37
+ # "prompt",
38
+ # type_hint=str,
39
+ # required=True,
40
+ # description="Input prompt",
41
+ # metadata={"mellon": "textbox"}, # For Mellon UI
42
+ # ),
43
+ ]
44
+
45
+ @property
46
+ def intermediate_outputs(self) -> List[OutputParam]:
47
+ """Define output parameters for your block."""
48
+ return [
49
+ # Example:
50
+ # OutputParam(
51
+ # "result",
52
+ # type_hint=str,
53
+ # description="Output result",
54
+ # metadata={"mellon": "text"}, # For Mellon UI
55
+ # ),
56
+ ]
57
+
58
+ def __call__(self, components, state: PipelineState) -> PipelineState:
59
+ """Execute your block logic."""
60
+ block_state = self.get_block_state(state)
61
+
62
+ # Your implementation here
63
+ # Access inputs via block_state.<input_name>
64
+ # Set outputs via block_state.<output_name> = value
65
+
66
+ self.set_block_state(state, block_state)
67
+ return components, state