RioShiina commited on
Commit
478e753
·
verified ·
1 Parent(s): b5d0250

Add ControlNet, DiffSynth ControlNet & VAE injectors

Browse files
chain_injectors/controlnet_injector.py ADDED
@@ -0,0 +1,60 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ def inject(assembler, chain_definition, chain_items):
2
+ if not chain_items:
3
+ return
4
+
5
+ ksampler_name = chain_definition.get('ksampler_node', 'ksampler')
6
+ if ksampler_name not in assembler.node_map:
7
+ print(f"Warning: Target node '{ksampler_name}' for ControlNet chain not found. Skipping chain injection.")
8
+ return
9
+
10
+ ksampler_id = assembler.node_map[ksampler_name]
11
+
12
+ if 'positive' not in assembler.workflow[ksampler_id]['inputs'] or \
13
+ 'negative' not in assembler.workflow[ksampler_id]['inputs']:
14
+ print(f"Warning: KSampler node '{ksampler_name}' is missing 'positive' or 'negative' inputs. Skipping ControlNet chain.")
15
+ return
16
+
17
+ vae_source_str = chain_definition.get('vae_source')
18
+ if not vae_source_str:
19
+ print("Warning: 'vae_source' definition missing in the recipe for the ControlNet chain. Skipping.")
20
+ return
21
+ vae_node_name, vae_idx_str = vae_source_str.split(':')
22
+ if vae_node_name not in assembler.node_map:
23
+ print(f"Warning: VAE source node '{vae_node_name}' for ControlNet chain not found. Skipping.")
24
+ return
25
+ vae_connection = [assembler.node_map[vae_node_name], int(vae_idx_str)]
26
+
27
+ current_positive_connection = assembler.workflow[ksampler_id]['inputs']['positive']
28
+ current_negative_connection = assembler.workflow[ksampler_id]['inputs']['negative']
29
+
30
+ for item_data in chain_items:
31
+ cn_loader_id = assembler._get_unique_id()
32
+ cn_loader_node = assembler._get_node_template("ControlNetLoader")
33
+ cn_loader_node['inputs']['control_net_name'] = item_data['control_net_name']
34
+ assembler.workflow[cn_loader_id] = cn_loader_node
35
+
36
+ image_loader_id = assembler._get_unique_id()
37
+ image_loader_node = assembler._get_node_template("LoadImage")
38
+ image_loader_node['inputs']['image'] = item_data['image']
39
+ assembler.workflow[image_loader_id] = image_loader_node
40
+
41
+ apply_cn_id = assembler._get_unique_id()
42
+ apply_cn_node = assembler._get_node_template(chain_definition['template'])
43
+
44
+ apply_cn_node['inputs']['strength'] = item_data['strength']
45
+
46
+ apply_cn_node['inputs']['positive'] = current_positive_connection
47
+ apply_cn_node['inputs']['negative'] = current_negative_connection
48
+ apply_cn_node['inputs']['control_net'] = [cn_loader_id, 0]
49
+ apply_cn_node['inputs']['image'] = [image_loader_id, 0]
50
+ apply_cn_node['inputs']['vae'] = vae_connection
51
+
52
+ assembler.workflow[apply_cn_id] = apply_cn_node
53
+
54
+ current_positive_connection = [apply_cn_id, 0]
55
+ current_negative_connection = [apply_cn_id, 1]
56
+
57
+ assembler.workflow[ksampler_id]['inputs']['positive'] = current_positive_connection
58
+ assembler.workflow[ksampler_id]['inputs']['negative'] = current_negative_connection
59
+
60
+ print(f"ControlNet injector applied. KSampler inputs redirected through {len(chain_items)} ControlNet nodes.")
chain_injectors/diffsynth_controlnet_injector.py ADDED
@@ -0,0 +1,75 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ def inject(assembler, chain_definition, chain_items):
2
+ if not chain_items:
3
+ return
4
+
5
+ model_sampler_name = chain_definition.get('model_sampler_node')
6
+ ksampler_name = chain_definition.get('ksampler_node', 'ksampler')
7
+
8
+ target_node_id = None
9
+ target_input_name = 'model'
10
+
11
+ if model_sampler_name and model_sampler_name in assembler.node_map:
12
+ model_sampler_id = assembler.node_map[model_sampler_name]
13
+ if target_input_name in assembler.workflow[model_sampler_id]['inputs']:
14
+ target_node_id = model_sampler_id
15
+ print(f"ControlNet Model Patch injector targeting ModelSamplingAuraFlow node '{model_sampler_name}'.")
16
+
17
+ if not target_node_id:
18
+ if ksampler_name in assembler.node_map:
19
+ ksampler_id = assembler.node_map[ksampler_name]
20
+ if target_input_name in assembler.workflow[ksampler_id]['inputs']:
21
+ target_node_id = ksampler_id
22
+ print(f"ControlNet Model Patch injector targeting KSampler node '{ksampler_name}'.")
23
+ else:
24
+ print(f"Warning: Neither ModelSamplingAuraFlow node '{model_sampler_name}' nor KSampler node '{ksampler_name}' found for ControlNet patch chain. Skipping.")
25
+ return
26
+
27
+ if not target_node_id:
28
+ print(f"Warning: Could not find a valid 'model' input on target nodes. Skipping ControlNet patch chain.")
29
+ return
30
+
31
+ current_model_connection = assembler.workflow[target_node_id]['inputs'][target_input_name]
32
+
33
+ vae_source_str = chain_definition.get('vae_source')
34
+ vae_connection = None
35
+ if vae_source_str:
36
+ try:
37
+ vae_node_name, vae_idx_str = vae_source_str.split(':')
38
+ if vae_node_name in assembler.node_map:
39
+ vae_connection = [assembler.node_map[vae_node_name], int(vae_idx_str)]
40
+ else:
41
+ print(f"Warning: VAE source node '{vae_node_name}' not found for ControlNet patch chain. VAE will not be connected.")
42
+ except ValueError:
43
+ print(f"Warning: Invalid 'vae_source' format '{vae_source_str}' for ControlNet patch chain. Expected 'node_name:index'. VAE will not be connected.")
44
+ else:
45
+ print(f"Warning: 'vae_source' not defined for ControlNet patch chain definition. VAE may not be connected.")
46
+
47
+ for item_data in chain_items:
48
+ patch_loader_id = assembler._get_unique_id()
49
+ patch_loader_node = assembler._get_node_template("ModelPatchLoader")
50
+ patch_loader_node['inputs']['name'] = item_data['control_net_name']
51
+ assembler.workflow[patch_loader_id] = patch_loader_node
52
+
53
+ image_loader_id = assembler._get_unique_id()
54
+ image_loader_node = assembler._get_node_template("LoadImage")
55
+ image_loader_node['inputs']['image'] = item_data['image']
56
+ assembler.workflow[image_loader_id] = image_loader_node
57
+
58
+ apply_cn_id = assembler._get_unique_id()
59
+ apply_cn_node = assembler._get_node_template(chain_definition['template'])
60
+
61
+ apply_cn_node['inputs']['strength'] = item_data.get('strength', 1.0)
62
+ apply_cn_node['inputs']['model'] = current_model_connection
63
+ apply_cn_node['inputs']['model_patch'] = [patch_loader_id, 0]
64
+ apply_cn_node['inputs']['image'] = [image_loader_id, 0]
65
+
66
+ if 'vae' in apply_cn_node['inputs'] and vae_connection:
67
+ apply_cn_node['inputs']['vae'] = vae_connection
68
+
69
+ assembler.workflow[apply_cn_id] = apply_cn_node
70
+
71
+ current_model_connection = [apply_cn_id, 0]
72
+
73
+ assembler.workflow[target_node_id]['inputs'][target_input_name] = current_model_connection
74
+
75
+ print(f"ControlNet Model Patch injector applied. Target 'model' input re-routed through {len(chain_items)} patch(es).")
chain_injectors/vae_injector.py ADDED
@@ -0,0 +1,30 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ def inject(assembler, chain_definition, chain_items):
2
+ if not chain_items:
3
+ return
4
+
5
+ vae_name = chain_items[0] if isinstance(chain_items, list) else chain_items
6
+ if not vae_name or vae_name == "None":
7
+ return
8
+
9
+ targets = chain_definition.get('targets', [])
10
+ if not targets:
11
+ return
12
+
13
+ vae_loader_id = assembler._get_unique_id()
14
+ vae_loader_node = assembler._get_node_template("VAELoader")
15
+ vae_loader_node['inputs']['vae_name'] = vae_name
16
+ assembler.workflow[vae_loader_id] = vae_loader_node
17
+
18
+ injected_count = 0
19
+ for target_str in targets:
20
+ try:
21
+ node_name, input_name = target_str.split(':')
22
+ if node_name in assembler.node_map:
23
+ node_id = assembler.node_map[node_name]
24
+ assembler.workflow[node_id]['inputs'][input_name] = [vae_loader_id, 0]
25
+ injected_count += 1
26
+ except ValueError:
27
+ print(f"Warning: Invalid VAE injector target format '{target_str}'. Expected 'node_name:input_name'.")
28
+
29
+ if injected_count > 0:
30
+ print(f"VAE injector applied. Rerouted {injected_count} connection(s) to new VAELoader ({vae_name}).")
yaml/controlnet_models.yaml ADDED
@@ -0,0 +1,177 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ ControlNet:
2
+ Qwen-Image:
3
+ - Filepath: "Qwen-Image-InstantX-ControlNet-Union.safetensors"
4
+ Series: "InstantX Union"
5
+ Type: ["Canny", "Soft Edge", "Depth", "Pose"]
6
+ FLUX.1:
7
+ - Filepath: "FLUX.1-dev-ControlNet-Union-Pro-2.0.safetensors"
8
+ Series: "Shakker Labs Union Pro"
9
+ Type: ["Canny", "Tile", "Depth", "Blur", "Pose", "Gray", "Low Quality"]
10
+ - Filepath: "flux-canny-controlnet-v3.safetensors"
11
+ Series: "XLabs-AI"
12
+ Type: ["Canny"]
13
+ - Filepath: "flux-depth-controlnet-v3.safetensors"
14
+ Series: "XLabs-AI"
15
+ Type: ["Depth (Midas)"]
16
+ - Filepath: "flux-hed-controlnet-v3.safetensors"
17
+ Series: "XLabs-AI"
18
+ Type: ["HED"]
19
+ SD3.5:
20
+ - Filepath: "sd3.5_large_controlnet_blur.safetensors"
21
+ Series: "[Large] StabilityAI"
22
+ Type: ["Blur"]
23
+ - Filepath: "sd3.5_large_controlnet_canny.safetensors"
24
+ Series: "[Large] StabilityAI"
25
+ Type: ["Canny"]
26
+ - Filepath: "sd3.5_large_controlnet_depth.safetensors"
27
+ Series: "[Large] StabilityAI"
28
+ Type: ["Depth"]
29
+ SDXL:
30
+ - Filepath: "controlnet-union-sdxl-1.0_promax.safetensors"
31
+ Series: "xinsir Union"
32
+ Type: ["Tile Deblur", "Tile variation", "Tile Super Resolution", "Image Inpainting", "Image Outpainting", "OpenPose", "Depth", "Canny", "Lineart", "Anime Lineart", "Mlsd", "Scribble", "Hed", "Pidi(Softedge)", "Teed", "Segment", "Normal"]
33
+ - Filepath: "controlnet-tile-sdxl-1.0.safetensors"
34
+ Series: "xinsir"
35
+ Type: ["Tile"]
36
+ - Filepath: "controlnet-canny-sdxl-1.0_V2.safetensors"
37
+ Series: "xinsir"
38
+ Type: ["Canny"]
39
+ - Filepath: "controlnet-openpose-sdxl-1.0.safetensors"
40
+ Series: "xinsir"
41
+ Type: ["OpenPose"]
42
+ - Filepath: "controlnet-openpose-sdxl-1.0.safetensors"
43
+ Series: "xinsir"
44
+ Type: ["OpenPose(Twins)"]
45
+ - Filepath: "controlnet-depth-sdxl-1.0"
46
+ Series: "xinsir"
47
+ Type: ["Depth"]
48
+ - Filepath: "controlnet-scribble-sdxl-1.0.safetensors"
49
+ Series: "xinsir"
50
+ Type: ["Scribble"]
51
+ - Filepath: "anime-painter.safetensors"
52
+ Series: "xinsir"
53
+ Type: ["Anime Painter"]
54
+ # SDXL-NoobAI
55
+ - Filepath: "noob_sdxl_controlnet_canny.fp16.safetensors"
56
+ Series: "NoobAI"
57
+ Type: ["Canny"]
58
+ - Filepath: "noob_sdxl_controlnet_depth.fp16.safetensors"
59
+ Series: "NoobAI"
60
+ Type: ["Depth"]
61
+ - Filepath: "noob-sdxl-controlnet-lineart_anime.fp16.safetensors"
62
+ Series: "NoobAI"
63
+ Type: ["Anime Lineart"]
64
+ - Filepath: "noob-sdxl-controlnet-lineart_realistic.fp16.safetensors"
65
+ Series: "NoobAI"
66
+ Type: ["Realistic Lineart"]
67
+ - Filepath: "noob-sdxl-controlnet-manga_line.fp16.safetensors"
68
+ Series: "NoobAI"
69
+ Type: ["Manga Lineart"]
70
+ - Filepath: "noob-sdxl-controlnet-normal.fp16.safetensors"
71
+ Series: "NoobAI"
72
+ Type: ["Normal"]
73
+ - Filepath: "noob-sdxl-controlnet-softedge_hed.fp16.safetensors"
74
+ Series: "NoobAI"
75
+ Type: ["SoftEdge (HED)"]
76
+ - Filepath: "noob-sdxl-controlnet-tile.fp16.safetensors"
77
+ Series: "NoobAI"
78
+ Type: ["Tile"]
79
+ - Filepath: "NoobAI_Inpainting_ControlNet.safetensors"
80
+ Series: "NoobAI"
81
+ Type: ["Inpainting"]
82
+ - Filepath: "noob_openpose_pre.safetensors"
83
+ Series: "NoobAI"
84
+ Type: ["OpenPose"]
85
+ - Filepath: "noobaiXLControlnet_epsDepthMidasV11.safetensors"
86
+ Series: "NoobAI"
87
+ Type: ["Depth (Midas)"]
88
+ - Filepath: "noobaiXLControlnet_epsNormalMidas.safetensors"
89
+ Series: "NoobAI"
90
+ Type: ["Normal (Midas)"]
91
+ - Filepath: "noobaiXLControlnet_epsScribbleHed.safetensors"
92
+ Series: "NoobAI"
93
+ Type: ["Scribble (HED)"]
94
+ - Filepath: "noobaiXLControlnet_epsScribblePidinet.safetensors"
95
+ Series: "NoobAI"
96
+ Type: ["Scribble (PiDiNet)"]
97
+ - Filepath: "noobaiXLControlnet_epsDepthMidas.safetensors"
98
+ Series: "NoobAI"
99
+ Type: ["Depth (Midas)"]
100
+ - Filepath: "noobaiXLControlnet_openposeModel.safetensors"
101
+ Series: "NoobAI"
102
+ Type: ["OpenPose"]
103
+ # SDXL - Illustrious-XL-v0.1
104
+ - Filepath: "illustriousXLv0.1_Canny_fp16.safetensors"
105
+ Series: "MIC-Lab/illustriousXLv0.1_controlnet"
106
+ Type: ["Canny"]
107
+ - Filepath: "illustriousXLv0.1_Lineart_fp16.safetensors"
108
+ Series: "MIC-Lab/illustriousXLv0.1_controlnet"
109
+ Type: ["Lineart"]
110
+ - Filepath: "illustriousXLv0.1_Softedge_fp16.safetensors"
111
+ Series: "MIC-Lab/illustriousXLv0.1_controlnet"
112
+ Type: ["SoftEdge"]
113
+ - Filepath: "illustriousXLv0.1_Tile_fp16.safetensors"
114
+ Series: "MIC-Lab/illustriousXLv0.1_controlnet"
115
+ Type: ["Tile"]
116
+ - Filepath: "illustriousXLv0.1_depth_midas_fp16.safetensors"
117
+ Series: "MIC-Lab/illustriousXLv0.1_controlnet"
118
+ Type: ["Depth (Midas)"]
119
+ - Filepath: "illustriousXLv0.1_inpainting_fp16.safetensors"
120
+ Series: "MIC-Lab/illustriousXLv0.1_controlnet"
121
+ Type: ["Inpainting"]
122
+ # SDXL - Illustrious-XL-v1.1
123
+ - Filepath: "illustriousXLv1.1_canny_fp16.safetensors"
124
+ Series: "MIC-Lab/illustriousXLv1.1_controlnet"
125
+ Type: ["Canny"]
126
+ - Filepath: "illustriousXLv1.1_depth_midas_fp16.safetensors"
127
+ Series: "MIC-Lab/illustriousXLv1.1_controlnet"
128
+ Type: ["Depth (Midas)"]
129
+ - Filepath: "illustriousXLv1.1_inpainting_fp16.safetensors"
130
+ Series: "MIC-Lab/illustriousXLv1.1_controlnet"
131
+ Type: ["Inpainting"]
132
+ - Filepath: "illustriousXLv1.1_tile_fp16.safetensors"
133
+ Series: "MIC-Lab/illustriousXLv1.1_controlnet"
134
+ Type: ["Tile"]
135
+ SD1.5:
136
+ - Filepath: "control_v11p_sd15_canny_fp16.safetensors"
137
+ Series: "Standard"
138
+ Type: ["Canny"]
139
+ - Filepath: "control_v11f1p_sd15_depth_fp16.safetensors"
140
+ Series: "Standard"
141
+ Type: ["Depth"]
142
+ - Filepath: "control_v11p_sd15_openpose_fp16.safetensors"
143
+ Series: "Standard"
144
+ Type: ["OpenPose"]
145
+ - Filepath: "control_v11p_sd15_lineart_fp16.safetensors"
146
+ Series: "Standard"
147
+ Type: ["Lineart"]
148
+ - Filepath: "control_v11p_sd15_softedge_fp16.safetensors"
149
+ Series: "Standard"
150
+ Type: ["SoftEdge"]
151
+ - Filepath: "control_v11p_sd15_scribble_fp16.safetensors"
152
+ Series: "Standard"
153
+ Type: ["Scribble"]
154
+ - Filepath: "control_v11p_sd15_seg_fp16.safetensors"
155
+ Series: "Standard"
156
+ Type: ["Segmentation"]
157
+ - Filepath: "control_v11p_sd15_normalbae_fp16.safetensors"
158
+ Series: "Standard"
159
+ Type: ["Normal BAE"]
160
+ - Filepath: "control_v11p_sd15_mlsd_fp16.safetensors"
161
+ Series: "Standard"
162
+ Type: ["MLSD"]
163
+ - Filepath: "control_v11p_sd15_inpaint_fp16.safetensors"
164
+ Series: "Standard"
165
+ Type: ["Inpaint"]
166
+ - Filepath: "control_v11f1e_sd15_tile_fp16.safetensors"
167
+ Series: "Standard"
168
+ Type: ["Tile"]
169
+ - Filepath: "control_v11e_sd15_shuffle_fp16.safetensors"
170
+ Series: "Standard"
171
+ Type: ["Shuffle"]
172
+ - Filepath: "control_v11e_sd15_ip2p_fp16.safetensors"
173
+ Series: "Standard"
174
+ Type: ["Instruct P2P"]
175
+ - Filepath: "control_v11p_sd15s2_lineart_anime_fp16.safetensors"
176
+ Series: "Standard"
177
+ Type: ["Anime Lineart"]
yaml/diffsynth_controlnet_models.yaml ADDED
@@ -0,0 +1,8 @@
 
 
 
 
 
 
 
 
 
1
+ DiffSynth_ControlNet:
2
+ Z-Image:
3
+ - Filepath: "Z-Image-Turbo-Fun-Controlnet-Union-2.1-8steps.safetensors"
4
+ Series: "alibaba-pai Controlnet Union 2.1 8steps"
5
+ Type: ["Pose", "Canny", "HED", "Depth", "MLSD"]
6
+ - Filepath: "Z-Image-Turbo-Fun-Controlnet-Tile-2.1-8steps.safetensors"
7
+ Series: "alibaba-pai Controlnet Union 2.1 8steps"
8
+ Type: ["Tile"]