gartajackhats1985 commited on
Commit
21d588d
1 Parent(s): c37b2dd

Upload 85 files

Browse files
This view is limited to 50 files because it contains too many changes.   See raw diff
Files changed (50) hide show
  1. ComfyUI-InstantID/.github/FUNDING.yml +13 -0
  2. ComfyUI-InstantID/INSTANTID WORKFLOWS/V1.0 InstantID + ArtGallery【Zho】.json +615 -0
  3. ComfyUI-InstantID/INSTANTID WORKFLOWS/V1.0 InstantID_fromhub【Zho】.json +400 -0
  4. ComfyUI-InstantID/INSTANTID WORKFLOWS/V1.0 InstantID_locally【Zho】.json +400 -0
  5. ComfyUI-InstantID/INSTANTID WORKFLOWS/V2.0 InstantID_fromhub_pose_ref【Zho】.json +451 -0
  6. ComfyUI-InstantID/INSTANTID WORKFLOWS/V2.0 InstantID_locally_pose_ref【Zho】.json +452 -0
  7. ComfyUI-InstantID/INSTANTID WORKFLOWS/V2.0 InstantID_pose_ref + ArtGallery 【Zho】.json +665 -0
  8. ComfyUI-InstantID/InstantIDNode.py +352 -0
  9. ComfyUI-InstantID/README.md +213 -0
  10. ComfyUI-InstantID/__init__.py +3 -0
  11. ComfyUI-InstantID/__pycache__/InstantIDNode.cpython-312.pyc +0 -0
  12. ComfyUI-InstantID/__pycache__/__init__.cpython-312.pyc +0 -0
  13. ComfyUI-InstantID/__pycache__/pipeline_stable_diffusion_xl_instantid.cpython-312.pyc +0 -0
  14. ComfyUI-InstantID/__pycache__/style_template.cpython-312.pyc +0 -0
  15. ComfyUI-InstantID/checkpoints/put_models_here.txt +1 -0
  16. ComfyUI-InstantID/ip_adapter/__pycache__/attention_processor.cpython-312.pyc +0 -0
  17. ComfyUI-InstantID/ip_adapter/__pycache__/resampler.cpython-312.pyc +0 -0
  18. ComfyUI-InstantID/ip_adapter/__pycache__/utils.cpython-312.pyc +0 -0
  19. ComfyUI-InstantID/ip_adapter/attention_processor.py +308 -0
  20. ComfyUI-InstantID/ip_adapter/resampler.py +121 -0
  21. ComfyUI-InstantID/ip_adapter/utils.py +5 -0
  22. ComfyUI-InstantID/models/antelopev2/1k3d68.onnx +3 -0
  23. ComfyUI-InstantID/models/antelopev2/2d106det.onnx +3 -0
  24. ComfyUI-InstantID/models/antelopev2/genderage.onnx +3 -0
  25. ComfyUI-InstantID/models/antelopev2/glintr100.onnx +3 -0
  26. ComfyUI-InstantID/models/antelopev2/scrfd_10g_bnkps.onnx +3 -0
  27. ComfyUI-InstantID/pipeline_stable_diffusion_xl_instantid.py +753 -0
  28. ComfyUI-InstantID/requirements.txt +6 -0
  29. ComfyUI-InstantID/style_template.py +49 -0
  30. ComfyUI-KJNodes/.github/FUNDING.yml +2 -0
  31. ComfyUI-KJNodes/.github/workflows/publish.yml +21 -0
  32. ComfyUI-KJNodes/.gitignore +11 -0
  33. ComfyUI-KJNodes/LICENSE +674 -0
  34. ComfyUI-KJNodes/README.md +65 -0
  35. ComfyUI-KJNodes/__init__.py +195 -0
  36. ComfyUI-KJNodes/__pycache__/__init__.cpython-312.pyc +0 -0
  37. ComfyUI-KJNodes/config.json +3 -0
  38. ComfyUI-KJNodes/custom_dimensions.json +22 -0
  39. ComfyUI-KJNodes/docs/images/2024-04-03_20_49_29-ComfyUI.png +0 -0
  40. ComfyUI-KJNodes/docs/images/319121566-05f66385-7568-4b1f-8bbc-11053660b02f.png +0 -0
  41. ComfyUI-KJNodes/docs/images/319121636-706b5081-9120-4a29-bd76-901691ada688.png +0 -0
  42. ComfyUI-KJNodes/fonts/FreeMono.ttf +0 -0
  43. ComfyUI-KJNodes/fonts/FreeMonoBoldOblique.otf +0 -0
  44. ComfyUI-KJNodes/fonts/TTNorms-Black.otf +0 -0
  45. ComfyUI-KJNodes/intrinsic_loras/intrinsic_lora_sd15_albedo.safetensors +3 -0
  46. ComfyUI-KJNodes/intrinsic_loras/intrinsic_lora_sd15_depth.safetensors +3 -0
  47. ComfyUI-KJNodes/intrinsic_loras/intrinsic_lora_sd15_normal.safetensors +3 -0
  48. ComfyUI-KJNodes/intrinsic_loras/intrinsic_lora_sd15_shading.safetensors +3 -0
  49. ComfyUI-KJNodes/intrinsic_loras/intrinsic_loras.txt +4 -0
  50. ComfyUI-KJNodes/kjweb_async/marked.min.js +6 -0
ComfyUI-InstantID/.github/FUNDING.yml ADDED
@@ -0,0 +1,13 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ # These are supported funding model platforms
2
+
3
+ github: # Replace with up to 4 GitHub Sponsors-enabled usernames e.g., [user1, user2]
4
+ patreon: # Replace with a single Patreon username
5
+ open_collective: # Replace with a single Open Collective username
6
+ ko_fi: # Replace with a single Ko-fi username
7
+ tidelift: # Replace with a single Tidelift platform-name/package-name e.g., npm/babel
8
+ community_bridge: # Replace with a single Community Bridge project-name e.g., cloud-foundry
9
+ liberapay: # Replace with a single Liberapay username
10
+ issuehunt: # Replace with a single IssueHunt username
11
+ otechie: # Replace with a single Otechie username
12
+ lfx_crowdfunding: # Replace with a single LFX Crowdfunding project-name e.g., cloud-foundry
13
+ custom: https://afdian.net/a/ZHOZHO # Replace with up to 4 custom sponsorship URLs e.g., ['link1', 'link2']
ComfyUI-InstantID/INSTANTID WORKFLOWS/V1.0 InstantID + ArtGallery【Zho】.json ADDED
@@ -0,0 +1,615 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ {
2
+ "last_node_id": 21,
3
+ "last_link_id": 41,
4
+ "nodes": [
5
+ {
6
+ "id": 6,
7
+ "type": "LoadImage",
8
+ "pos": [
9
+ 100,
10
+ 1770
11
+ ],
12
+ "size": {
13
+ "0": 380,
14
+ "1": 500
15
+ },
16
+ "flags": {},
17
+ "order": 0,
18
+ "mode": 0,
19
+ "outputs": [
20
+ {
21
+ "name": "IMAGE",
22
+ "type": "IMAGE",
23
+ "links": [
24
+ 31
25
+ ],
26
+ "shape": 3
27
+ },
28
+ {
29
+ "name": "MASK",
30
+ "type": "MASK",
31
+ "links": null,
32
+ "shape": 3
33
+ }
34
+ ],
35
+ "properties": {
36
+ "Node name for S&R": "LoadImage"
37
+ },
38
+ "widgets_values": [
39
+ "download.jpg",
40
+ "image"
41
+ ]
42
+ },
43
+ {
44
+ "id": 16,
45
+ "type": "IDBaseModelLoader_fromhub",
46
+ "pos": [
47
+ 100,
48
+ 1420
49
+ ],
50
+ "size": {
51
+ "0": 290,
52
+ "1": 60
53
+ },
54
+ "flags": {},
55
+ "order": 5,
56
+ "mode": 0,
57
+ "inputs": [
58
+ {
59
+ "name": "controlnet",
60
+ "type": "MODEL",
61
+ "link": 33
62
+ }
63
+ ],
64
+ "outputs": [
65
+ {
66
+ "name": "pipe",
67
+ "type": "MODEL",
68
+ "links": [
69
+ 34
70
+ ],
71
+ "shape": 3,
72
+ "slot_index": 0
73
+ }
74
+ ],
75
+ "properties": {
76
+ "Node name for S&R": "IDBaseModelLoader_fromhub"
77
+ },
78
+ "widgets_values": [
79
+ "wangqixun/YamerMIX_v8"
80
+ ]
81
+ },
82
+ {
83
+ "id": 11,
84
+ "type": "InsightFaceLoader",
85
+ "pos": [
86
+ 100,
87
+ 1660
88
+ ],
89
+ "size": {
90
+ "0": 290,
91
+ "1": 60
92
+ },
93
+ "flags": {},
94
+ "order": 1,
95
+ "mode": 0,
96
+ "outputs": [
97
+ {
98
+ "name": "INSIGHTFACE",
99
+ "type": "INSIGHTFACE",
100
+ "links": [
101
+ 29
102
+ ],
103
+ "shape": 3,
104
+ "slot_index": 0
105
+ }
106
+ ],
107
+ "properties": {
108
+ "Node name for S&R": "InsightFaceLoader"
109
+ },
110
+ "widgets_values": [
111
+ "CUDA"
112
+ ]
113
+ },
114
+ {
115
+ "id": 4,
116
+ "type": "Ipadapter_instantidLoader",
117
+ "pos": [
118
+ 98,
119
+ 1526
120
+ ],
121
+ "size": {
122
+ "0": 290,
123
+ "1": 90
124
+ },
125
+ "flags": {},
126
+ "order": 7,
127
+ "mode": 0,
128
+ "inputs": [
129
+ {
130
+ "name": "pipe",
131
+ "type": "MODEL",
132
+ "link": 34
133
+ }
134
+ ],
135
+ "outputs": [
136
+ {
137
+ "name": "MODEL",
138
+ "type": "MODEL",
139
+ "links": [
140
+ 30
141
+ ],
142
+ "shape": 3,
143
+ "slot_index": 0
144
+ }
145
+ ],
146
+ "properties": {
147
+ "Node name for S&R": "Ipadapter_instantidLoader"
148
+ },
149
+ "widgets_values": [
150
+ "/content/ComfyUI/models/checkpoints",
151
+ "ip-adapter.bin"
152
+ ]
153
+ },
154
+ {
155
+ "id": 2,
156
+ "type": "IDControlNetLoader",
157
+ "pos": [
158
+ 100,
159
+ 1320
160
+ ],
161
+ "size": {
162
+ "0": 290,
163
+ "1": 60
164
+ },
165
+ "flags": {},
166
+ "order": 2,
167
+ "mode": 0,
168
+ "outputs": [
169
+ {
170
+ "name": "controlnet",
171
+ "type": "MODEL",
172
+ "links": [
173
+ 33
174
+ ],
175
+ "shape": 3,
176
+ "slot_index": 0
177
+ }
178
+ ],
179
+ "properties": {
180
+ "Node name for S&R": "IDControlNetLoader"
181
+ },
182
+ "widgets_values": [
183
+ "/content/ComfyUI/models/controlnet"
184
+ ]
185
+ },
186
+ {
187
+ "id": 12,
188
+ "type": "PreviewImage",
189
+ "pos": [
190
+ 500,
191
+ 1770
192
+ ],
193
+ "size": {
194
+ "0": 470,
195
+ "1": 500
196
+ },
197
+ "flags": {},
198
+ "order": 11,
199
+ "mode": 0,
200
+ "inputs": [
201
+ {
202
+ "name": "images",
203
+ "type": "IMAGE",
204
+ "link": 32
205
+ }
206
+ ],
207
+ "properties": {
208
+ "Node name for S&R": "PreviewImage"
209
+ }
210
+ },
211
+ {
212
+ "id": 18,
213
+ "type": "ArtistsImage_Zho",
214
+ "pos": [
215
+ 410,
216
+ 1320
217
+ ],
218
+ "size": [
219
+ 300,
220
+ 400
221
+ ],
222
+ "flags": {},
223
+ "order": 3,
224
+ "mode": 0,
225
+ "outputs": [
226
+ {
227
+ "name": "name",
228
+ "type": "STRING",
229
+ "links": [
230
+ 40
231
+ ],
232
+ "shape": 3,
233
+ "slot_index": 0
234
+ },
235
+ {
236
+ "name": "image",
237
+ "type": "IMAGE",
238
+ "links": null,
239
+ "shape": 3,
240
+ "slot_index": 1
241
+ }
242
+ ],
243
+ "properties": {
244
+ "Node name for S&R": "ArtistsImage_Zho"
245
+ },
246
+ "widgets_values": [
247
+ "Alphonse Osbert .png",
248
+ 1.2
249
+ ]
250
+ },
251
+ {
252
+ "id": 20,
253
+ "type": "MovementsImage_Zho",
254
+ "pos": [
255
+ 730,
256
+ 1320
257
+ ],
258
+ "size": [
259
+ 300,
260
+ 400
261
+ ],
262
+ "flags": {},
263
+ "order": 4,
264
+ "mode": 0,
265
+ "outputs": [
266
+ {
267
+ "name": "name",
268
+ "type": "STRING",
269
+ "links": [
270
+ 39
271
+ ],
272
+ "shape": 3,
273
+ "slot_index": 0
274
+ },
275
+ {
276
+ "name": "image",
277
+ "type": "IMAGE",
278
+ "links": null,
279
+ "shape": 3
280
+ }
281
+ ],
282
+ "properties": {
283
+ "Node name for S&R": "MovementsImage_Zho"
284
+ },
285
+ "widgets_values": [
286
+ "Gutai Group.png",
287
+ 0.6
288
+ ]
289
+ },
290
+ {
291
+ "id": 9,
292
+ "type": "ID_Prompt_Styler",
293
+ "pos": [
294
+ 1050,
295
+ 1570
296
+ ],
297
+ "size": [
298
+ 230,
299
+ 150
300
+ ],
301
+ "flags": {},
302
+ "order": 9,
303
+ "mode": 0,
304
+ "inputs": [
305
+ {
306
+ "name": "prompt",
307
+ "type": "STRING",
308
+ "link": 36,
309
+ "widget": {
310
+ "name": "prompt"
311
+ }
312
+ }
313
+ ],
314
+ "outputs": [
315
+ {
316
+ "name": "positive_prompt",
317
+ "type": "STRING",
318
+ "links": [
319
+ 28
320
+ ],
321
+ "shape": 3,
322
+ "slot_index": 0
323
+ },
324
+ {
325
+ "name": "negative_prompt",
326
+ "type": "STRING",
327
+ "links": [
328
+ 27
329
+ ],
330
+ "shape": 3,
331
+ "slot_index": 1
332
+ }
333
+ ],
334
+ "properties": {
335
+ "Node name for S&R": "ID_Prompt_Styler"
336
+ },
337
+ "widgets_values": [
338
+ " a woman, retro futurism, retro game",
339
+ "(lowres, low quality, worst quality:1.2), (text:1.2), watermark, painting, drawing, illustration, glitch, deformed, mutated, cross-eyed, ugly, disfigured (lowres, low quality, worst quality:1.2), (text:1.2), watermark, painting, drawing, illustration, glitch,deformed, mutated, cross-eyed, ugly, disfigured",
340
+ "Neon"
341
+ ]
342
+ },
343
+ {
344
+ "id": 19,
345
+ "type": "ConcatText_Zho",
346
+ "pos": [
347
+ 1050,
348
+ 1420
349
+ ],
350
+ "size": [
351
+ 230,
352
+ 100
353
+ ],
354
+ "flags": {},
355
+ "order": 8,
356
+ "mode": 0,
357
+ "inputs": [
358
+ {
359
+ "name": "text_1",
360
+ "type": "STRING",
361
+ "link": 41,
362
+ "widget": {
363
+ "name": "text_1"
364
+ }
365
+ }
366
+ ],
367
+ "outputs": [
368
+ {
369
+ "name": "text",
370
+ "type": "STRING",
371
+ "links": [
372
+ 36
373
+ ],
374
+ "shape": 3,
375
+ "slot_index": 0
376
+ }
377
+ ],
378
+ "properties": {
379
+ "Node name for S&R": "ConcatText_Zho"
380
+ },
381
+ "widgets_values": [
382
+ "",
383
+ " a woman, retro futurism, retro game"
384
+ ]
385
+ },
386
+ {
387
+ "id": 21,
388
+ "type": "ConcatText_Zho",
389
+ "pos": [
390
+ 1050,
391
+ 1320
392
+ ],
393
+ "size": [
394
+ 230,
395
+ 50
396
+ ],
397
+ "flags": {},
398
+ "order": 6,
399
+ "mode": 0,
400
+ "inputs": [
401
+ {
402
+ "name": "text_1",
403
+ "type": "STRING",
404
+ "link": 40,
405
+ "widget": {
406
+ "name": "text_1"
407
+ }
408
+ },
409
+ {
410
+ "name": "text_2",
411
+ "type": "STRING",
412
+ "link": 39,
413
+ "widget": {
414
+ "name": "text_2"
415
+ }
416
+ }
417
+ ],
418
+ "outputs": [
419
+ {
420
+ "name": "text",
421
+ "type": "STRING",
422
+ "links": [
423
+ 41
424
+ ],
425
+ "shape": 3,
426
+ "slot_index": 0
427
+ }
428
+ ],
429
+ "properties": {
430
+ "Node name for S&R": "ConcatText_Zho"
431
+ },
432
+ "widgets_values": [
433
+ "",
434
+ " a woman, retro futurism, retro game"
435
+ ]
436
+ },
437
+ {
438
+ "id": 15,
439
+ "type": "IDGenerationNode",
440
+ "pos": [
441
+ 990,
442
+ 1770
443
+ ],
444
+ "size": [
445
+ 290,
446
+ 500
447
+ ],
448
+ "flags": {},
449
+ "order": 10,
450
+ "mode": 0,
451
+ "inputs": [
452
+ {
453
+ "name": "face_image",
454
+ "type": "IMAGE",
455
+ "link": 31,
456
+ "slot_index": 0
457
+ },
458
+ {
459
+ "name": "pipe",
460
+ "type": "MODEL",
461
+ "link": 30
462
+ },
463
+ {
464
+ "name": "insightface",
465
+ "type": "INSIGHTFACE",
466
+ "link": 29
467
+ },
468
+ {
469
+ "name": "positive",
470
+ "type": "STRING",
471
+ "link": 28,
472
+ "widget": {
473
+ "name": "positive"
474
+ }
475
+ },
476
+ {
477
+ "name": "negative",
478
+ "type": "STRING",
479
+ "link": 27,
480
+ "widget": {
481
+ "name": "negative"
482
+ }
483
+ }
484
+ ],
485
+ "outputs": [
486
+ {
487
+ "name": "IMAGE",
488
+ "type": "IMAGE",
489
+ "links": [
490
+ 32
491
+ ],
492
+ "shape": 3,
493
+ "slot_index": 0
494
+ }
495
+ ],
496
+ "properties": {
497
+ "Node name for S&R": "IDGenerationNode"
498
+ },
499
+ "widgets_values": [
500
+ "",
501
+ "",
502
+ 0.8,
503
+ 0.8,
504
+ 50,
505
+ 5,
506
+ 1024,
507
+ 1024,
508
+ 780847710635035,
509
+ "randomize"
510
+ ]
511
+ }
512
+ ],
513
+ "links": [
514
+ [
515
+ 27,
516
+ 9,
517
+ 1,
518
+ 15,
519
+ 4,
520
+ "STRING"
521
+ ],
522
+ [
523
+ 28,
524
+ 9,
525
+ 0,
526
+ 15,
527
+ 3,
528
+ "STRING"
529
+ ],
530
+ [
531
+ 29,
532
+ 11,
533
+ 0,
534
+ 15,
535
+ 2,
536
+ "INSIGHTFACE"
537
+ ],
538
+ [
539
+ 30,
540
+ 4,
541
+ 0,
542
+ 15,
543
+ 1,
544
+ "MODEL"
545
+ ],
546
+ [
547
+ 31,
548
+ 6,
549
+ 0,
550
+ 15,
551
+ 0,
552
+ "IMAGE"
553
+ ],
554
+ [
555
+ 32,
556
+ 15,
557
+ 0,
558
+ 12,
559
+ 0,
560
+ "IMAGE"
561
+ ],
562
+ [
563
+ 33,
564
+ 2,
565
+ 0,
566
+ 16,
567
+ 0,
568
+ "MODEL"
569
+ ],
570
+ [
571
+ 34,
572
+ 16,
573
+ 0,
574
+ 4,
575
+ 0,
576
+ "MODEL"
577
+ ],
578
+ [
579
+ 36,
580
+ 19,
581
+ 0,
582
+ 9,
583
+ 0,
584
+ "STRING"
585
+ ],
586
+ [
587
+ 39,
588
+ 20,
589
+ 0,
590
+ 21,
591
+ 1,
592
+ "STRING"
593
+ ],
594
+ [
595
+ 40,
596
+ 18,
597
+ 0,
598
+ 21,
599
+ 0,
600
+ "STRING"
601
+ ],
602
+ [
603
+ 41,
604
+ 21,
605
+ 0,
606
+ 19,
607
+ 0,
608
+ "STRING"
609
+ ]
610
+ ],
611
+ "groups": [],
612
+ "config": {},
613
+ "extra": {},
614
+ "version": 0.4
615
+ }
ComfyUI-InstantID/INSTANTID WORKFLOWS/V1.0 InstantID_fromhub【Zho】.json ADDED
@@ -0,0 +1,400 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ {
2
+ "last_node_id": 16,
3
+ "last_link_id": 34,
4
+ "nodes": [
5
+ {
6
+ "id": 6,
7
+ "type": "LoadImage",
8
+ "pos": [
9
+ 100,
10
+ 1770
11
+ ],
12
+ "size": {
13
+ "0": 380,
14
+ "1": 500
15
+ },
16
+ "flags": {},
17
+ "order": 0,
18
+ "mode": 0,
19
+ "outputs": [
20
+ {
21
+ "name": "IMAGE",
22
+ "type": "IMAGE",
23
+ "links": [
24
+ 31
25
+ ],
26
+ "shape": 3
27
+ },
28
+ {
29
+ "name": "MASK",
30
+ "type": "MASK",
31
+ "links": null,
32
+ "shape": 3
33
+ }
34
+ ],
35
+ "properties": {
36
+ "Node name for S&R": "LoadImage"
37
+ },
38
+ "widgets_values": [
39
+ "download.jpg",
40
+ "image"
41
+ ]
42
+ },
43
+ {
44
+ "id": 15,
45
+ "type": "IDGenerationNode",
46
+ "pos": [
47
+ 690,
48
+ 1320
49
+ ],
50
+ "size": [
51
+ 280,
52
+ 400
53
+ ],
54
+ "flags": {},
55
+ "order": 6,
56
+ "mode": 0,
57
+ "inputs": [
58
+ {
59
+ "name": "face_image",
60
+ "type": "IMAGE",
61
+ "link": 31,
62
+ "slot_index": 0
63
+ },
64
+ {
65
+ "name": "pipe",
66
+ "type": "MODEL",
67
+ "link": 30
68
+ },
69
+ {
70
+ "name": "insightface",
71
+ "type": "INSIGHTFACE",
72
+ "link": 29
73
+ },
74
+ {
75
+ "name": "positive",
76
+ "type": "STRING",
77
+ "link": 28,
78
+ "widget": {
79
+ "name": "positive"
80
+ }
81
+ },
82
+ {
83
+ "name": "negative",
84
+ "type": "STRING",
85
+ "link": 27,
86
+ "widget": {
87
+ "name": "negative"
88
+ }
89
+ }
90
+ ],
91
+ "outputs": [
92
+ {
93
+ "name": "IMAGE",
94
+ "type": "IMAGE",
95
+ "links": [
96
+ 32
97
+ ],
98
+ "shape": 3,
99
+ "slot_index": 0
100
+ }
101
+ ],
102
+ "properties": {
103
+ "Node name for S&R": "IDGenerationNode"
104
+ },
105
+ "widgets_values": [
106
+ "",
107
+ "",
108
+ 0.8,
109
+ 0.8,
110
+ 50,
111
+ 5,
112
+ 1024,
113
+ 1024,
114
+ 1010461052994244,
115
+ "randomize"
116
+ ]
117
+ },
118
+ {
119
+ "id": 16,
120
+ "type": "IDBaseModelLoader_fromhub",
121
+ "pos": [
122
+ 100,
123
+ 1420
124
+ ],
125
+ "size": [
126
+ 290,
127
+ 60
128
+ ],
129
+ "flags": {},
130
+ "order": 4,
131
+ "mode": 0,
132
+ "inputs": [
133
+ {
134
+ "name": "controlnet",
135
+ "type": "MODEL",
136
+ "link": 33
137
+ }
138
+ ],
139
+ "outputs": [
140
+ {
141
+ "name": "pipe",
142
+ "type": "MODEL",
143
+ "links": [
144
+ 34
145
+ ],
146
+ "shape": 3,
147
+ "slot_index": 0
148
+ }
149
+ ],
150
+ "properties": {
151
+ "Node name for S&R": "IDBaseModelLoader_fromhub"
152
+ },
153
+ "widgets_values": [
154
+ "wangqixun/YamerMIX_v8"
155
+ ]
156
+ },
157
+ {
158
+ "id": 11,
159
+ "type": "InsightFaceLoader",
160
+ "pos": [
161
+ 100,
162
+ 1660
163
+ ],
164
+ "size": [
165
+ 290,
166
+ 60
167
+ ],
168
+ "flags": {},
169
+ "order": 1,
170
+ "mode": 0,
171
+ "outputs": [
172
+ {
173
+ "name": "INSIGHTFACE",
174
+ "type": "INSIGHTFACE",
175
+ "links": [
176
+ 29
177
+ ],
178
+ "shape": 3,
179
+ "slot_index": 0
180
+ }
181
+ ],
182
+ "properties": {
183
+ "Node name for S&R": "InsightFaceLoader"
184
+ },
185
+ "widgets_values": [
186
+ "CUDA"
187
+ ]
188
+ },
189
+ {
190
+ "id": 2,
191
+ "type": "IDControlNetLoader",
192
+ "pos": [
193
+ 100,
194
+ 1320
195
+ ],
196
+ "size": [
197
+ 290,
198
+ 60
199
+ ],
200
+ "flags": {},
201
+ "order": 2,
202
+ "mode": 0,
203
+ "outputs": [
204
+ {
205
+ "name": "controlnet",
206
+ "type": "MODEL",
207
+ "links": [
208
+ 33
209
+ ],
210
+ "shape": 3,
211
+ "slot_index": 0
212
+ }
213
+ ],
214
+ "properties": {
215
+ "Node name for S&R": "IDControlNetLoader"
216
+ },
217
+ "widgets_values": [
218
+ "/content/ComfyUI/models/controlnet"
219
+ ]
220
+ },
221
+ {
222
+ "id": 12,
223
+ "type": "PreviewImage",
224
+ "pos": [
225
+ 500,
226
+ 1770
227
+ ],
228
+ "size": {
229
+ "0": 470,
230
+ "1": 500
231
+ },
232
+ "flags": {},
233
+ "order": 7,
234
+ "mode": 0,
235
+ "inputs": [
236
+ {
237
+ "name": "images",
238
+ "type": "IMAGE",
239
+ "link": 32
240
+ }
241
+ ],
242
+ "properties": {
243
+ "Node name for S&R": "PreviewImage"
244
+ }
245
+ },
246
+ {
247
+ "id": 9,
248
+ "type": "ID_Prompt_Styler",
249
+ "pos": [
250
+ 410,
251
+ 1320
252
+ ],
253
+ "size": [
254
+ 260,
255
+ 400
256
+ ],
257
+ "flags": {},
258
+ "order": 3,
259
+ "mode": 0,
260
+ "outputs": [
261
+ {
262
+ "name": "positive_prompt",
263
+ "type": "STRING",
264
+ "links": [
265
+ 28
266
+ ],
267
+ "shape": 3,
268
+ "slot_index": 0
269
+ },
270
+ {
271
+ "name": "negative_prompt",
272
+ "type": "STRING",
273
+ "links": [
274
+ 27
275
+ ],
276
+ "shape": 3,
277
+ "slot_index": 1
278
+ }
279
+ ],
280
+ "properties": {
281
+ "Node name for S&R": "ID_Prompt_Styler"
282
+ },
283
+ "widgets_values": [
284
+ " a woman, retro futurism, retro game",
285
+ "(lowres, low quality, worst quality:1.2), (text:1.2), watermark, painting, drawing, illustration, glitch, deformed, mutated, cross-eyed, ugly, disfigured (lowres, low quality, worst quality:1.2), (text:1.2), watermark, painting, drawing, illustration, glitch,deformed, mutated, cross-eyed, ugly, disfigured",
286
+ "Snow"
287
+ ]
288
+ },
289
+ {
290
+ "id": 4,
291
+ "type": "Ipadapter_instantidLoader",
292
+ "pos": [
293
+ 98,
294
+ 1526
295
+ ],
296
+ "size": [
297
+ 290,
298
+ 90
299
+ ],
300
+ "flags": {},
301
+ "order": 5,
302
+ "mode": 0,
303
+ "inputs": [
304
+ {
305
+ "name": "pipe",
306
+ "type": "MODEL",
307
+ "link": 34
308
+ }
309
+ ],
310
+ "outputs": [
311
+ {
312
+ "name": "MODEL",
313
+ "type": "MODEL",
314
+ "links": [
315
+ 30
316
+ ],
317
+ "shape": 3,
318
+ "slot_index": 0
319
+ }
320
+ ],
321
+ "properties": {
322
+ "Node name for S&R": "Ipadapter_instantidLoader"
323
+ },
324
+ "widgets_values": [
325
+ "/content/ComfyUI/models/checkpoints",
326
+ "ip-adapter.bin"
327
+ ]
328
+ }
329
+ ],
330
+ "links": [
331
+ [
332
+ 27,
333
+ 9,
334
+ 1,
335
+ 15,
336
+ 4,
337
+ "STRING"
338
+ ],
339
+ [
340
+ 28,
341
+ 9,
342
+ 0,
343
+ 15,
344
+ 3,
345
+ "STRING"
346
+ ],
347
+ [
348
+ 29,
349
+ 11,
350
+ 0,
351
+ 15,
352
+ 2,
353
+ "INSIGHTFACE"
354
+ ],
355
+ [
356
+ 30,
357
+ 4,
358
+ 0,
359
+ 15,
360
+ 1,
361
+ "MODEL"
362
+ ],
363
+ [
364
+ 31,
365
+ 6,
366
+ 0,
367
+ 15,
368
+ 0,
369
+ "IMAGE"
370
+ ],
371
+ [
372
+ 32,
373
+ 15,
374
+ 0,
375
+ 12,
376
+ 0,
377
+ "IMAGE"
378
+ ],
379
+ [
380
+ 33,
381
+ 2,
382
+ 0,
383
+ 16,
384
+ 0,
385
+ "MODEL"
386
+ ],
387
+ [
388
+ 34,
389
+ 16,
390
+ 0,
391
+ 4,
392
+ 0,
393
+ "MODEL"
394
+ ]
395
+ ],
396
+ "groups": [],
397
+ "config": {},
398
+ "extra": {},
399
+ "version": 0.4
400
+ }
ComfyUI-InstantID/INSTANTID WORKFLOWS/V1.0 InstantID_locally【Zho】.json ADDED
@@ -0,0 +1,400 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ {
2
+ "last_node_id": 17,
3
+ "last_link_id": 36,
4
+ "nodes": [
5
+ {
6
+ "id": 6,
7
+ "type": "LoadImage",
8
+ "pos": [
9
+ 100,
10
+ 1770
11
+ ],
12
+ "size": {
13
+ "0": 380,
14
+ "1": 500
15
+ },
16
+ "flags": {},
17
+ "order": 0,
18
+ "mode": 0,
19
+ "outputs": [
20
+ {
21
+ "name": "IMAGE",
22
+ "type": "IMAGE",
23
+ "links": [
24
+ 31
25
+ ],
26
+ "shape": 3
27
+ },
28
+ {
29
+ "name": "MASK",
30
+ "type": "MASK",
31
+ "links": null,
32
+ "shape": 3
33
+ }
34
+ ],
35
+ "properties": {
36
+ "Node name for S&R": "LoadImage"
37
+ },
38
+ "widgets_values": [
39
+ "download.jpg",
40
+ "image"
41
+ ]
42
+ },
43
+ {
44
+ "id": 15,
45
+ "type": "IDGenerationNode",
46
+ "pos": [
47
+ 690,
48
+ 1320
49
+ ],
50
+ "size": [
51
+ 280,
52
+ 400
53
+ ],
54
+ "flags": {},
55
+ "order": 6,
56
+ "mode": 0,
57
+ "inputs": [
58
+ {
59
+ "name": "face_image",
60
+ "type": "IMAGE",
61
+ "link": 31,
62
+ "slot_index": 0
63
+ },
64
+ {
65
+ "name": "pipe",
66
+ "type": "MODEL",
67
+ "link": 30
68
+ },
69
+ {
70
+ "name": "insightface",
71
+ "type": "INSIGHTFACE",
72
+ "link": 29
73
+ },
74
+ {
75
+ "name": "positive",
76
+ "type": "STRING",
77
+ "link": 28,
78
+ "widget": {
79
+ "name": "positive"
80
+ }
81
+ },
82
+ {
83
+ "name": "negative",
84
+ "type": "STRING",
85
+ "link": 27,
86
+ "widget": {
87
+ "name": "negative"
88
+ }
89
+ }
90
+ ],
91
+ "outputs": [
92
+ {
93
+ "name": "IMAGE",
94
+ "type": "IMAGE",
95
+ "links": [
96
+ 32
97
+ ],
98
+ "shape": 3,
99
+ "slot_index": 0
100
+ }
101
+ ],
102
+ "properties": {
103
+ "Node name for S&R": "IDGenerationNode"
104
+ },
105
+ "widgets_values": [
106
+ "",
107
+ "",
108
+ 0.8,
109
+ 0.8,
110
+ 50,
111
+ 5,
112
+ 1024,
113
+ 1024,
114
+ 836332103938257,
115
+ "randomize"
116
+ ]
117
+ },
118
+ {
119
+ "id": 11,
120
+ "type": "InsightFaceLoader",
121
+ "pos": [
122
+ 100,
123
+ 1660
124
+ ],
125
+ "size": [
126
+ 290,
127
+ 60
128
+ ],
129
+ "flags": {},
130
+ "order": 1,
131
+ "mode": 0,
132
+ "outputs": [
133
+ {
134
+ "name": "INSIGHTFACE",
135
+ "type": "INSIGHTFACE",
136
+ "links": [
137
+ 29
138
+ ],
139
+ "shape": 3,
140
+ "slot_index": 0
141
+ }
142
+ ],
143
+ "properties": {
144
+ "Node name for S&R": "InsightFaceLoader"
145
+ },
146
+ "widgets_values": [
147
+ "CUDA"
148
+ ]
149
+ },
150
+ {
151
+ "id": 12,
152
+ "type": "PreviewImage",
153
+ "pos": [
154
+ 500,
155
+ 1770
156
+ ],
157
+ "size": {
158
+ "0": 470,
159
+ "1": 500
160
+ },
161
+ "flags": {},
162
+ "order": 7,
163
+ "mode": 0,
164
+ "inputs": [
165
+ {
166
+ "name": "images",
167
+ "type": "IMAGE",
168
+ "link": 32
169
+ }
170
+ ],
171
+ "properties": {
172
+ "Node name for S&R": "PreviewImage"
173
+ }
174
+ },
175
+ {
176
+ "id": 4,
177
+ "type": "Ipadapter_instantidLoader",
178
+ "pos": [
179
+ 98,
180
+ 1526
181
+ ],
182
+ "size": [
183
+ 290,
184
+ 90
185
+ ],
186
+ "flags": {},
187
+ "order": 5,
188
+ "mode": 0,
189
+ "inputs": [
190
+ {
191
+ "name": "pipe",
192
+ "type": "MODEL",
193
+ "link": 36
194
+ }
195
+ ],
196
+ "outputs": [
197
+ {
198
+ "name": "MODEL",
199
+ "type": "MODEL",
200
+ "links": [
201
+ 30
202
+ ],
203
+ "shape": 3,
204
+ "slot_index": 0
205
+ }
206
+ ],
207
+ "properties": {
208
+ "Node name for S&R": "Ipadapter_instantidLoader"
209
+ },
210
+ "widgets_values": [
211
+ "/content/ComfyUI/models/checkpoints",
212
+ "ip-adapter.bin"
213
+ ]
214
+ },
215
+ {
216
+ "id": 9,
217
+ "type": "ID_Prompt_Styler",
218
+ "pos": [
219
+ 410,
220
+ 1320
221
+ ],
222
+ "size": [
223
+ 260,
224
+ 400
225
+ ],
226
+ "flags": {},
227
+ "order": 2,
228
+ "mode": 0,
229
+ "outputs": [
230
+ {
231
+ "name": "positive_prompt",
232
+ "type": "STRING",
233
+ "links": [
234
+ 28
235
+ ],
236
+ "shape": 3,
237
+ "slot_index": 0
238
+ },
239
+ {
240
+ "name": "negative_prompt",
241
+ "type": "STRING",
242
+ "links": [
243
+ 27
244
+ ],
245
+ "shape": 3,
246
+ "slot_index": 1
247
+ }
248
+ ],
249
+ "properties": {
250
+ "Node name for S&R": "ID_Prompt_Styler"
251
+ },
252
+ "widgets_values": [
253
+ " a woman, retro futurism, retro game",
254
+ "(lowres, low quality, worst quality:1.2), (text:1.2), watermark, painting, drawing, illustration, glitch, deformed, mutated, cross-eyed, ugly, disfigured (lowres, low quality, worst quality:1.2), (text:1.2), watermark, painting, drawing, illustration, glitch,deformed, mutated, cross-eyed, ugly, disfigured",
255
+ "Vibrant Color"
256
+ ]
257
+ },
258
+ {
259
+ "id": 2,
260
+ "type": "IDControlNetLoader",
261
+ "pos": [
262
+ 100,
263
+ 1320
264
+ ],
265
+ "size": [
266
+ 290,
267
+ 60
268
+ ],
269
+ "flags": {},
270
+ "order": 3,
271
+ "mode": 0,
272
+ "outputs": [
273
+ {
274
+ "name": "controlnet",
275
+ "type": "MODEL",
276
+ "links": [
277
+ 35
278
+ ],
279
+ "shape": 3,
280
+ "slot_index": 0
281
+ }
282
+ ],
283
+ "properties": {
284
+ "Node name for S&R": "IDControlNetLoader"
285
+ },
286
+ "widgets_values": [
287
+ "/content/ComfyUI/models/controlnet"
288
+ ]
289
+ },
290
+ {
291
+ "id": 17,
292
+ "type": "IDBaseModelLoader_local",
293
+ "pos": [
294
+ 100,
295
+ 1420
296
+ ],
297
+ "size": [
298
+ 290,
299
+ 60
300
+ ],
301
+ "flags": {},
302
+ "order": 4,
303
+ "mode": 0,
304
+ "inputs": [
305
+ {
306
+ "name": "controlnet",
307
+ "type": "MODEL",
308
+ "link": 35
309
+ }
310
+ ],
311
+ "outputs": [
312
+ {
313
+ "name": "pipe",
314
+ "type": "MODEL",
315
+ "links": [
316
+ 36
317
+ ],
318
+ "shape": 3,
319
+ "slot_index": 0
320
+ }
321
+ ],
322
+ "properties": {
323
+ "Node name for S&R": "IDBaseModelLoader_local"
324
+ },
325
+ "widgets_values": [
326
+ "sd_xl_base_1.0.safetensors"
327
+ ]
328
+ }
329
+ ],
330
+ "links": [
331
+ [
332
+ 27,
333
+ 9,
334
+ 1,
335
+ 15,
336
+ 4,
337
+ "STRING"
338
+ ],
339
+ [
340
+ 28,
341
+ 9,
342
+ 0,
343
+ 15,
344
+ 3,
345
+ "STRING"
346
+ ],
347
+ [
348
+ 29,
349
+ 11,
350
+ 0,
351
+ 15,
352
+ 2,
353
+ "INSIGHTFACE"
354
+ ],
355
+ [
356
+ 30,
357
+ 4,
358
+ 0,
359
+ 15,
360
+ 1,
361
+ "MODEL"
362
+ ],
363
+ [
364
+ 31,
365
+ 6,
366
+ 0,
367
+ 15,
368
+ 0,
369
+ "IMAGE"
370
+ ],
371
+ [
372
+ 32,
373
+ 15,
374
+ 0,
375
+ 12,
376
+ 0,
377
+ "IMAGE"
378
+ ],
379
+ [
380
+ 35,
381
+ 2,
382
+ 0,
383
+ 17,
384
+ 0,
385
+ "MODEL"
386
+ ],
387
+ [
388
+ 36,
389
+ 17,
390
+ 0,
391
+ 4,
392
+ 0,
393
+ "MODEL"
394
+ ]
395
+ ],
396
+ "groups": [],
397
+ "config": {},
398
+ "extra": {},
399
+ "version": 0.4
400
+ }
ComfyUI-InstantID/INSTANTID WORKFLOWS/V2.0 InstantID_fromhub_pose_ref【Zho】.json ADDED
@@ -0,0 +1,451 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ {
2
+ "last_node_id": 9,
3
+ "last_link_id": 9,
4
+ "nodes": [
5
+ {
6
+ "id": 3,
7
+ "type": "IDBaseModelLoader_fromhub",
8
+ "pos": [
9
+ 350,
10
+ 640
11
+ ],
12
+ "size": [
13
+ 310,
14
+ 60
15
+ ],
16
+ "flags": {},
17
+ "order": 5,
18
+ "mode": 0,
19
+ "inputs": [
20
+ {
21
+ "name": "controlnet",
22
+ "type": "MODEL",
23
+ "link": 1
24
+ }
25
+ ],
26
+ "outputs": [
27
+ {
28
+ "name": "pipe",
29
+ "type": "MODEL",
30
+ "links": [
31
+ 2
32
+ ],
33
+ "shape": 3,
34
+ "slot_index": 0
35
+ }
36
+ ],
37
+ "properties": {
38
+ "Node name for S&R": "IDBaseModelLoader_fromhub"
39
+ },
40
+ "widgets_values": [
41
+ "wangqixun/YamerMIX_v8"
42
+ ]
43
+ },
44
+ {
45
+ "id": 2,
46
+ "type": "IDControlNetLoader",
47
+ "pos": [
48
+ 350,
49
+ 530
50
+ ],
51
+ "size": [
52
+ 310,
53
+ 60
54
+ ],
55
+ "flags": {},
56
+ "order": 0,
57
+ "mode": 0,
58
+ "outputs": [
59
+ {
60
+ "name": "controlnet",
61
+ "type": "MODEL",
62
+ "links": [
63
+ 1
64
+ ],
65
+ "shape": 3,
66
+ "slot_index": 0
67
+ }
68
+ ],
69
+ "properties": {
70
+ "Node name for S&R": "IDControlNetLoader"
71
+ },
72
+ "widgets_values": [
73
+ "/content/ComfyUI/models/controlnet"
74
+ ]
75
+ },
76
+ {
77
+ "id": 1,
78
+ "type": "InsightFaceLoader_Zho",
79
+ "pos": [
80
+ 680,
81
+ 530
82
+ ],
83
+ "size": [
84
+ 370,
85
+ 60
86
+ ],
87
+ "flags": {},
88
+ "order": 1,
89
+ "mode": 0,
90
+ "outputs": [
91
+ {
92
+ "name": "INSIGHTFACEMODEL",
93
+ "type": "INSIGHTFACEMODEL",
94
+ "links": [
95
+ 7
96
+ ],
97
+ "shape": 3,
98
+ "slot_index": 0
99
+ }
100
+ ],
101
+ "properties": {
102
+ "Node name for S&R": "InsightFaceLoader_Zho"
103
+ },
104
+ "widgets_values": [
105
+ "CUDA"
106
+ ]
107
+ },
108
+ {
109
+ "id": 4,
110
+ "type": "Ipadapter_instantidLoader",
111
+ "pos": [
112
+ 350,
113
+ 750
114
+ ],
115
+ "size": [
116
+ 310,
117
+ 80
118
+ ],
119
+ "flags": {},
120
+ "order": 6,
121
+ "mode": 0,
122
+ "inputs": [
123
+ {
124
+ "name": "pipe",
125
+ "type": "MODEL",
126
+ "link": 2
127
+ }
128
+ ],
129
+ "outputs": [
130
+ {
131
+ "name": "MODEL",
132
+ "type": "MODEL",
133
+ "links": [
134
+ 8
135
+ ],
136
+ "shape": 3,
137
+ "slot_index": 0
138
+ }
139
+ ],
140
+ "properties": {
141
+ "Node name for S&R": "Ipadapter_instantidLoader"
142
+ },
143
+ "widgets_values": [
144
+ "/content/ComfyUI/models/checkpoints",
145
+ "ip-adapter.bin"
146
+ ]
147
+ },
148
+ {
149
+ "id": 7,
150
+ "type": "LoadImage",
151
+ "pos": [
152
+ 350,
153
+ 880
154
+ ],
155
+ "size": [
156
+ 310,
157
+ 430
158
+ ],
159
+ "flags": {},
160
+ "order": 2,
161
+ "mode": 0,
162
+ "outputs": [
163
+ {
164
+ "name": "IMAGE",
165
+ "type": "IMAGE",
166
+ "links": [
167
+ 5
168
+ ],
169
+ "shape": 3
170
+ },
171
+ {
172
+ "name": "MASK",
173
+ "type": "MASK",
174
+ "links": null,
175
+ "shape": 3
176
+ }
177
+ ],
178
+ "properties": {
179
+ "Node name for S&R": "LoadImage"
180
+ },
181
+ "widgets_values": [
182
+ "download.jpg",
183
+ "image"
184
+ ]
185
+ },
186
+ {
187
+ "id": 5,
188
+ "type": "ID_Prompt_Styler",
189
+ "pos": [
190
+ 680,
191
+ 640
192
+ ],
193
+ "size": [
194
+ 370,
195
+ 190
196
+ ],
197
+ "flags": {},
198
+ "order": 3,
199
+ "mode": 0,
200
+ "outputs": [
201
+ {
202
+ "name": "positive_prompt",
203
+ "type": "STRING",
204
+ "links": [
205
+ 3
206
+ ],
207
+ "shape": 3,
208
+ "slot_index": 0
209
+ },
210
+ {
211
+ "name": "negative_prompt",
212
+ "type": "STRING",
213
+ "links": [
214
+ 4
215
+ ],
216
+ "shape": 3,
217
+ "slot_index": 1
218
+ }
219
+ ],
220
+ "properties": {
221
+ "Node name for S&R": "ID_Prompt_Styler"
222
+ },
223
+ "widgets_values": [
224
+ "a woman, retro futurism, retro game",
225
+ "(lowres, low quality, worst quality:1.2), (text:1.2), watermark, painting, drawing, illustration, glitch, deformed, mutated, cross-eyed, ugly",
226
+ "Vibrant Color"
227
+ ]
228
+ },
229
+ {
230
+ "id": 9,
231
+ "type": "PreviewImage",
232
+ "pos": [
233
+ 680,
234
+ 880
235
+ ],
236
+ "size": [
237
+ 720,
238
+ 980
239
+ ],
240
+ "flags": {},
241
+ "order": 8,
242
+ "mode": 0,
243
+ "inputs": [
244
+ {
245
+ "name": "images",
246
+ "type": "IMAGE",
247
+ "link": 9
248
+ }
249
+ ],
250
+ "properties": {
251
+ "Node name for S&R": "PreviewImage"
252
+ }
253
+ },
254
+ {
255
+ "id": 6,
256
+ "type": "IDGenerationNode",
257
+ "pos": [
258
+ 1070,
259
+ 530
260
+ ],
261
+ "size": [
262
+ 330,
263
+ 300
264
+ ],
265
+ "flags": {},
266
+ "order": 7,
267
+ "mode": 0,
268
+ "inputs": [
269
+ {
270
+ "name": "face_image",
271
+ "type": "IMAGE",
272
+ "link": 5,
273
+ "slot_index": 0
274
+ },
275
+ {
276
+ "name": "pipe",
277
+ "type": "MODEL",
278
+ "link": 8
279
+ },
280
+ {
281
+ "name": "insightface",
282
+ "type": "INSIGHTFACEMODEL",
283
+ "link": 7
284
+ },
285
+ {
286
+ "name": "pose_image_optional",
287
+ "type": "IMAGE",
288
+ "link": 6,
289
+ "slot_index": 3
290
+ },
291
+ {
292
+ "name": "positive",
293
+ "type": "STRING",
294
+ "link": 3,
295
+ "widget": {
296
+ "name": "positive"
297
+ }
298
+ },
299
+ {
300
+ "name": "negative",
301
+ "type": "STRING",
302
+ "link": 4,
303
+ "widget": {
304
+ "name": "negative"
305
+ }
306
+ }
307
+ ],
308
+ "outputs": [
309
+ {
310
+ "name": "IMAGE",
311
+ "type": "IMAGE",
312
+ "links": [
313
+ 9
314
+ ],
315
+ "shape": 3,
316
+ "slot_index": 0
317
+ }
318
+ ],
319
+ "properties": {
320
+ "Node name for S&R": "IDGenerationNode"
321
+ },
322
+ "widgets_values": [
323
+ "",
324
+ "",
325
+ 0.8,
326
+ 0.8,
327
+ 50,
328
+ 5,
329
+ true,
330
+ 1041987604602403,
331
+ "fixed"
332
+ ]
333
+ },
334
+ {
335
+ "id": 8,
336
+ "type": "LoadImage",
337
+ "pos": [
338
+ 350,
339
+ 1360
340
+ ],
341
+ "size": [
342
+ 310,
343
+ 500
344
+ ],
345
+ "flags": {},
346
+ "order": 4,
347
+ "mode": 0,
348
+ "outputs": [
349
+ {
350
+ "name": "IMAGE",
351
+ "type": "IMAGE",
352
+ "links": [
353
+ 6
354
+ ],
355
+ "shape": 3
356
+ },
357
+ {
358
+ "name": "MASK",
359
+ "type": "MASK",
360
+ "links": null,
361
+ "shape": 3
362
+ }
363
+ ],
364
+ "properties": {
365
+ "Node name for S&R": "LoadImage"
366
+ },
367
+ "widgets_values": [
368
+ "u=425589426,3799949985&fm=253&fmt=auto&app=138&f=JPEG.webp",
369
+ "image"
370
+ ]
371
+ }
372
+ ],
373
+ "links": [
374
+ [
375
+ 1,
376
+ 2,
377
+ 0,
378
+ 3,
379
+ 0,
380
+ "MODEL"
381
+ ],
382
+ [
383
+ 2,
384
+ 3,
385
+ 0,
386
+ 4,
387
+ 0,
388
+ "MODEL"
389
+ ],
390
+ [
391
+ 3,
392
+ 5,
393
+ 0,
394
+ 6,
395
+ 4,
396
+ "STRING"
397
+ ],
398
+ [
399
+ 4,
400
+ 5,
401
+ 1,
402
+ 6,
403
+ 5,
404
+ "STRING"
405
+ ],
406
+ [
407
+ 5,
408
+ 7,
409
+ 0,
410
+ 6,
411
+ 0,
412
+ "IMAGE"
413
+ ],
414
+ [
415
+ 6,
416
+ 8,
417
+ 0,
418
+ 6,
419
+ 3,
420
+ "IMAGE"
421
+ ],
422
+ [
423
+ 7,
424
+ 1,
425
+ 0,
426
+ 6,
427
+ 2,
428
+ "INSIGHTFACEMODEL"
429
+ ],
430
+ [
431
+ 8,
432
+ 4,
433
+ 0,
434
+ 6,
435
+ 1,
436
+ "MODEL"
437
+ ],
438
+ [
439
+ 9,
440
+ 6,
441
+ 0,
442
+ 9,
443
+ 0,
444
+ "IMAGE"
445
+ ]
446
+ ],
447
+ "groups": [],
448
+ "config": {},
449
+ "extra": {},
450
+ "version": 0.4
451
+ }
ComfyUI-InstantID/INSTANTID WORKFLOWS/V2.0 InstantID_locally_pose_ref【Zho】.json ADDED
@@ -0,0 +1,452 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ {
2
+ "last_node_id": 10,
3
+ "last_link_id": 11,
4
+ "nodes": [
5
+ {
6
+ "id": 2,
7
+ "type": "IDControlNetLoader",
8
+ "pos": [
9
+ 350,
10
+ 530
11
+ ],
12
+ "size": [
13
+ 310,
14
+ 60
15
+ ],
16
+ "flags": {},
17
+ "order": 0,
18
+ "mode": 0,
19
+ "outputs": [
20
+ {
21
+ "name": "controlnet",
22
+ "type": "MODEL",
23
+ "links": [
24
+ 11
25
+ ],
26
+ "shape": 3,
27
+ "slot_index": 0
28
+ }
29
+ ],
30
+ "properties": {
31
+ "Node name for S&R": "IDControlNetLoader"
32
+ },
33
+ "widgets_values": [
34
+ "/content/ComfyUI/models/controlnet"
35
+ ]
36
+ },
37
+ {
38
+ "id": 1,
39
+ "type": "InsightFaceLoader_Zho",
40
+ "pos": [
41
+ 680,
42
+ 530
43
+ ],
44
+ "size": [
45
+ 370,
46
+ 60
47
+ ],
48
+ "flags": {},
49
+ "order": 1,
50
+ "mode": 0,
51
+ "outputs": [
52
+ {
53
+ "name": "INSIGHTFACEMODEL",
54
+ "type": "INSIGHTFACEMODEL",
55
+ "links": [
56
+ 7
57
+ ],
58
+ "shape": 3,
59
+ "slot_index": 0
60
+ }
61
+ ],
62
+ "properties": {
63
+ "Node name for S&R": "InsightFaceLoader_Zho"
64
+ },
65
+ "widgets_values": [
66
+ "CUDA"
67
+ ]
68
+ },
69
+ {
70
+ "id": 4,
71
+ "type": "Ipadapter_instantidLoader",
72
+ "pos": [
73
+ 350,
74
+ 750
75
+ ],
76
+ "size": [
77
+ 310,
78
+ 80
79
+ ],
80
+ "flags": {},
81
+ "order": 6,
82
+ "mode": 0,
83
+ "inputs": [
84
+ {
85
+ "name": "pipe",
86
+ "type": "MODEL",
87
+ "link": 10
88
+ }
89
+ ],
90
+ "outputs": [
91
+ {
92
+ "name": "MODEL",
93
+ "type": "MODEL",
94
+ "links": [
95
+ 8
96
+ ],
97
+ "shape": 3,
98
+ "slot_index": 0
99
+ }
100
+ ],
101
+ "properties": {
102
+ "Node name for S&R": "Ipadapter_instantidLoader"
103
+ },
104
+ "widgets_values": [
105
+ "/content/ComfyUI/models/checkpoints",
106
+ "ip-adapter.bin"
107
+ ]
108
+ },
109
+ {
110
+ "id": 7,
111
+ "type": "LoadImage",
112
+ "pos": [
113
+ 350,
114
+ 880
115
+ ],
116
+ "size": [
117
+ 310,
118
+ 430
119
+ ],
120
+ "flags": {},
121
+ "order": 2,
122
+ "mode": 0,
123
+ "outputs": [
124
+ {
125
+ "name": "IMAGE",
126
+ "type": "IMAGE",
127
+ "links": [
128
+ 5
129
+ ],
130
+ "shape": 3
131
+ },
132
+ {
133
+ "name": "MASK",
134
+ "type": "MASK",
135
+ "links": null,
136
+ "shape": 3
137
+ }
138
+ ],
139
+ "properties": {
140
+ "Node name for S&R": "LoadImage"
141
+ },
142
+ "widgets_values": [
143
+ "download.jpg",
144
+ "image"
145
+ ]
146
+ },
147
+ {
148
+ "id": 9,
149
+ "type": "PreviewImage",
150
+ "pos": [
151
+ 680,
152
+ 880
153
+ ],
154
+ "size": [
155
+ 720,
156
+ 980
157
+ ],
158
+ "flags": {},
159
+ "order": 8,
160
+ "mode": 0,
161
+ "inputs": [
162
+ {
163
+ "name": "images",
164
+ "type": "IMAGE",
165
+ "link": 9
166
+ }
167
+ ],
168
+ "properties": {
169
+ "Node name for S&R": "PreviewImage"
170
+ }
171
+ },
172
+ {
173
+ "id": 8,
174
+ "type": "LoadImage",
175
+ "pos": [
176
+ 350,
177
+ 1360
178
+ ],
179
+ "size": [
180
+ 310,
181
+ 500
182
+ ],
183
+ "flags": {},
184
+ "order": 3,
185
+ "mode": 0,
186
+ "outputs": [
187
+ {
188
+ "name": "IMAGE",
189
+ "type": "IMAGE",
190
+ "links": [
191
+ 6
192
+ ],
193
+ "shape": 3
194
+ },
195
+ {
196
+ "name": "MASK",
197
+ "type": "MASK",
198
+ "links": null,
199
+ "shape": 3
200
+ }
201
+ ],
202
+ "properties": {
203
+ "Node name for S&R": "LoadImage"
204
+ },
205
+ "widgets_values": [
206
+ "u=425589426,3799949985&fm=253&fmt=auto&app=138&f=JPEG.webp",
207
+ "image"
208
+ ]
209
+ },
210
+ {
211
+ "id": 10,
212
+ "type": "IDBaseModelLoader_local",
213
+ "pos": [
214
+ 350,
215
+ 640
216
+ ],
217
+ "size": [
218
+ 310,
219
+ 60
220
+ ],
221
+ "flags": {},
222
+ "order": 5,
223
+ "mode": 0,
224
+ "inputs": [
225
+ {
226
+ "name": "controlnet",
227
+ "type": "MODEL",
228
+ "link": 11,
229
+ "slot_index": 0
230
+ }
231
+ ],
232
+ "outputs": [
233
+ {
234
+ "name": "pipe",
235
+ "type": "MODEL",
236
+ "links": [
237
+ 10
238
+ ],
239
+ "shape": 3,
240
+ "slot_index": 0
241
+ }
242
+ ],
243
+ "properties": {
244
+ "Node name for S&R": "IDBaseModelLoader_local"
245
+ },
246
+ "widgets_values": [
247
+ "sd_xl_base_1.0.safetensors"
248
+ ]
249
+ },
250
+ {
251
+ "id": 5,
252
+ "type": "ID_Prompt_Styler",
253
+ "pos": [
254
+ 680,
255
+ 640
256
+ ],
257
+ "size": [
258
+ 370,
259
+ 190
260
+ ],
261
+ "flags": {},
262
+ "order": 4,
263
+ "mode": 0,
264
+ "outputs": [
265
+ {
266
+ "name": "positive_prompt",
267
+ "type": "STRING",
268
+ "links": [
269
+ 3
270
+ ],
271
+ "shape": 3,
272
+ "slot_index": 0
273
+ },
274
+ {
275
+ "name": "negative_prompt",
276
+ "type": "STRING",
277
+ "links": [
278
+ 4
279
+ ],
280
+ "shape": 3,
281
+ "slot_index": 1
282
+ }
283
+ ],
284
+ "properties": {
285
+ "Node name for S&R": "ID_Prompt_Styler"
286
+ },
287
+ "widgets_values": [
288
+ "a woman, retro futurism, retro game",
289
+ "(lowres, low quality, worst quality:1.2), (text:1.2), watermark, painting, drawing, illustration, glitch, deformed, mutated, cross-eyed, ugly",
290
+ "Film Noir"
291
+ ]
292
+ },
293
+ {
294
+ "id": 6,
295
+ "type": "IDGenerationNode",
296
+ "pos": [
297
+ 1070,
298
+ 530
299
+ ],
300
+ "size": [
301
+ 330,
302
+ 300
303
+ ],
304
+ "flags": {},
305
+ "order": 7,
306
+ "mode": 0,
307
+ "inputs": [
308
+ {
309
+ "name": "face_image",
310
+ "type": "IMAGE",
311
+ "link": 5,
312
+ "slot_index": 0
313
+ },
314
+ {
315
+ "name": "pipe",
316
+ "type": "MODEL",
317
+ "link": 8
318
+ },
319
+ {
320
+ "name": "insightface",
321
+ "type": "INSIGHTFACEMODEL",
322
+ "link": 7
323
+ },
324
+ {
325
+ "name": "pose_image_optional",
326
+ "type": "IMAGE",
327
+ "link": 6,
328
+ "slot_index": 3
329
+ },
330
+ {
331
+ "name": "positive",
332
+ "type": "STRING",
333
+ "link": 3,
334
+ "widget": {
335
+ "name": "positive"
336
+ }
337
+ },
338
+ {
339
+ "name": "negative",
340
+ "type": "STRING",
341
+ "link": 4,
342
+ "widget": {
343
+ "name": "negative"
344
+ }
345
+ }
346
+ ],
347
+ "outputs": [
348
+ {
349
+ "name": "IMAGE",
350
+ "type": "IMAGE",
351
+ "links": [
352
+ 9
353
+ ],
354
+ "shape": 3,
355
+ "slot_index": 0
356
+ }
357
+ ],
358
+ "properties": {
359
+ "Node name for S&R": "IDGenerationNode"
360
+ },
361
+ "widgets_values": [
362
+ "",
363
+ "",
364
+ 0.8,
365
+ 0.8,
366
+ 50,
367
+ 5,
368
+ true,
369
+ 210876416756428,
370
+ "randomize"
371
+ ]
372
+ }
373
+ ],
374
+ "links": [
375
+ [
376
+ 3,
377
+ 5,
378
+ 0,
379
+ 6,
380
+ 4,
381
+ "STRING"
382
+ ],
383
+ [
384
+ 4,
385
+ 5,
386
+ 1,
387
+ 6,
388
+ 5,
389
+ "STRING"
390
+ ],
391
+ [
392
+ 5,
393
+ 7,
394
+ 0,
395
+ 6,
396
+ 0,
397
+ "IMAGE"
398
+ ],
399
+ [
400
+ 6,
401
+ 8,
402
+ 0,
403
+ 6,
404
+ 3,
405
+ "IMAGE"
406
+ ],
407
+ [
408
+ 7,
409
+ 1,
410
+ 0,
411
+ 6,
412
+ 2,
413
+ "INSIGHTFACEMODEL"
414
+ ],
415
+ [
416
+ 8,
417
+ 4,
418
+ 0,
419
+ 6,
420
+ 1,
421
+ "MODEL"
422
+ ],
423
+ [
424
+ 9,
425
+ 6,
426
+ 0,
427
+ 9,
428
+ 0,
429
+ "IMAGE"
430
+ ],
431
+ [
432
+ 10,
433
+ 10,
434
+ 0,
435
+ 4,
436
+ 0,
437
+ "MODEL"
438
+ ],
439
+ [
440
+ 11,
441
+ 2,
442
+ 0,
443
+ 10,
444
+ 0,
445
+ "MODEL"
446
+ ]
447
+ ],
448
+ "groups": [],
449
+ "config": {},
450
+ "extra": {},
451
+ "version": 0.4
452
+ }
ComfyUI-InstantID/INSTANTID WORKFLOWS/V2.0 InstantID_pose_ref + ArtGallery 【Zho】.json ADDED
@@ -0,0 +1,665 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ {
2
+ "last_node_id": 13,
3
+ "last_link_id": 13,
4
+ "nodes": [
5
+ {
6
+ "id": 3,
7
+ "type": "IDBaseModelLoader_fromhub",
8
+ "pos": [
9
+ 350,
10
+ 530
11
+ ],
12
+ "size": {
13
+ "0": 310,
14
+ "1": 60
15
+ },
16
+ "flags": {},
17
+ "order": 6,
18
+ "mode": 0,
19
+ "inputs": [
20
+ {
21
+ "name": "controlnet",
22
+ "type": "MODEL",
23
+ "link": 1
24
+ }
25
+ ],
26
+ "outputs": [
27
+ {
28
+ "name": "pipe",
29
+ "type": "MODEL",
30
+ "links": [
31
+ 2
32
+ ],
33
+ "shape": 3,
34
+ "slot_index": 0
35
+ }
36
+ ],
37
+ "properties": {
38
+ "Node name for S&R": "IDBaseModelLoader_fromhub"
39
+ },
40
+ "widgets_values": [
41
+ "wangqixun/YamerMIX_v8"
42
+ ]
43
+ },
44
+ {
45
+ "id": 4,
46
+ "type": "Ipadapter_instantidLoader",
47
+ "pos": [
48
+ 350,
49
+ 640
50
+ ],
51
+ "size": {
52
+ "0": 310,
53
+ "1": 82
54
+ },
55
+ "flags": {},
56
+ "order": 8,
57
+ "mode": 0,
58
+ "inputs": [
59
+ {
60
+ "name": "pipe",
61
+ "type": "MODEL",
62
+ "link": 2
63
+ }
64
+ ],
65
+ "outputs": [
66
+ {
67
+ "name": "MODEL",
68
+ "type": "MODEL",
69
+ "links": [
70
+ 8
71
+ ],
72
+ "shape": 3,
73
+ "slot_index": 0
74
+ }
75
+ ],
76
+ "properties": {
77
+ "Node name for S&R": "Ipadapter_instantidLoader"
78
+ },
79
+ "widgets_values": [
80
+ "/content/ComfyUI/models/checkpoints",
81
+ "ip-adapter.bin"
82
+ ]
83
+ },
84
+ {
85
+ "id": 1,
86
+ "type": "InsightFaceLoader_Zho",
87
+ "pos": [
88
+ 350,
89
+ 770
90
+ ],
91
+ "size": [
92
+ 310,
93
+ 60
94
+ ],
95
+ "flags": {},
96
+ "order": 0,
97
+ "mode": 0,
98
+ "outputs": [
99
+ {
100
+ "name": "INSIGHTFACEMODEL",
101
+ "type": "INSIGHTFACEMODEL",
102
+ "links": [
103
+ 7
104
+ ],
105
+ "shape": 3,
106
+ "slot_index": 0
107
+ }
108
+ ],
109
+ "properties": {
110
+ "Node name for S&R": "InsightFaceLoader_Zho"
111
+ },
112
+ "widgets_values": [
113
+ "CUDA"
114
+ ]
115
+ },
116
+ {
117
+ "id": 2,
118
+ "type": "IDControlNetLoader",
119
+ "pos": [
120
+ 350,
121
+ 420
122
+ ],
123
+ "size": {
124
+ "0": 310,
125
+ "1": 60
126
+ },
127
+ "flags": {},
128
+ "order": 1,
129
+ "mode": 0,
130
+ "outputs": [
131
+ {
132
+ "name": "controlnet",
133
+ "type": "MODEL",
134
+ "links": [
135
+ 1
136
+ ],
137
+ "shape": 3,
138
+ "slot_index": 0
139
+ }
140
+ ],
141
+ "properties": {
142
+ "Node name for S&R": "IDControlNetLoader"
143
+ },
144
+ "widgets_values": [
145
+ "/content/ComfyUI/models/controlnet"
146
+ ]
147
+ },
148
+ {
149
+ "id": 13,
150
+ "type": "ConcatText_Zho",
151
+ "pos": [
152
+ 1340,
153
+ 530
154
+ ],
155
+ "size": [
156
+ 300,
157
+ 96
158
+ ],
159
+ "flags": {},
160
+ "order": 9,
161
+ "mode": 0,
162
+ "inputs": [
163
+ {
164
+ "name": "text_1",
165
+ "type": "STRING",
166
+ "link": 12,
167
+ "widget": {
168
+ "name": "text_1"
169
+ }
170
+ }
171
+ ],
172
+ "outputs": [
173
+ {
174
+ "name": "text",
175
+ "type": "STRING",
176
+ "links": [
177
+ 13
178
+ ],
179
+ "shape": 3,
180
+ "slot_index": 0
181
+ }
182
+ ],
183
+ "properties": {
184
+ "Node name for S&R": "ConcatText_Zho"
185
+ },
186
+ "widgets_values": [
187
+ "",
188
+ "a woman, retro futurism, retro game"
189
+ ]
190
+ },
191
+ {
192
+ "id": 11,
193
+ "type": "MovementsImage_Zho",
194
+ "pos": [
195
+ 1010,
196
+ 420
197
+ ],
198
+ "size": [
199
+ 310,
200
+ 410
201
+ ],
202
+ "flags": {},
203
+ "order": 2,
204
+ "mode": 0,
205
+ "outputs": [
206
+ {
207
+ "name": "name",
208
+ "type": "STRING",
209
+ "links": [
210
+ 11
211
+ ],
212
+ "shape": 3,
213
+ "slot_index": 0
214
+ },
215
+ {
216
+ "name": "image",
217
+ "type": "IMAGE",
218
+ "links": null,
219
+ "shape": 3
220
+ }
221
+ ],
222
+ "properties": {
223
+ "Node name for S&R": "MovementsImage_Zho"
224
+ },
225
+ "widgets_values": [
226
+ "Abstract Expressionism.png",
227
+ 1.2
228
+ ]
229
+ },
230
+ {
231
+ "id": 12,
232
+ "type": "ConcatText_Zho",
233
+ "pos": [
234
+ 1340,
235
+ 420
236
+ ],
237
+ "size": [
238
+ 300,
239
+ 66.00003337860107
240
+ ],
241
+ "flags": {},
242
+ "order": 7,
243
+ "mode": 0,
244
+ "inputs": [
245
+ {
246
+ "name": "text_1",
247
+ "type": "STRING",
248
+ "link": 10,
249
+ "widget": {
250
+ "name": "text_1"
251
+ }
252
+ },
253
+ {
254
+ "name": "text_2",
255
+ "type": "STRING",
256
+ "link": 11,
257
+ "widget": {
258
+ "name": "text_2"
259
+ }
260
+ }
261
+ ],
262
+ "outputs": [
263
+ {
264
+ "name": "text",
265
+ "type": "STRING",
266
+ "links": [
267
+ 12
268
+ ],
269
+ "shape": 3,
270
+ "slot_index": 0
271
+ }
272
+ ],
273
+ "properties": {
274
+ "Node name for S&R": "ConcatText_Zho"
275
+ },
276
+ "widgets_values": [
277
+ "",
278
+ ""
279
+ ]
280
+ },
281
+ {
282
+ "id": 7,
283
+ "type": "LoadImage",
284
+ "pos": [
285
+ 350,
286
+ 880
287
+ ],
288
+ "size": {
289
+ "0": 310,
290
+ "1": 430
291
+ },
292
+ "flags": {},
293
+ "order": 3,
294
+ "mode": 0,
295
+ "outputs": [
296
+ {
297
+ "name": "IMAGE",
298
+ "type": "IMAGE",
299
+ "links": [
300
+ 5
301
+ ],
302
+ "shape": 3
303
+ },
304
+ {
305
+ "name": "MASK",
306
+ "type": "MASK",
307
+ "links": null,
308
+ "shape": 3
309
+ }
310
+ ],
311
+ "properties": {
312
+ "Node name for S&R": "LoadImage"
313
+ },
314
+ "widgets_values": [
315
+ "download.jpg",
316
+ "image"
317
+ ]
318
+ },
319
+ {
320
+ "id": 5,
321
+ "type": "ID_Prompt_Styler",
322
+ "pos": [
323
+ 1340,
324
+ 670
325
+ ],
326
+ "size": [
327
+ 300,
328
+ 160
329
+ ],
330
+ "flags": {},
331
+ "order": 10,
332
+ "mode": 0,
333
+ "inputs": [
334
+ {
335
+ "name": "prompt",
336
+ "type": "STRING",
337
+ "link": 13,
338
+ "widget": {
339
+ "name": "prompt"
340
+ }
341
+ }
342
+ ],
343
+ "outputs": [
344
+ {
345
+ "name": "positive_prompt",
346
+ "type": "STRING",
347
+ "links": [
348
+ 3
349
+ ],
350
+ "shape": 3,
351
+ "slot_index": 0
352
+ },
353
+ {
354
+ "name": "negative_prompt",
355
+ "type": "STRING",
356
+ "links": [
357
+ 4
358
+ ],
359
+ "shape": 3,
360
+ "slot_index": 1
361
+ }
362
+ ],
363
+ "properties": {
364
+ "Node name for S&R": "ID_Prompt_Styler"
365
+ },
366
+ "widgets_values": [
367
+ "",
368
+ "(lowres, low quality, worst quality:1.2), (text:1.2), watermark, painting, drawing, illustration, glitch, deformed, mutated, cross-eyed, ugly",
369
+ "Neon"
370
+ ]
371
+ },
372
+ {
373
+ "id": 8,
374
+ "type": "LoadImage",
375
+ "pos": [
376
+ 350,
377
+ 1360
378
+ ],
379
+ "size": [
380
+ 310,
381
+ 270
382
+ ],
383
+ "flags": {},
384
+ "order": 4,
385
+ "mode": 0,
386
+ "outputs": [
387
+ {
388
+ "name": "IMAGE",
389
+ "type": "IMAGE",
390
+ "links": [
391
+ 6
392
+ ],
393
+ "shape": 3
394
+ },
395
+ {
396
+ "name": "MASK",
397
+ "type": "MASK",
398
+ "links": null,
399
+ "shape": 3
400
+ }
401
+ ],
402
+ "properties": {
403
+ "Node name for S&R": "LoadImage"
404
+ },
405
+ "widgets_values": [
406
+ "u=2585260240,4217738218&fm=253&fmt=auto&app=120&f=JPEG.webp",
407
+ "image"
408
+ ]
409
+ },
410
+ {
411
+ "id": 9,
412
+ "type": "PreviewImage",
413
+ "pos": [
414
+ 680,
415
+ 880
416
+ ],
417
+ "size": [
418
+ 1310,
419
+ 750
420
+ ],
421
+ "flags": {},
422
+ "order": 12,
423
+ "mode": 0,
424
+ "inputs": [
425
+ {
426
+ "name": "images",
427
+ "type": "IMAGE",
428
+ "link": 9
429
+ }
430
+ ],
431
+ "properties": {
432
+ "Node name for S&R": "PreviewImage"
433
+ }
434
+ },
435
+ {
436
+ "id": 6,
437
+ "type": "IDGenerationNode",
438
+ "pos": [
439
+ 1660,
440
+ 420
441
+ ],
442
+ "size": [
443
+ 330,
444
+ 410
445
+ ],
446
+ "flags": {},
447
+ "order": 11,
448
+ "mode": 0,
449
+ "inputs": [
450
+ {
451
+ "name": "face_image",
452
+ "type": "IMAGE",
453
+ "link": 5,
454
+ "slot_index": 0
455
+ },
456
+ {
457
+ "name": "pipe",
458
+ "type": "MODEL",
459
+ "link": 8
460
+ },
461
+ {
462
+ "name": "insightface",
463
+ "type": "INSIGHTFACEMODEL",
464
+ "link": 7
465
+ },
466
+ {
467
+ "name": "pose_image_optional",
468
+ "type": "IMAGE",
469
+ "link": 6,
470
+ "slot_index": 3
471
+ },
472
+ {
473
+ "name": "positive",
474
+ "type": "STRING",
475
+ "link": 3,
476
+ "widget": {
477
+ "name": "positive"
478
+ }
479
+ },
480
+ {
481
+ "name": "negative",
482
+ "type": "STRING",
483
+ "link": 4,
484
+ "widget": {
485
+ "name": "negative"
486
+ }
487
+ }
488
+ ],
489
+ "outputs": [
490
+ {
491
+ "name": "IMAGE",
492
+ "type": "IMAGE",
493
+ "links": [
494
+ 9
495
+ ],
496
+ "shape": 3,
497
+ "slot_index": 0
498
+ }
499
+ ],
500
+ "properties": {
501
+ "Node name for S&R": "IDGenerationNode"
502
+ },
503
+ "widgets_values": [
504
+ "",
505
+ "",
506
+ 0.8,
507
+ 0.8,
508
+ 50,
509
+ 5,
510
+ true,
511
+ 1041987604602403,
512
+ "fixed"
513
+ ]
514
+ },
515
+ {
516
+ "id": 10,
517
+ "type": "ArtistsImage_Zho",
518
+ "pos": [
519
+ 680,
520
+ 420
521
+ ],
522
+ "size": [
523
+ 310,
524
+ 410
525
+ ],
526
+ "flags": {},
527
+ "order": 5,
528
+ "mode": 0,
529
+ "outputs": [
530
+ {
531
+ "name": "name",
532
+ "type": "STRING",
533
+ "links": [
534
+ 10
535
+ ],
536
+ "shape": 3,
537
+ "slot_index": 0
538
+ },
539
+ {
540
+ "name": "image",
541
+ "type": "IMAGE",
542
+ "links": null,
543
+ "shape": 3
544
+ }
545
+ ],
546
+ "properties": {
547
+ "Node name for S&R": "ArtistsImage_Zho"
548
+ },
549
+ "widgets_values": [
550
+ "Atey Ghailan .png",
551
+ 1.2
552
+ ]
553
+ }
554
+ ],
555
+ "links": [
556
+ [
557
+ 1,
558
+ 2,
559
+ 0,
560
+ 3,
561
+ 0,
562
+ "MODEL"
563
+ ],
564
+ [
565
+ 2,
566
+ 3,
567
+ 0,
568
+ 4,
569
+ 0,
570
+ "MODEL"
571
+ ],
572
+ [
573
+ 3,
574
+ 5,
575
+ 0,
576
+ 6,
577
+ 4,
578
+ "STRING"
579
+ ],
580
+ [
581
+ 4,
582
+ 5,
583
+ 1,
584
+ 6,
585
+ 5,
586
+ "STRING"
587
+ ],
588
+ [
589
+ 5,
590
+ 7,
591
+ 0,
592
+ 6,
593
+ 0,
594
+ "IMAGE"
595
+ ],
596
+ [
597
+ 6,
598
+ 8,
599
+ 0,
600
+ 6,
601
+ 3,
602
+ "IMAGE"
603
+ ],
604
+ [
605
+ 7,
606
+ 1,
607
+ 0,
608
+ 6,
609
+ 2,
610
+ "INSIGHTFACEMODEL"
611
+ ],
612
+ [
613
+ 8,
614
+ 4,
615
+ 0,
616
+ 6,
617
+ 1,
618
+ "MODEL"
619
+ ],
620
+ [
621
+ 9,
622
+ 6,
623
+ 0,
624
+ 9,
625
+ 0,
626
+ "IMAGE"
627
+ ],
628
+ [
629
+ 10,
630
+ 10,
631
+ 0,
632
+ 12,
633
+ 0,
634
+ "STRING"
635
+ ],
636
+ [
637
+ 11,
638
+ 11,
639
+ 0,
640
+ 12,
641
+ 1,
642
+ "STRING"
643
+ ],
644
+ [
645
+ 12,
646
+ 12,
647
+ 0,
648
+ 13,
649
+ 0,
650
+ "STRING"
651
+ ],
652
+ [
653
+ 13,
654
+ 13,
655
+ 0,
656
+ 5,
657
+ 0,
658
+ "STRING"
659
+ ]
660
+ ],
661
+ "groups": [],
662
+ "config": {},
663
+ "extra": {},
664
+ "version": 0.4
665
+ }
ComfyUI-InstantID/InstantIDNode.py ADDED
@@ -0,0 +1,352 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import diffusers
2
+ from diffusers.utils import load_image
3
+ from diffusers.models import ControlNetModel
4
+ from .style_template import styles
5
+
6
+ import os
7
+ import cv2
8
+ import torch
9
+ import numpy as np
10
+ from PIL import Image
11
+ import folder_paths
12
+
13
+ from huggingface_hub import hf_hub_download
14
+ from insightface.app import FaceAnalysis
15
+ from .pipeline_stable_diffusion_xl_instantid import StableDiffusionXLInstantIDPipeline, draw_kps
16
+
17
+
18
+ current_directory = os.path.dirname(os.path.abspath(__file__))
19
+ device = "cuda" if torch.cuda.is_available() else "cpu"
20
+ STYLE_NAMES = list(styles.keys())
21
+ DEFAULT_STYLE_NAME = "Neon"
22
+
23
+
24
+ def apply_style(style_name: str, positive: str, negative: str = "") -> tuple[str, str]:
25
+ p, n = styles.get(style_name, styles[DEFAULT_STYLE_NAME])
26
+ return p.replace("{prompt}", positive), n + ' ' + negative
27
+
28
+
29
+ def resize_img(input_image, max_side=1280, min_side=1024, size=None,
30
+ pad_to_max_side=False, mode=Image.BILINEAR, base_pixel_number=64):
31
+
32
+ image_np = (255. * input_image.cpu().numpy().squeeze()).clip(0, 255).astype(np.uint8)
33
+ input_image = Image.fromarray(image_np)
34
+
35
+ w, h = input_image.size
36
+ if size is not None:
37
+ w_resize_new, h_resize_new = size
38
+ else:
39
+ ratio = min_side / min(h, w)
40
+ w, h = round(ratio*w), round(ratio*h)
41
+ ratio = max_side / max(h, w)
42
+ input_image = input_image.resize([round(ratio*w), round(ratio*h)], mode)
43
+ w_resize_new = (round(ratio * w) // base_pixel_number) * base_pixel_number
44
+ h_resize_new = (round(ratio * h) // base_pixel_number) * base_pixel_number
45
+ input_image = input_image.resize([w_resize_new, h_resize_new], mode)
46
+
47
+ if pad_to_max_side:
48
+ res = np.ones([max_side, max_side, 3], dtype=np.uint8) * 255
49
+ offset_x = (max_side - w_resize_new) // 2
50
+ offset_y = (max_side - h_resize_new) // 2
51
+ res[offset_y:offset_y+h_resize_new, offset_x:offset_x+w_resize_new] = np.array(input_image)
52
+ input_image = Image.fromarray(res)
53
+ return input_image
54
+
55
+
56
+ class InsightFaceLoader_Node_Zho:
57
+ @classmethod
58
+ def INPUT_TYPES(s):
59
+ return {
60
+ "required": {
61
+ "provider": (["CUDA", "CPU"], ),
62
+ },
63
+ }
64
+
65
+ RETURN_TYPES = ("INSIGHTFACEMODEL",)
66
+ FUNCTION = "load_insight_face_antelopev2"
67
+ CATEGORY = "📷InstantID"
68
+
69
+ def load_insight_face_antelopev2(self, provider):
70
+
71
+ model = FaceAnalysis(name="antelopev2", root=current_directory, providers=[provider + 'ExecutionProvider',])
72
+ model.prepare(ctx_id=0, det_size=(640, 640))
73
+
74
+ return (model,)
75
+
76
+
77
+ class IDControlNetLoaderNode_Zho:
78
+ def __init__(self):
79
+ pass
80
+
81
+ @classmethod
82
+ def INPUT_TYPES(cls):
83
+ return {
84
+ "required": {
85
+ "controlnet_path": ("STRING", {"default": "enter your path"}),
86
+ }
87
+ }
88
+
89
+ RETURN_TYPES = ("MODEL",)
90
+ RETURN_NAMES = ("controlnet",)
91
+ FUNCTION = "load_idcontrolnet"
92
+ CATEGORY = "📷InstantID"
93
+
94
+ def load_idcontrolnet(self, controlnet_path):
95
+
96
+ controlnet = ControlNetModel.from_pretrained(controlnet_path, torch_dtype=torch.float16)
97
+
98
+ return [controlnet]
99
+
100
+
101
+ class IDBaseModelLoader_fromhub_Node_Zho:
102
+ def __init__(self):
103
+ pass
104
+
105
+ @classmethod
106
+ def INPUT_TYPES(cls):
107
+ return {
108
+ "required": {
109
+ "base_model_path": ("STRING", {"default": "wangqixun/YamerMIX_v8"}),
110
+ "controlnet": ("MODEL",)
111
+ }
112
+ }
113
+
114
+ RETURN_TYPES = ("MODEL",)
115
+ RETURN_NAMES = ("pipe",)
116
+ FUNCTION = "load_model"
117
+ CATEGORY = "📷InstantID"
118
+
119
+ def load_model(self, base_model_path, controlnet):
120
+ # Code to load the base model
121
+ pipe = StableDiffusionXLInstantIDPipeline.from_pretrained(
122
+ base_model_path,
123
+ controlnet=controlnet,
124
+ torch_dtype=torch.float16,
125
+ local_dir="./checkpoints"
126
+ ).to(device)
127
+ return [pipe]
128
+
129
+
130
+ class IDBaseModelLoader_local_Node_Zho:
131
+ def __init__(self):
132
+ pass
133
+
134
+ @classmethod
135
+ def INPUT_TYPES(cls):
136
+ return {
137
+ "required": {
138
+ "ckpt_name": (folder_paths.get_filename_list("checkpoints"), ),
139
+ "controlnet": ("MODEL",)
140
+ }
141
+ }
142
+
143
+ RETURN_TYPES = ("MODEL",)
144
+ RETURN_NAMES = ("pipe",)
145
+ FUNCTION = "load_model"
146
+ CATEGORY = "📷InstantID"
147
+
148
+ def load_model(self, ckpt_name, controlnet):
149
+ # Code to load the base model
150
+ if not ckpt_name:
151
+ raise ValueError("Please provide the ckpt_name parameter with the name of the checkpoint file.")
152
+
153
+ ckpt_path = folder_paths.get_full_path("checkpoints", ckpt_name)
154
+
155
+ if not os.path.exists(ckpt_path):
156
+ raise FileNotFoundError(f"Checkpoint file {ckpt_path} not found.")
157
+
158
+ pipe = StableDiffusionXLInstantIDPipeline.from_single_file(
159
+ pretrained_model_link_or_path=ckpt_path,
160
+ controlnet=controlnet,
161
+ torch_dtype=torch.float16,
162
+ use_safetensors=True,
163
+ variant="fp16"
164
+ ).to(device)
165
+ return [pipe]
166
+
167
+
168
+ class Ipadapter_instantidLoader_Node_Zho:
169
+ def __init__(self):
170
+ pass
171
+
172
+ @classmethod
173
+ def INPUT_TYPES(cls):
174
+ return {
175
+ "required": {
176
+ "Ipadapter_instantid_path": ("STRING", {"default": "enter your path"}),
177
+ "filename": ("STRING", {"default": "ip-adapter.bin"}),
178
+ "pipe": ("MODEL",),
179
+ }
180
+ }
181
+
182
+ RETURN_TYPES = ("MODEL",)
183
+ FUNCTION = "load_ip_adapter_instantid"
184
+ CATEGORY = "📷InstantID"
185
+
186
+ def load_ip_adapter_instantid(self, pipe, Ipadapter_instantid_path, filename):
187
+ # 使用hf_hub_download方法获取PhotoMaker文件的路径
188
+ face_adapter = os.path.join(Ipadapter_instantid_path, filename)
189
+
190
+ # load adapter
191
+ pipe.load_ip_adapter_instantid(face_adapter)
192
+
193
+ return [pipe]
194
+
195
+
196
+ class ID_Prompt_Style_Zho:
197
+ def __init__(self):
198
+ pass
199
+
200
+ @classmethod
201
+ def INPUT_TYPES(cls):
202
+ return {
203
+ "required": {
204
+ "prompt": ("STRING", {"default": "a woman, retro futurism, retro game", "multiline": True}),
205
+ "negative_prompt": ("STRING", {"default": "(lowres, low quality, worst quality:1.2), (text:1.2), watermark, painting, drawing, illustration, glitch, deformed, mutated, cross-eyed, ugly", "multiline": True}),
206
+ "style_name": (STYLE_NAMES, {"default": DEFAULT_STYLE_NAME})
207
+ }
208
+ }
209
+
210
+ RETURN_TYPES = ('STRING','STRING',)
211
+ RETURN_NAMES = ('positive_prompt','negative_prompt',)
212
+ FUNCTION = "id_prompt_style"
213
+ CATEGORY = "📷InstantID"
214
+
215
+ def id_prompt_style(self, style_name, prompt, negative_prompt):
216
+ prompt, negative_prompt = apply_style(style_name, prompt, negative_prompt)
217
+
218
+ return prompt, negative_prompt
219
+
220
+
221
+ class IDGenerationNode_Zho:
222
+ def __init__(self):
223
+ pass
224
+
225
+ @classmethod
226
+ def INPUT_TYPES(cls):
227
+ return {
228
+ "required": {
229
+ "face_image": ("IMAGE",),
230
+ "pipe": ("MODEL",),
231
+ "insightface": ("INSIGHTFACEMODEL",),
232
+ "positive": ("STRING", {"multiline": True, "forceInput": True}),
233
+ "negative": ("STRING", {"multiline": True, "forceInput": True}),
234
+ "ip_adapter_scale": ("FLOAT", {"default": 0.8, "min": 0, "max": 1.0, "display": "slider"}),
235
+ "controlnet_conditioning_scale": ("FLOAT", {"default": 0.8, "min": 0, "max": 1.0, "display": "slider"}),
236
+ "steps": ("INT", {"default": 50, "min": 1, "max": 100, "step": 1, "display": "slider"}),
237
+ "guidance_scale": ("FLOAT", {"default": 5, "min": 0, "max": 10, "display": "slider"}),
238
+ "enhance_face_region": ("BOOLEAN", {"default": True}),
239
+ "seed": ("INT", {"default": 0, "min": 0, "max": 0xffffffffffffffff}),
240
+ },
241
+ "optional": {
242
+ "pose_image_optional": ("IMAGE",),
243
+ }
244
+ }
245
+
246
+ RETURN_TYPES = ("IMAGE",)
247
+ FUNCTION = "id_generate_image"
248
+ CATEGORY = "📷InstantID"
249
+
250
+ def id_generate_image(self, insightface, positive, negative, face_image, pipe, ip_adapter_scale, controlnet_conditioning_scale, steps, guidance_scale, seed, enhance_face_region, pose_image_optional=None):
251
+
252
+ face_image = resize_img(face_image)
253
+
254
+ # prepare face emb
255
+ face_info = insightface.get(cv2.cvtColor(np.array(face_image), cv2.COLOR_RGB2BGR))
256
+ if not face_info:
257
+ return "No face detected"
258
+
259
+ face_info = sorted(face_info, key=lambda x: (x['bbox'][2] - x['bbox'][0]) * (x['bbox'][3] - x['bbox'][1]))[-1]
260
+ face_emb = face_info['embedding']
261
+ face_kps = draw_kps(face_image, face_info['kps'])
262
+ width, height = face_kps.size
263
+
264
+ if pose_image_optional is not None:
265
+ pose_image = resize_img(pose_image_optional)
266
+ face_info = insightface.get(cv2.cvtColor(np.array(pose_image), cv2.COLOR_RGB2BGR))
267
+ if len(face_info) == 0:
268
+ raise gr.Error(f"Cannot find any face in the reference image! Please upload another person image")
269
+
270
+ face_info = face_info[-1]
271
+ face_kps = draw_kps(pose_image, face_info['kps'])
272
+
273
+ width, height = face_kps.size
274
+
275
+ if enhance_face_region:
276
+ control_mask = np.zeros([height, width, 3])
277
+ x1, y1, x2, y2 = face_info['bbox']
278
+ x1, y1, x2, y2 = int(x1), int(y1), int(x2), int(y2)
279
+ control_mask[y1:y2, x1:x2] = 255
280
+ control_mask = Image.fromarray(control_mask.astype(np.uint8))
281
+ else:
282
+ control_mask = None
283
+
284
+ generator = torch.Generator(device=device).manual_seed(seed)
285
+
286
+ pipe.set_ip_adapter_scale(ip_adapter_scale)
287
+
288
+ output = pipe(
289
+ prompt=positive,
290
+ negative_prompt=negative,
291
+ image_embeds=face_emb,
292
+ image=face_kps,
293
+ control_mask=control_mask,
294
+ controlnet_conditioning_scale=controlnet_conditioning_scale,
295
+ num_inference_steps=steps,
296
+ generator=generator,
297
+ guidance_scale=guidance_scale,
298
+ width=width,
299
+ height=height,
300
+ return_dict=False
301
+ )
302
+
303
+ # 检查输出类型并相应处理
304
+ if isinstance(output, tuple):
305
+ # 当返回的是元组时,第一个元素是图像列表
306
+ images_list = output[0]
307
+ else:
308
+ # 如果返回的是 StableDiffusionXLPipelineOutput,需要从中提取图像
309
+ images_list = output.images
310
+
311
+ # 转换图像为 torch.Tensor,并调整维度顺序为 NHWC
312
+ images_tensors = []
313
+ for img in images_list:
314
+ # 将 PIL.Image 转换为 numpy.ndarray
315
+ img_array = np.array(img)
316
+ # 转换 numpy.ndarray 为 torch.Tensor
317
+ img_tensor = torch.from_numpy(img_array).float() / 255.
318
+ # 转换图像格式为 CHW (如果需要)
319
+ if img_tensor.ndim == 3 and img_tensor.shape[-1] == 3:
320
+ img_tensor = img_tensor.permute(2, 0, 1)
321
+ # 添加批次维度并转换为 NHWC
322
+ img_tensor = img_tensor.unsqueeze(0).permute(0, 2, 3, 1)
323
+ images_tensors.append(img_tensor)
324
+
325
+ if len(images_tensors) > 1:
326
+ output_image = torch.cat(images_tensors, dim=0)
327
+ else:
328
+ output_image = images_tensors[0]
329
+
330
+ return (output_image,)
331
+
332
+
333
+
334
+ NODE_CLASS_MAPPINGS = {
335
+ "InsightFaceLoader_Zho": InsightFaceLoader_Node_Zho,
336
+ "IDControlNetLoader": IDControlNetLoaderNode_Zho,
337
+ "IDBaseModelLoader_fromhub": IDBaseModelLoader_fromhub_Node_Zho,
338
+ "IDBaseModelLoader_local": IDBaseModelLoader_local_Node_Zho,
339
+ "Ipadapter_instantidLoader": Ipadapter_instantidLoader_Node_Zho,
340
+ "ID_Prompt_Styler": ID_Prompt_Style_Zho,
341
+ "IDGenerationNode": IDGenerationNode_Zho
342
+ }
343
+
344
+ NODE_DISPLAY_NAME_MAPPINGS = {
345
+ "InsightFaceLoader_Zho": "📷InsightFace Loader",
346
+ "IDControlNetLoader": "📷ID ControlNet Loader",
347
+ "IDBaseModelLoader_fromhub": "📷ID Base Model Loader from hub 🤗",
348
+ "IDBaseModelLoader_local": "📷ID Base Model Loader locally",
349
+ "Ipadapter_instantidLoader": "📷Ipadapter_instantid Loader",
350
+ "ID_Prompt_Styler": "📷ID Prompt_Styler",
351
+ "IDGenerationNode": "📷InstantID Generation"
352
+ }
ComfyUI-InstantID/README.md ADDED
@@ -0,0 +1,213 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+
2
+ ![ISID_](https://github.com/ZHO-ZHO-ZHO/ComfyUI-InstantID/assets/140084057/01393483-3145-4691-9daa-7ce9035c9bd0)
3
+
4
+
5
+ # ComfyUI InstantID
6
+
7
+ Unofficial implementation of [InstantID](https://github.com/InstantID/InstantID) for ComfyUI
8
+
9
+ ![Dingtalk_20240123182131](https://github.com/ZHO-ZHO-ZHO/ComfyUI-InstantID/assets/140084057/7a99b32c-b4a2-4c46-acb0-f796fc46f9ee)
10
+
11
+ + pose_ref
12
+
13
+ ![Dingtalk_20240124232946](https://github.com/ZHO-ZHO-ZHO/ComfyUI-InstantID/assets/140084057/caa60456-f2d8-4315-864b-659a9e7cea89)
14
+
15
+
16
+ ## 项目介绍 | Info
17
+
18
+ - 来自对[InstantID](https://github.com/InstantID/InstantID)的非官方实现
19
+
20
+ - 版本:V2.0 支持姿势参考图
21
+
22
+ <!---
23
+ 同时支持本地、huggingface hub模型,支持通用styler(也与 PhotoMaker Styler 通用)
24
+ --->
25
+
26
+ ## 视频演示
27
+
28
+ V2.0
29
+
30
+
31
+ https://github.com/ZHO-ZHO-ZHO/ComfyUI-InstantID/assets/140084057/083c9e5e-06a0-4623-b5ac-05f7e85a74f2
32
+
33
+
34
+ V1.0
35
+
36
+ https://github.com/ZHO-ZHO-ZHO/ComfyUI-InstantID/assets/140084057/7295c0d7-1d1b-4044-aea3-8efa67047362
37
+
38
+
39
+
40
+ ## 节点说明 | Features
41
+
42
+ - 基础模型加载 | base model loader
43
+ - 📷ID Base Model Loader from hub 🤗:支持从 huggingface hub 自动下载模型,输入模型名称(如:wangqixun/YamerMIX_v8)即可
44
+ - 📷ID Base Model Loader locally:支持加载本地模型(需 SDXL 系列模型)
45
+
46
+ - InsightFace 模型加载 | 📷InsightFace Loader
47
+ - :支持 CUDA 和 CPU
48
+
49
+ - ID ControlNet 模型加载 | 📷ID ControlNet Loader
50
+ - controlnet_path:ID ControlNet 模型地址
51
+
52
+ - Ipadapter_instantid 模型加载 | 📷Ipadapter_instantid Loader
53
+ - Ipadapter_instantid_path:模型路径
54
+ - filename:模型名称
55
+
56
+ - 提示词 + 风格 | 📷ID Prompt_Styler
57
+ - 与各种提示词(文本)输入(如肖像大师等)、styler、 Photomaker Prompt_Styler 兼容
58
+ - prompt、negative:正负提示词
59
+ - style_name:支持官方提供的8种风格
60
+ - (No style)
61
+ - Watercolor
62
+ - Film Noir
63
+ - Neon
64
+ - Jungle
65
+ - Mars
66
+ - Vibrant Color
67
+ - Snow
68
+ - Line art
69
+
70
+ - InstantID 生成 | 📷InstantID Generation 🆕
71
+ - face_image:接入脸部参考图像
72
+ - pipe:接入模型
73
+ - insightface:接入 insightface 模型 🆕
74
+ - pose_image_optional(非必要):接入姿势参考图像(注意:仅对面部周围姿势起效,与通常的 openpose 不同)
75
+ - positivet、negative:正负提示词
76
+ - ip_adapter_scale:IPA 强度
77
+ - controlnet_conditioning_scale:ID Controlnet 强度
78
+ - step:步数,官方默认30步
79
+ - guidance_scale:提示词相关度,一般默认为5
80
+ - enhance_face_region:脸部增强选项 🆕
81
+ - seed:种子
82
+
83
+
84
+ ## 风格 | Styles
85
+
86
+ ![ISID_STYLE](https://github.com/ZHO-ZHO-ZHO/ComfyUI-InstantID/assets/140084057/142bda7a-798b-46b3-aa69-1b88701c8311)
87
+
88
+
89
+
90
+ ## 安装 | Install
91
+
92
+
93
+ - 推荐使用管理器 ComfyUI Manager 安装(On the Way)
94
+
95
+
96
+ - 手动安装:
97
+ 1. `cd custom_nodes`
98
+ 2. `git clone https://github.com/ZHO-ZHO-ZHO/ComfyUI-InstantID.git`
99
+ 3. `cd custom_nodes/ComfyUI-InstantID`
100
+ 4. `pip install -r requirements.txt`
101
+ 5. 重启 ComfyUI
102
+
103
+
104
+ ## 使用方法 | How to Use
105
+
106
+ - 下载 [InstantID/ControlNetModel](https://huggingface.co/InstantX/InstantID/tree/main/ControlNetModel) 中的 config.json 和 diffusion_pytorch_model.safetensors ,将模型地址填入 📷ID ControlNet Loader 节点中(例如:ComfyUI/custom_nodes/ComfyUI-InstantID/checkpoints/controlnet)
107
+
108
+ - 下载 [InstantID/ip-adapter](https://huggingface.co/InstantX/InstantID/tree/main) 中的 ip-adapter.bin ,将其地址填入 📷Ipadapter_instantid Loader 节点中(例如:ComfyUI/custom_nodes/ComfyUI-InstantID/checkpoints)
109
+
110
+ - 下载 [DIAMONIK7777/antelopev2](https://huggingface.co/DIAMONIK7777/antelopev2/tree/main) 中的所有模型,将其放入 ComfyUI//custom_nodes/ComfyUI-InstantID/models/antelopev2 中
111
+
112
+ - 兼容性: CUDA11 支持默认安装的 onnxruntime-gpu(1.16.0),如果是 CUDA12 则需手动安装 onnxruntime-gpu==1.17.0 [地址](https://dev.azure.com/onnxruntime/onnxruntime/_artifacts/feed/onnxruntime-cuda-12/PyPI/onnxruntime-gpu/overview/1.17.0)
113
+
114
+
115
+ ## 工作流 | Workflows
116
+
117
+ V2.0
118
+
119
+ - [V2.0 InstantID_pose_ref + ArtGallery](https://github.com/ZHO-ZHO-ZHO/ComfyUI-InstantID/blob/main/INSTANTID%20WORKFLOWS/V2.0%20InstantID_pose_ref%20%2B%20ArtGallery%20%E3%80%90Zho%E3%80%91.json)
120
+
121
+ ![Dingtalk_20240124232833](https://github.com/ZHO-ZHO-ZHO/ComfyUI-InstantID/assets/140084057/99be9592-775d-4c33-bafc-5bd5c95a7222)
122
+
123
+
124
+ - [V2.0 自动下载 huggingface hub](https://github.com/ZHO-ZHO-ZHO/ComfyUI-InstantID/blob/main/INSTANTID%20WORKFLOWS/V2.0%20InstantID_fromhub_pose_ref%E3%80%90Zho%E3%80%91.json)
125
+
126
+ ![Dingtalk_20240124230145](https://github.com/ZHO-ZHO-ZHO/ComfyUI-InstantID/assets/140084057/95c4a1dd-864d-4a46-8c45-a48866aef29f)
127
+
128
+
129
+ - [V2.0 InstantID_locally_pose_ref](https://github.com/ZHO-ZHO-ZHO/ComfyUI-InstantID/blob/main/INSTANTID%20WORKFLOWS/V2.0%20InstantID_locally_pose_ref%E3%80%90Zho%E3%80%91.json)
130
+
131
+ ![Dingtalk_20240124230609](https://github.com/ZHO-ZHO-ZHO/ComfyUI-InstantID/assets/140084057/d4c22389-f853-44bd-9ea2-568b2ac7ed06)
132
+
133
+
134
+ V1.0 工作流仅适用于V1.0 版本
135
+
136
+ - [V1.0 InstantID + ArtGallery](https://github.com/ZHO-ZHO-ZHO/ComfyUI-InstantID/blob/main/INSTANTID%20WORKFLOWS/V1.0%20InstantID%20%2B%20ArtGallery%E3%80%90Zho%E3%80%91.json)
137
+
138
+
139
+ ![Dingtalk_20240123182440](https://github.com/ZHO-ZHO-ZHO/ComfyUI-InstantID/assets/140084057/c6ee25bf-a528-4d78-9b35-f5b0d0303601)
140
+
141
+
142
+ - [V1.0 本地模型 locally](https://github.com/ZHO-ZHO-ZHO/ComfyUI-InstantID/blob/main/INSTANTID%20WORKFLOWS/V1.0%20InstantID_locally%E3%80%90Zho%E3%80%91.json)
143
+
144
+ ![Dingtalk_20240123175624](https://github.com/ZHO-ZHO-ZHO/ComfyUI-InstantID/assets/140084057/459bfede-59e8-4d8d-941c-a950c4827c49)
145
+
146
+
147
+ - [V1.0 自动下载 huggingface hub](https://github.com/ZHO-ZHO-ZHO/ComfyUI-InstantID/blob/main/INSTANTID%20WORKFLOWS/V1.0%20InstantID_fromhub%E3%80%90Zho%E3%80%91.json)
148
+
149
+ ![Dingtalk_20240123174950](https://github.com/ZHO-ZHO-ZHO/ComfyUI-InstantID/assets/140084057/50133961-1752-4ec8-ac0b-068d998b8534)
150
+
151
+
152
+
153
+
154
+ ## 更新日志
155
+
156
+ - 20240124
157
+
158
+ 更新为 V2.0 :新增姿势参考图、优化代码
159
+
160
+ 修复 insightfaceloader 冲突问题
161
+
162
+ 修复 onnxruntime-gpu 版本兼容性的问题
163
+
164
+ - 20240123
165
+
166
+ V1.0 上线:同时支持本地、huggingface hub托管模型,支持8种风格
167
+
168
+ - 20240122
169
+
170
+ 创建项目
171
+
172
+
173
+ ## 速度实测 | Speed
174
+
175
+ - V1.0
176
+
177
+ - A100 50步 14s
178
+
179
+ ![image](https://github.com/ZHO-ZHO-ZHO/ComfyUI-InstantID/assets/140084057/dc535e67-3f56-4faf-be81-621b84bb6ee2)
180
+
181
+
182
+
183
+ ## Stars
184
+
185
+ [![Star History Chart](https://api.star-history.com/svg?repos=ZHO-ZHO-ZHO/ComfyUI-InstantID&type=Date)](https://star-history.com/#ZHO-ZHO-ZHO/ComfyUI-InstantID&Date)
186
+
187
+
188
+ ## 关于我 | About me
189
+
190
+ 📬 **联系我**:
191
+ - 邮箱:zhozho3965@gmail.com
192
+ - QQ 群:839821928
193
+
194
+ 🔗 **社交媒体**:
195
+ - 个人页:[-Zho-](https://jike.city/zho)
196
+ - Bilibili:[我的B站主页](https://space.bilibili.com/484366804)
197
+ - X(Twitter):[我的Twitter](https://twitter.com/ZHOZHO672070)
198
+ - 小红书:[我的小红书主页](https://www.xiaohongshu.com/user/profile/63f11530000000001001e0c8?xhsshare=CopyLink&appuid=63f11530000000001001e0c8&apptime=1690528872)
199
+
200
+ 💡 **支持我**:
201
+ - B站:[B站充电](https://space.bilibili.com/484366804)
202
+ - 爱发电:[为我充电](https://afdian.net/a/ZHOZHO)
203
+
204
+
205
+ ## Credits
206
+
207
+ [InstantID](https://github.com/InstantID/InstantID)
208
+
209
+ 📷InsightFace Loader 代码修改自 [ComfyUI_IPAdapter_plus](https://github.com/cubiq/ComfyUI_IPAdapter_plus),感谢 [@cubiq](https://github.com/cubiq)!
210
+
211
+ 感谢 [@hidecloud](https://twitter.com/hidecloud) 对 onnxruntime 版本兼容性的测试与反馈!
212
+
213
+ 感谢 [esheep](https://www.esheep.com/) 技术人员对节点冲突问题的反馈!
ComfyUI-InstantID/__init__.py ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ from .InstantIDNode import NODE_CLASS_MAPPINGS, NODE_DISPLAY_NAME_MAPPINGS
2
+
3
+ __all__ = ['NODE_CLASS_MAPPINGS', 'NODE_DISPLAY_NAME_MAPPINGS']
ComfyUI-InstantID/__pycache__/InstantIDNode.cpython-312.pyc ADDED
Binary file (15.5 kB). View file
 
ComfyUI-InstantID/__pycache__/__init__.cpython-312.pyc ADDED
Binary file (331 Bytes). View file
 
ComfyUI-InstantID/__pycache__/pipeline_stable_diffusion_xl_instantid.cpython-312.pyc ADDED
Binary file (38.9 kB). View file
 
ComfyUI-InstantID/__pycache__/style_template.cpython-312.pyc ADDED
Binary file (3.26 kB). View file
 
ComfyUI-InstantID/checkpoints/put_models_here.txt ADDED
@@ -0,0 +1 @@
 
 
1
+
ComfyUI-InstantID/ip_adapter/__pycache__/attention_processor.cpython-312.pyc ADDED
Binary file (12.4 kB). View file
 
ComfyUI-InstantID/ip_adapter/__pycache__/resampler.cpython-312.pyc ADDED
Binary file (5.82 kB). View file
 
ComfyUI-InstantID/ip_adapter/__pycache__/utils.cpython-312.pyc ADDED
Binary file (466 Bytes). View file
 
ComfyUI-InstantID/ip_adapter/attention_processor.py ADDED
@@ -0,0 +1,308 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ # modified from https://github.com/huggingface/diffusers/blob/main/src/diffusers/models/attention_processor.py
2
+ import torch
3
+ import torch.nn as nn
4
+ import torch.nn.functional as F
5
+
6
+ try:
7
+ import xformers
8
+ import xformers.ops
9
+ xformers_available = True
10
+ except Exception as e:
11
+ xformers_available = False
12
+
13
+
14
+
15
+ class RegionControler(object):
16
+ def __init__(self) -> None:
17
+ self.prompt_image_conditioning = []
18
+ region_control = RegionControler()
19
+
20
+
21
+ class AttnProcessor(nn.Module):
22
+ r"""
23
+ Default processor for performing attention-related computations.
24
+ """
25
+ def __init__(
26
+ self,
27
+ hidden_size=None,
28
+ cross_attention_dim=None,
29
+ ):
30
+ super().__init__()
31
+
32
+ def __call__(
33
+ self,
34
+ attn,
35
+ hidden_states,
36
+ encoder_hidden_states=None,
37
+ attention_mask=None,
38
+ temb=None,
39
+ ):
40
+ residual = hidden_states
41
+
42
+ if attn.spatial_norm is not None:
43
+ hidden_states = attn.spatial_norm(hidden_states, temb)
44
+
45
+ input_ndim = hidden_states.ndim
46
+
47
+ if input_ndim == 4:
48
+ batch_size, channel, height, width = hidden_states.shape
49
+ hidden_states = hidden_states.view(batch_size, channel, height * width).transpose(1, 2)
50
+
51
+ batch_size, sequence_length, _ = (
52
+ hidden_states.shape if encoder_hidden_states is None else encoder_hidden_states.shape
53
+ )
54
+ attention_mask = attn.prepare_attention_mask(attention_mask, sequence_length, batch_size)
55
+
56
+ if attn.group_norm is not None:
57
+ hidden_states = attn.group_norm(hidden_states.transpose(1, 2)).transpose(1, 2)
58
+
59
+ query = attn.to_q(hidden_states)
60
+
61
+ if encoder_hidden_states is None:
62
+ encoder_hidden_states = hidden_states
63
+ elif attn.norm_cross:
64
+ encoder_hidden_states = attn.norm_encoder_hidden_states(encoder_hidden_states)
65
+
66
+ key = attn.to_k(encoder_hidden_states)
67
+ value = attn.to_v(encoder_hidden_states)
68
+
69
+ query = attn.head_to_batch_dim(query)
70
+ key = attn.head_to_batch_dim(key)
71
+ value = attn.head_to_batch_dim(value)
72
+
73
+ attention_probs = attn.get_attention_scores(query, key, attention_mask)
74
+ hidden_states = torch.bmm(attention_probs, value)
75
+ hidden_states = attn.batch_to_head_dim(hidden_states)
76
+
77
+ # linear proj
78
+ hidden_states = attn.to_out[0](hidden_states)
79
+ # dropout
80
+ hidden_states = attn.to_out[1](hidden_states)
81
+
82
+ if input_ndim == 4:
83
+ hidden_states = hidden_states.transpose(-1, -2).reshape(batch_size, channel, height, width)
84
+
85
+ if attn.residual_connection:
86
+ hidden_states = hidden_states + residual
87
+
88
+ hidden_states = hidden_states / attn.rescale_output_factor
89
+
90
+ return hidden_states
91
+
92
+
93
+ class IPAttnProcessor(nn.Module):
94
+ r"""
95
+ Attention processor for IP-Adapater.
96
+ Args:
97
+ hidden_size (`int`):
98
+ The hidden size of the attention layer.
99
+ cross_attention_dim (`int`):
100
+ The number of channels in the `encoder_hidden_states`.
101
+ scale (`float`, defaults to 1.0):
102
+ the weight scale of image prompt.
103
+ num_tokens (`int`, defaults to 4 when do ip_adapter_plus it should be 16):
104
+ The context length of the image features.
105
+ """
106
+
107
+ def __init__(self, hidden_size, cross_attention_dim=None, scale=1.0, num_tokens=4):
108
+ super().__init__()
109
+
110
+ self.hidden_size = hidden_size
111
+ self.cross_attention_dim = cross_attention_dim
112
+ self.scale = scale
113
+ self.num_tokens = num_tokens
114
+
115
+ self.to_k_ip = nn.Linear(cross_attention_dim or hidden_size, hidden_size, bias=False)
116
+ self.to_v_ip = nn.Linear(cross_attention_dim or hidden_size, hidden_size, bias=False)
117
+
118
+ def __call__(
119
+ self,
120
+ attn,
121
+ hidden_states,
122
+ encoder_hidden_states=None,
123
+ attention_mask=None,
124
+ temb=None,
125
+ ):
126
+ residual = hidden_states
127
+
128
+ if attn.spatial_norm is not None:
129
+ hidden_states = attn.spatial_norm(hidden_states, temb)
130
+
131
+ input_ndim = hidden_states.ndim
132
+
133
+ if input_ndim == 4:
134
+ batch_size, channel, height, width = hidden_states.shape
135
+ hidden_states = hidden_states.view(batch_size, channel, height * width).transpose(1, 2)
136
+
137
+ batch_size, sequence_length, _ = (
138
+ hidden_states.shape if encoder_hidden_states is None else encoder_hidden_states.shape
139
+ )
140
+ attention_mask = attn.prepare_attention_mask(attention_mask, sequence_length, batch_size)
141
+
142
+ if attn.group_norm is not None:
143
+ hidden_states = attn.group_norm(hidden_states.transpose(1, 2)).transpose(1, 2)
144
+
145
+ query = attn.to_q(hidden_states)
146
+
147
+ if encoder_hidden_states is None:
148
+ encoder_hidden_states = hidden_states
149
+ else:
150
+ # get encoder_hidden_states, ip_hidden_states
151
+ end_pos = encoder_hidden_states.shape[1] - self.num_tokens
152
+ encoder_hidden_states, ip_hidden_states = encoder_hidden_states[:, :end_pos, :], encoder_hidden_states[:, end_pos:, :]
153
+ if attn.norm_cross:
154
+ encoder_hidden_states = attn.norm_encoder_hidden_states(encoder_hidden_states)
155
+
156
+ key = attn.to_k(encoder_hidden_states)
157
+ value = attn.to_v(encoder_hidden_states)
158
+
159
+ query = attn.head_to_batch_dim(query)
160
+ key = attn.head_to_batch_dim(key)
161
+ value = attn.head_to_batch_dim(value)
162
+
163
+ if xformers_available:
164
+ hidden_states = self._memory_efficient_attention_xformers(query, key, value, attention_mask)
165
+ else:
166
+ attention_probs = attn.get_attention_scores(query, key, attention_mask)
167
+ hidden_states = torch.bmm(attention_probs, value)
168
+ hidden_states = attn.batch_to_head_dim(hidden_states)
169
+
170
+ # for ip-adapter
171
+ ip_key = self.to_k_ip(ip_hidden_states)
172
+ ip_value = self.to_v_ip(ip_hidden_states)
173
+
174
+ ip_key = attn.head_to_batch_dim(ip_key)
175
+ ip_value = attn.head_to_batch_dim(ip_value)
176
+
177
+ if xformers_available:
178
+ ip_hidden_states = self._memory_efficient_attention_xformers(query, ip_key, ip_value, None)
179
+ else:
180
+ ip_attention_probs = attn.get_attention_scores(query, ip_key, None)
181
+ ip_hidden_states = torch.bmm(ip_attention_probs, ip_value)
182
+ ip_hidden_states = attn.batch_to_head_dim(ip_hidden_states)
183
+
184
+ # region control
185
+ if len(region_control.prompt_image_conditioning) == 1:
186
+ region_mask = region_control.prompt_image_conditioning[0].get('region_mask', None)
187
+ if region_mask is not None:
188
+ h, w = region_mask.shape[:2]
189
+ ratio = (h * w / query.shape[1]) ** 0.5
190
+ mask = F.interpolate(region_mask[None, None], scale_factor=1/ratio, mode='nearest').reshape([1, -1, 1])
191
+ else:
192
+ mask = torch.ones_like(ip_hidden_states)
193
+ ip_hidden_states = ip_hidden_states * mask
194
+
195
+ hidden_states = hidden_states + self.scale * ip_hidden_states
196
+
197
+ # linear proj
198
+ hidden_states = attn.to_out[0](hidden_states)
199
+ # dropout
200
+ hidden_states = attn.to_out[1](hidden_states)
201
+
202
+ if input_ndim == 4:
203
+ hidden_states = hidden_states.transpose(-1, -2).reshape(batch_size, channel, height, width)
204
+
205
+ if attn.residual_connection:
206
+ hidden_states = hidden_states + residual
207
+
208
+ hidden_states = hidden_states / attn.rescale_output_factor
209
+
210
+ return hidden_states
211
+
212
+
213
+ def _memory_efficient_attention_xformers(self, query, key, value, attention_mask):
214
+ # TODO attention_mask
215
+ query = query.contiguous()
216
+ key = key.contiguous()
217
+ value = value.contiguous()
218
+ hidden_states = xformers.ops.memory_efficient_attention(query, key, value, attn_bias=attention_mask)
219
+ # hidden_states = self.reshape_batch_dim_to_heads(hidden_states)
220
+ return hidden_states
221
+
222
+
223
+ class AttnProcessor2_0(torch.nn.Module):
224
+ r"""
225
+ Processor for implementing scaled dot-product attention (enabled by default if you're using PyTorch 2.0).
226
+ """
227
+ def __init__(
228
+ self,
229
+ hidden_size=None,
230
+ cross_attention_dim=None,
231
+ ):
232
+ super().__init__()
233
+ if not hasattr(F, "scaled_dot_product_attention"):
234
+ raise ImportError("AttnProcessor2_0 requires PyTorch 2.0, to use it, please upgrade PyTorch to 2.0.")
235
+
236
+ def __call__(
237
+ self,
238
+ attn,
239
+ hidden_states,
240
+ encoder_hidden_states=None,
241
+ attention_mask=None,
242
+ temb=None,
243
+ ):
244
+ residual = hidden_states
245
+
246
+ if attn.spatial_norm is not None:
247
+ hidden_states = attn.spatial_norm(hidden_states, temb)
248
+
249
+ input_ndim = hidden_states.ndim
250
+
251
+ if input_ndim == 4:
252
+ batch_size, channel, height, width = hidden_states.shape
253
+ hidden_states = hidden_states.view(batch_size, channel, height * width).transpose(1, 2)
254
+
255
+ batch_size, sequence_length, _ = (
256
+ hidden_states.shape if encoder_hidden_states is None else encoder_hidden_states.shape
257
+ )
258
+
259
+ if attention_mask is not None:
260
+ attention_mask = attn.prepare_attention_mask(attention_mask, sequence_length, batch_size)
261
+ # scaled_dot_product_attention expects attention_mask shape to be
262
+ # (batch, heads, source_length, target_length)
263
+ attention_mask = attention_mask.view(batch_size, attn.heads, -1, attention_mask.shape[-1])
264
+
265
+ if attn.group_norm is not None:
266
+ hidden_states = attn.group_norm(hidden_states.transpose(1, 2)).transpose(1, 2)
267
+
268
+ query = attn.to_q(hidden_states)
269
+
270
+ if encoder_hidden_states is None:
271
+ encoder_hidden_states = hidden_states
272
+ elif attn.norm_cross:
273
+ encoder_hidden_states = attn.norm_encoder_hidden_states(encoder_hidden_states)
274
+
275
+ key = attn.to_k(encoder_hidden_states)
276
+ value = attn.to_v(encoder_hidden_states)
277
+
278
+ inner_dim = key.shape[-1]
279
+ head_dim = inner_dim // attn.heads
280
+
281
+ query = query.view(batch_size, -1, attn.heads, head_dim).transpose(1, 2)
282
+
283
+ key = key.view(batch_size, -1, attn.heads, head_dim).transpose(1, 2)
284
+ value = value.view(batch_size, -1, attn.heads, head_dim).transpose(1, 2)
285
+
286
+ # the output of sdp = (batch, num_heads, seq_len, head_dim)
287
+ # TODO: add support for attn.scale when we move to Torch 2.1
288
+ hidden_states = F.scaled_dot_product_attention(
289
+ query, key, value, attn_mask=attention_mask, dropout_p=0.0, is_causal=False
290
+ )
291
+
292
+ hidden_states = hidden_states.transpose(1, 2).reshape(batch_size, -1, attn.heads * head_dim)
293
+ hidden_states = hidden_states.to(query.dtype)
294
+
295
+ # linear proj
296
+ hidden_states = attn.to_out[0](hidden_states)
297
+ # dropout
298
+ hidden_states = attn.to_out[1](hidden_states)
299
+
300
+ if input_ndim == 4:
301
+ hidden_states = hidden_states.transpose(-1, -2).reshape(batch_size, channel, height, width)
302
+
303
+ if attn.residual_connection:
304
+ hidden_states = hidden_states + residual
305
+
306
+ hidden_states = hidden_states / attn.rescale_output_factor
307
+
308
+ return hidden_states
ComfyUI-InstantID/ip_adapter/resampler.py ADDED
@@ -0,0 +1,121 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ # modified from https://github.com/mlfoundations/open_flamingo/blob/main/open_flamingo/src/helpers.py
2
+ import math
3
+
4
+ import torch
5
+ import torch.nn as nn
6
+
7
+
8
+ # FFN
9
+ def FeedForward(dim, mult=4):
10
+ inner_dim = int(dim * mult)
11
+ return nn.Sequential(
12
+ nn.LayerNorm(dim),
13
+ nn.Linear(dim, inner_dim, bias=False),
14
+ nn.GELU(),
15
+ nn.Linear(inner_dim, dim, bias=False),
16
+ )
17
+
18
+
19
+ def reshape_tensor(x, heads):
20
+ bs, length, width = x.shape
21
+ #(bs, length, width) --> (bs, length, n_heads, dim_per_head)
22
+ x = x.view(bs, length, heads, -1)
23
+ # (bs, length, n_heads, dim_per_head) --> (bs, n_heads, length, dim_per_head)
24
+ x = x.transpose(1, 2)
25
+ # (bs, n_heads, length, dim_per_head) --> (bs*n_heads, length, dim_per_head)
26
+ x = x.reshape(bs, heads, length, -1)
27
+ return x
28
+
29
+
30
+ class PerceiverAttention(nn.Module):
31
+ def __init__(self, *, dim, dim_head=64, heads=8):
32
+ super().__init__()
33
+ self.scale = dim_head**-0.5
34
+ self.dim_head = dim_head
35
+ self.heads = heads
36
+ inner_dim = dim_head * heads
37
+
38
+ self.norm1 = nn.LayerNorm(dim)
39
+ self.norm2 = nn.LayerNorm(dim)
40
+
41
+ self.to_q = nn.Linear(dim, inner_dim, bias=False)
42
+ self.to_kv = nn.Linear(dim, inner_dim * 2, bias=False)
43
+ self.to_out = nn.Linear(inner_dim, dim, bias=False)
44
+
45
+
46
+ def forward(self, x, latents):
47
+ """
48
+ Args:
49
+ x (torch.Tensor): image features
50
+ shape (b, n1, D)
51
+ latent (torch.Tensor): latent features
52
+ shape (b, n2, D)
53
+ """
54
+ x = self.norm1(x)
55
+ latents = self.norm2(latents)
56
+
57
+ b, l, _ = latents.shape
58
+
59
+ q = self.to_q(latents)
60
+ kv_input = torch.cat((x, latents), dim=-2)
61
+ k, v = self.to_kv(kv_input).chunk(2, dim=-1)
62
+
63
+ q = reshape_tensor(q, self.heads)
64
+ k = reshape_tensor(k, self.heads)
65
+ v = reshape_tensor(v, self.heads)
66
+
67
+ # attention
68
+ scale = 1 / math.sqrt(math.sqrt(self.dim_head))
69
+ weight = (q * scale) @ (k * scale).transpose(-2, -1) # More stable with f16 than dividing afterwards
70
+ weight = torch.softmax(weight.float(), dim=-1).type(weight.dtype)
71
+ out = weight @ v
72
+
73
+ out = out.permute(0, 2, 1, 3).reshape(b, l, -1)
74
+
75
+ return self.to_out(out)
76
+
77
+
78
+ class Resampler(nn.Module):
79
+ def __init__(
80
+ self,
81
+ dim=1024,
82
+ depth=8,
83
+ dim_head=64,
84
+ heads=16,
85
+ num_queries=8,
86
+ embedding_dim=768,
87
+ output_dim=1024,
88
+ ff_mult=4,
89
+ ):
90
+ super().__init__()
91
+
92
+ self.latents = nn.Parameter(torch.randn(1, num_queries, dim) / dim**0.5)
93
+
94
+ self.proj_in = nn.Linear(embedding_dim, dim)
95
+
96
+ self.proj_out = nn.Linear(dim, output_dim)
97
+ self.norm_out = nn.LayerNorm(output_dim)
98
+
99
+ self.layers = nn.ModuleList([])
100
+ for _ in range(depth):
101
+ self.layers.append(
102
+ nn.ModuleList(
103
+ [
104
+ PerceiverAttention(dim=dim, dim_head=dim_head, heads=heads),
105
+ FeedForward(dim=dim, mult=ff_mult),
106
+ ]
107
+ )
108
+ )
109
+
110
+ def forward(self, x):
111
+
112
+ latents = self.latents.repeat(x.size(0), 1, 1)
113
+
114
+ x = self.proj_in(x)
115
+
116
+ for attn, ff in self.layers:
117
+ latents = attn(x, latents) + latents
118
+ latents = ff(latents) + latents
119
+
120
+ latents = self.proj_out(latents)
121
+ return self.norm_out(latents)
ComfyUI-InstantID/ip_adapter/utils.py ADDED
@@ -0,0 +1,5 @@
 
 
 
 
 
 
1
+ import torch.nn.functional as F
2
+
3
+
4
+ def is_torch2_available():
5
+ return hasattr(F, "scaled_dot_product_attention")
ComfyUI-InstantID/models/antelopev2/1k3d68.onnx ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:42c8b6575bc827380f1b27e4c80b326962531da96186fd1597fa35693fdc9515
3
+ size 137
ComfyUI-InstantID/models/antelopev2/2d106det.onnx ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:f75c331a32849d158fda14b6f8dbe84cf31ccb5db41e031bab768680b96f873f
3
+ size 135
ComfyUI-InstantID/models/antelopev2/genderage.onnx ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:f53e9ee9d98434da0782d1b205576c3a370dbc2331cd70188f8426a3aef121b9
3
+ size 135
ComfyUI-InstantID/models/antelopev2/glintr100.onnx ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:af374ec7db9ea896ee633dee1e1721e9f7957e19c43ce3fc9869950f82290c1e
3
+ size 137
ComfyUI-InstantID/models/antelopev2/scrfd_10g_bnkps.onnx ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:2e683c9e3c78b5b43aa3b5aa9566d06ab1befeae995ebc8259a7eb30f7b2421b
3
+ size 136
ComfyUI-InstantID/pipeline_stable_diffusion_xl_instantid.py ADDED
@@ -0,0 +1,753 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ # Copyright 2024 The InstantX Team. All rights reserved.
2
+ #
3
+ # Licensed under the Apache License, Version 2.0 (the "License");
4
+ # you may not use this file except in compliance with the License.
5
+ # You may obtain a copy of the License at
6
+ #
7
+ # http://www.apache.org/licenses/LICENSE-2.0
8
+ #
9
+ # Unless required by applicable law or agreed to in writing, software
10
+ # distributed under the License is distributed on an "AS IS" BASIS,
11
+ # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12
+ # See the License for the specific language governing permissions and
13
+ # limitations under the License.
14
+
15
+
16
+ from typing import Any, Callable, Dict, List, Optional, Tuple, Union
17
+
18
+ import cv2
19
+ import math
20
+
21
+ import numpy as np
22
+ import PIL.Image
23
+ import torch
24
+ import torch.nn.functional as F
25
+
26
+ from diffusers.image_processor import PipelineImageInput
27
+
28
+ from diffusers.models import ControlNetModel
29
+
30
+ from diffusers.utils import (
31
+ deprecate,
32
+ logging,
33
+ replace_example_docstring,
34
+ )
35
+ from diffusers.utils.torch_utils import is_compiled_module, is_torch_version
36
+ from diffusers.pipelines.stable_diffusion_xl import StableDiffusionXLPipelineOutput
37
+
38
+ from diffusers import StableDiffusionXLControlNetPipeline
39
+ from diffusers.pipelines.controlnet.multicontrolnet import MultiControlNetModel
40
+ from diffusers.utils.import_utils import is_xformers_available
41
+
42
+ from .ip_adapter.resampler import Resampler
43
+ from .ip_adapter.utils import is_torch2_available
44
+
45
+ from .ip_adapter.attention_processor import AttnProcessor, IPAttnProcessor
46
+
47
+ logger = logging.get_logger(__name__) # pylint: disable=invalid-name
48
+
49
+
50
+ EXAMPLE_DOC_STRING = """
51
+ Examples:
52
+ ```py
53
+ >>> # !pip install opencv-python transformers accelerate insightface
54
+ >>> import diffusers
55
+ >>> from diffusers.utils import load_image
56
+ >>> from diffusers.models import ControlNetModel
57
+
58
+ >>> import cv2
59
+ >>> import torch
60
+ >>> import numpy as np
61
+ >>> from PIL import Image
62
+
63
+ >>> from insightface.app import FaceAnalysis
64
+ >>> from pipeline_stable_diffusion_xl_instantid import StableDiffusionXLInstantIDPipeline, draw_kps
65
+
66
+ >>> # download 'antelopev2' under ./models
67
+ >>> app = FaceAnalysis(name='antelopev2', root='./', providers=['CUDAExecutionProvider', 'CPUExecutionProvider'])
68
+ >>> app.prepare(ctx_id=0, det_size=(640, 640))
69
+
70
+ >>> # download models under ./checkpoints
71
+ >>> face_adapter = f'./checkpoints/ip-adapter.bin'
72
+ >>> controlnet_path = f'./checkpoints/ControlNetModel'
73
+
74
+ >>> # load IdentityNet
75
+ >>> controlnet = ControlNetModel.from_pretrained(controlnet_path, torch_dtype=torch.float16)
76
+
77
+ >>> pipe = StableDiffusionXLInstantIDPipeline.from_pretrained(
78
+ ... "stabilityai/stable-diffusion-xl-base-1.0", controlnet=controlnet, torch_dtype=torch.float16
79
+ ... )
80
+ >>> pipe.cuda()
81
+
82
+ >>> # load adapter
83
+ >>> pipe.load_ip_adapter_instantid(face_adapter)
84
+
85
+ >>> prompt = "analog film photo of a man. faded film, desaturated, 35mm photo, grainy, vignette, vintage, Kodachrome, Lomography, stained, highly detailed, found footage, masterpiece, best quality"
86
+ >>> negative_prompt = "(lowres, low quality, worst quality:1.2), (text:1.2), watermark, painting, drawing, illustration, glitch, deformed, mutated, cross-eyed, ugly, disfigured (lowres, low quality, worst quality:1.2), (text:1.2), watermark, painting, drawing, illustration, glitch,deformed, mutated, cross-eyed, ugly, disfigured"
87
+
88
+ >>> # load an image
89
+ >>> image = load_image("your-example.jpg")
90
+
91
+ >>> face_info = app.get(cv2.cvtColor(np.array(face_image), cv2.COLOR_RGB2BGR))[-1]
92
+ >>> face_emb = face_info['embedding']
93
+ >>> face_kps = draw_kps(face_image, face_info['kps'])
94
+
95
+ >>> pipe.set_ip_adapter_scale(0.8)
96
+
97
+ >>> # generate image
98
+ >>> image = pipe(
99
+ ... prompt, image_embeds=face_emb, image=face_kps, controlnet_conditioning_scale=0.8
100
+ ... ).images[0]
101
+ ```
102
+ """
103
+
104
+ def draw_kps(image_pil, kps, color_list=[(255,0,0), (0,255,0), (0,0,255), (255,255,0), (255,0,255)]):
105
+
106
+ stickwidth = 4
107
+ limbSeq = np.array([[0, 2], [1, 2], [3, 2], [4, 2]])
108
+ kps = np.array(kps)
109
+
110
+ w, h = image_pil.size
111
+ out_img = np.zeros([h, w, 3])
112
+
113
+ for i in range(len(limbSeq)):
114
+ index = limbSeq[i]
115
+ color = color_list[index[0]]
116
+
117
+ x = kps[index][:, 0]
118
+ y = kps[index][:, 1]
119
+ length = ((x[0] - x[1]) ** 2 + (y[0] - y[1]) ** 2) ** 0.5
120
+ angle = math.degrees(math.atan2(y[0] - y[1], x[0] - x[1]))
121
+ polygon = cv2.ellipse2Poly((int(np.mean(x)), int(np.mean(y))), (int(length / 2), stickwidth), int(angle), 0, 360, 1)
122
+ out_img = cv2.fillConvexPoly(out_img.copy(), polygon, color)
123
+ out_img = (out_img * 0.6).astype(np.uint8)
124
+
125
+ for idx_kp, kp in enumerate(kps):
126
+ color = color_list[idx_kp]
127
+ x, y = kp
128
+ out_img = cv2.circle(out_img.copy(), (int(x), int(y)), 10, color, -1)
129
+
130
+ out_img_pil = PIL.Image.fromarray(out_img.astype(np.uint8))
131
+ return out_img_pil
132
+
133
+ class StableDiffusionXLInstantIDPipeline(StableDiffusionXLControlNetPipeline):
134
+
135
+ def cuda(self, dtype=torch.float16, use_xformers=False):
136
+ self.to('cuda', dtype)
137
+
138
+ if hasattr(self, 'image_proj_model'):
139
+ self.image_proj_model.to(self.unet.device).to(self.unet.dtype)
140
+
141
+ if use_xformers:
142
+ if is_xformers_available():
143
+ import xformers
144
+ from packaging import version
145
+
146
+ xformers_version = version.parse(xformers.__version__)
147
+ if xformers_version == version.parse("0.0.16"):
148
+ logger.warn(
149
+ "xFormers 0.0.16 cannot be used for training in some GPUs. If you observe problems during training, please update xFormers to at least 0.0.17. See https://huggingface.co/docs/diffusers/main/en/optimization/xformers for more details."
150
+ )
151
+ self.enable_xformers_memory_efficient_attention()
152
+ else:
153
+ raise ValueError("xformers is not available. Make sure it is installed correctly")
154
+
155
+ def load_ip_adapter_instantid(self, model_ckpt, image_emb_dim=512, num_tokens=16, scale=0.5):
156
+ self.set_image_proj_model(model_ckpt, image_emb_dim, num_tokens)
157
+ self.set_ip_adapter(model_ckpt, num_tokens, scale)
158
+
159
+ def set_image_proj_model(self, model_ckpt, image_emb_dim=512, num_tokens=16):
160
+
161
+ image_proj_model = Resampler(
162
+ dim=1280,
163
+ depth=4,
164
+ dim_head=64,
165
+ heads=20,
166
+ num_queries=num_tokens,
167
+ embedding_dim=image_emb_dim,
168
+ output_dim=self.unet.config.cross_attention_dim,
169
+ ff_mult=4,
170
+ )
171
+
172
+ image_proj_model.eval()
173
+
174
+ self.image_proj_model = image_proj_model.to(self.device, dtype=self.dtype)
175
+ state_dict = torch.load(model_ckpt, map_location="cpu")
176
+ if 'image_proj' in state_dict:
177
+ state_dict = state_dict["image_proj"]
178
+ self.image_proj_model.load_state_dict(state_dict)
179
+
180
+ self.image_proj_model_in_features = image_emb_dim
181
+
182
+ def set_ip_adapter(self, model_ckpt, num_tokens, scale):
183
+
184
+ unet = self.unet
185
+ attn_procs = {}
186
+ for name in unet.attn_processors.keys():
187
+ cross_attention_dim = None if name.endswith("attn1.processor") else unet.config.cross_attention_dim
188
+ if name.startswith("mid_block"):
189
+ hidden_size = unet.config.block_out_channels[-1]
190
+ elif name.startswith("up_blocks"):
191
+ block_id = int(name[len("up_blocks.")])
192
+ hidden_size = list(reversed(unet.config.block_out_channels))[block_id]
193
+ elif name.startswith("down_blocks"):
194
+ block_id = int(name[len("down_blocks.")])
195
+ hidden_size = unet.config.block_out_channels[block_id]
196
+ if cross_attention_dim is None:
197
+ attn_procs[name] = AttnProcessor().to(unet.device, dtype=unet.dtype)
198
+ else:
199
+ attn_procs[name] = IPAttnProcessor(hidden_size=hidden_size,
200
+ cross_attention_dim=cross_attention_dim,
201
+ scale=scale,
202
+ num_tokens=num_tokens).to(unet.device, dtype=unet.dtype)
203
+ unet.set_attn_processor(attn_procs)
204
+
205
+ state_dict = torch.load(model_ckpt, map_location="cpu")
206
+ ip_layers = torch.nn.ModuleList(self.unet.attn_processors.values())
207
+ if 'ip_adapter' in state_dict:
208
+ state_dict = state_dict['ip_adapter']
209
+ ip_layers.load_state_dict(state_dict)
210
+
211
+ def set_ip_adapter_scale(self, scale):
212
+ unet = getattr(self, self.unet_name) if not hasattr(self, "unet") else self.unet
213
+ for attn_processor in unet.attn_processors.values():
214
+ if isinstance(attn_processor, IPAttnProcessor):
215
+ attn_processor.scale = scale
216
+
217
+ def _encode_prompt_image_emb(self, prompt_image_emb, device, dtype, do_classifier_free_guidance):
218
+
219
+ if isinstance(prompt_image_emb, torch.Tensor):
220
+ prompt_image_emb = prompt_image_emb.clone().detach()
221
+ else:
222
+ prompt_image_emb = torch.tensor(prompt_image_emb)
223
+
224
+ prompt_image_emb = prompt_image_emb.to(device=device, dtype=dtype)
225
+ prompt_image_emb = prompt_image_emb.reshape([1, -1, self.image_proj_model_in_features])
226
+
227
+ if do_classifier_free_guidance:
228
+ prompt_image_emb = torch.cat([torch.zeros_like(prompt_image_emb), prompt_image_emb], dim=0)
229
+ else:
230
+ prompt_image_emb = torch.cat([prompt_image_emb], dim=0)
231
+
232
+ prompt_image_emb = self.image_proj_model(prompt_image_emb)
233
+ return prompt_image_emb
234
+
235
+ @torch.no_grad()
236
+ @replace_example_docstring(EXAMPLE_DOC_STRING)
237
+ def __call__(
238
+ self,
239
+ prompt: Union[str, List[str]] = None,
240
+ prompt_2: Optional[Union[str, List[str]]] = None,
241
+ image: PipelineImageInput = None,
242
+ height: Optional[int] = None,
243
+ width: Optional[int] = None,
244
+ num_inference_steps: int = 50,
245
+ guidance_scale: float = 5.0,
246
+ negative_prompt: Optional[Union[str, List[str]]] = None,
247
+ negative_prompt_2: Optional[Union[str, List[str]]] = None,
248
+ num_images_per_prompt: Optional[int] = 1,
249
+ eta: float = 0.0,
250
+ generator: Optional[Union[torch.Generator, List[torch.Generator]]] = None,
251
+ latents: Optional[torch.FloatTensor] = None,
252
+ prompt_embeds: Optional[torch.FloatTensor] = None,
253
+ negative_prompt_embeds: Optional[torch.FloatTensor] = None,
254
+ pooled_prompt_embeds: Optional[torch.FloatTensor] = None,
255
+ negative_pooled_prompt_embeds: Optional[torch.FloatTensor] = None,
256
+ image_embeds: Optional[torch.FloatTensor] = None,
257
+ output_type: Optional[str] = "pil",
258
+ return_dict: bool = True,
259
+ cross_attention_kwargs: Optional[Dict[str, Any]] = None,
260
+ controlnet_conditioning_scale: Union[float, List[float]] = 1.0,
261
+ guess_mode: bool = False,
262
+ control_guidance_start: Union[float, List[float]] = 0.0,
263
+ control_guidance_end: Union[float, List[float]] = 1.0,
264
+ original_size: Tuple[int, int] = None,
265
+ crops_coords_top_left: Tuple[int, int] = (0, 0),
266
+ target_size: Tuple[int, int] = None,
267
+ negative_original_size: Optional[Tuple[int, int]] = None,
268
+ negative_crops_coords_top_left: Tuple[int, int] = (0, 0),
269
+ negative_target_size: Optional[Tuple[int, int]] = None,
270
+ clip_skip: Optional[int] = None,
271
+ callback_on_step_end: Optional[Callable[[int, int, Dict], None]] = None,
272
+ callback_on_step_end_tensor_inputs: List[str] = ["latents"],
273
+ **kwargs,
274
+ ):
275
+ r"""
276
+ The call function to the pipeline for generation.
277
+
278
+ Args:
279
+ prompt (`str` or `List[str]`, *optional*):
280
+ The prompt or prompts to guide image generation. If not defined, you need to pass `prompt_embeds`.
281
+ prompt_2 (`str` or `List[str]`, *optional*):
282
+ The prompt or prompts to be sent to `tokenizer_2` and `text_encoder_2`. If not defined, `prompt` is
283
+ used in both text-encoders.
284
+ image (`torch.FloatTensor`, `PIL.Image.Image`, `np.ndarray`, `List[torch.FloatTensor]`, `List[PIL.Image.Image]`, `List[np.ndarray]`,:
285
+ `List[List[torch.FloatTensor]]`, `List[List[np.ndarray]]` or `List[List[PIL.Image.Image]]`):
286
+ The ControlNet input condition to provide guidance to the `unet` for generation. If the type is
287
+ specified as `torch.FloatTensor`, it is passed to ControlNet as is. `PIL.Image.Image` can also be
288
+ accepted as an image. The dimensions of the output image defaults to `image`'s dimensions. If height
289
+ and/or width are passed, `image` is resized accordingly. If multiple ControlNets are specified in
290
+ `init`, images must be passed as a list such that each element of the list can be correctly batched for
291
+ input to a single ControlNet.
292
+ height (`int`, *optional*, defaults to `self.unet.config.sample_size * self.vae_scale_factor`):
293
+ The height in pixels of the generated image. Anything below 512 pixels won't work well for
294
+ [stabilityai/stable-diffusion-xl-base-1.0](https://huggingface.co/stabilityai/stable-diffusion-xl-base-1.0)
295
+ and checkpoints that are not specifically fine-tuned on low resolutions.
296
+ width (`int`, *optional*, defaults to `self.unet.config.sample_size * self.vae_scale_factor`):
297
+ The width in pixels of the generated image. Anything below 512 pixels won't work well for
298
+ [stabilityai/stable-diffusion-xl-base-1.0](https://huggingface.co/stabilityai/stable-diffusion-xl-base-1.0)
299
+ and checkpoints that are not specifically fine-tuned on low resolutions.
300
+ num_inference_steps (`int`, *optional*, defaults to 50):
301
+ The number of denoising steps. More denoising steps usually lead to a higher quality image at the
302
+ expense of slower inference.
303
+ guidance_scale (`float`, *optional*, defaults to 5.0):
304
+ A higher guidance scale value encourages the model to generate images closely linked to the text
305
+ `prompt` at the expense of lower image quality. Guidance scale is enabled when `guidance_scale > 1`.
306
+ negative_prompt (`str` or `List[str]`, *optional*):
307
+ The prompt or prompts to guide what to not include in image generation. If not defined, you need to
308
+ pass `negative_prompt_embeds` instead. Ignored when not using guidance (`guidance_scale < 1`).
309
+ negative_prompt_2 (`str` or `List[str]`, *optional*):
310
+ The prompt or prompts to guide what to not include in image generation. This is sent to `tokenizer_2`
311
+ and `text_encoder_2`. If not defined, `negative_prompt` is used in both text-encoders.
312
+ num_images_per_prompt (`int`, *optional*, defaults to 1):
313
+ The number of images to generate per prompt.
314
+ eta (`float`, *optional*, defaults to 0.0):
315
+ Corresponds to parameter eta (η) from the [DDIM](https://arxiv.org/abs/2010.02502) paper. Only applies
316
+ to the [`~schedulers.DDIMScheduler`], and is ignored in other schedulers.
317
+ generator (`torch.Generator` or `List[torch.Generator]`, *optional*):
318
+ A [`torch.Generator`](https://pytorch.org/docs/stable/generated/torch.Generator.html) to make
319
+ generation deterministic.
320
+ latents (`torch.FloatTensor`, *optional*):
321
+ Pre-generated noisy latents sampled from a Gaussian distribution, to be used as inputs for image
322
+ generation. Can be used to tweak the same generation with different prompts. If not provided, a latents
323
+ tensor is generated by sampling using the supplied random `generator`.
324
+ prompt_embeds (`torch.FloatTensor`, *optional*):
325
+ Pre-generated text embeddings. Can be used to easily tweak text inputs (prompt weighting). If not
326
+ provided, text embeddings are generated from the `prompt` input argument.
327
+ negative_prompt_embeds (`torch.FloatTensor`, *optional*):
328
+ Pre-generated negative text embeddings. Can be used to easily tweak text inputs (prompt weighting). If
329
+ not provided, `negative_prompt_embeds` are generated from the `negative_prompt` input argument.
330
+ pooled_prompt_embeds (`torch.FloatTensor`, *optional*):
331
+ Pre-generated pooled text embeddings. Can be used to easily tweak text inputs (prompt weighting). If
332
+ not provided, pooled text embeddings are generated from `prompt` input argument.
333
+ negative_pooled_prompt_embeds (`torch.FloatTensor`, *optional*):
334
+ Pre-generated negative pooled text embeddings. Can be used to easily tweak text inputs (prompt
335
+ weighting). If not provided, pooled `negative_prompt_embeds` are generated from `negative_prompt` input
336
+ argument.
337
+ image_embeds (`torch.FloatTensor`, *optional*):
338
+ Pre-generated image embeddings.
339
+ output_type (`str`, *optional*, defaults to `"pil"`):
340
+ The output format of the generated image. Choose between `PIL.Image` or `np.array`.
341
+ return_dict (`bool`, *optional*, defaults to `True`):
342
+ Whether or not to return a [`~pipelines.stable_diffusion.StableDiffusionPipelineOutput`] instead of a
343
+ plain tuple.
344
+ cross_attention_kwargs (`dict`, *optional*):
345
+ A kwargs dictionary that if specified is passed along to the [`AttentionProcessor`] as defined in
346
+ [`self.processor`](https://github.com/huggingface/diffusers/blob/main/src/diffusers/models/attention_processor.py).
347
+ controlnet_conditioning_scale (`float` or `List[float]`, *optional*, defaults to 1.0):
348
+ The outputs of the ControlNet are multiplied by `controlnet_conditioning_scale` before they are added
349
+ to the residual in the original `unet`. If multiple ControlNets are specified in `init`, you can set
350
+ the corresponding scale as a list.
351
+ guess_mode (`bool`, *optional*, defaults to `False`):
352
+ The ControlNet encoder tries to recognize the content of the input image even if you remove all
353
+ prompts. A `guidance_scale` value between 3.0 and 5.0 is recommended.
354
+ control_guidance_start (`float` or `List[float]`, *optional*, defaults to 0.0):
355
+ The percentage of total steps at which the ControlNet starts applying.
356
+ control_guidance_end (`float` or `List[float]`, *optional*, defaults to 1.0):
357
+ The percentage of total steps at which the ControlNet stops applying.
358
+ original_size (`Tuple[int]`, *optional*, defaults to (1024, 1024)):
359
+ If `original_size` is not the same as `target_size` the image will appear to be down- or upsampled.
360
+ `original_size` defaults to `(height, width)` if not specified. Part of SDXL's micro-conditioning as
361
+ explained in section 2.2 of
362
+ [https://huggingface.co/papers/2307.01952](https://huggingface.co/papers/2307.01952).
363
+ crops_coords_top_left (`Tuple[int]`, *optional*, defaults to (0, 0)):
364
+ `crops_coords_top_left` can be used to generate an image that appears to be "cropped" from the position
365
+ `crops_coords_top_left` downwards. Favorable, well-centered images are usually achieved by setting
366
+ `crops_coords_top_left` to (0, 0). Part of SDXL's micro-conditioning as explained in section 2.2 of
367
+ [https://huggingface.co/papers/2307.01952](https://huggingface.co/papers/2307.01952).
368
+ target_size (`Tuple[int]`, *optional*, defaults to (1024, 1024)):
369
+ For most cases, `target_size` should be set to the desired height and width of the generated image. If
370
+ not specified it will default to `(height, width)`. Part of SDXL's micro-conditioning as explained in
371
+ section 2.2 of [https://huggingface.co/papers/2307.01952](https://huggingface.co/papers/2307.01952).
372
+ negative_original_size (`Tuple[int]`, *optional*, defaults to (1024, 1024)):
373
+ To negatively condition the generation process based on a specific image resolution. Part of SDXL's
374
+ micro-conditioning as explained in section 2.2 of
375
+ [https://huggingface.co/papers/2307.01952](https://huggingface.co/papers/2307.01952). For more
376
+ information, refer to this issue thread: https://github.com/huggingface/diffusers/issues/4208.
377
+ negative_crops_coords_top_left (`Tuple[int]`, *optional*, defaults to (0, 0)):
378
+ To negatively condition the generation process based on a specific crop coordinates. Part of SDXL's
379
+ micro-conditioning as explained in section 2.2 of
380
+ [https://huggingface.co/papers/2307.01952](https://huggingface.co/papers/2307.01952). For more
381
+ information, refer to this issue thread: https://github.com/huggingface/diffusers/issues/4208.
382
+ negative_target_size (`Tuple[int]`, *optional*, defaults to (1024, 1024)):
383
+ To negatively condition the generation process based on a target image resolution. It should be as same
384
+ as the `target_size` for most cases. Part of SDXL's micro-conditioning as explained in section 2.2 of
385
+ [https://huggingface.co/papers/2307.01952](https://huggingface.co/papers/2307.01952). For more
386
+ information, refer to this issue thread: https://github.com/huggingface/diffusers/issues/4208.
387
+ clip_skip (`int`, *optional*):
388
+ Number of layers to be skipped from CLIP while computing the prompt embeddings. A value of 1 means that
389
+ the output of the pre-final layer will be used for computing the prompt embeddings.
390
+ callback_on_step_end (`Callable`, *optional*):
391
+ A function that calls at the end of each denoising steps during the inference. The function is called
392
+ with the following arguments: `callback_on_step_end(self: DiffusionPipeline, step: int, timestep: int,
393
+ callback_kwargs: Dict)`. `callback_kwargs` will include a list of all tensors as specified by
394
+ `callback_on_step_end_tensor_inputs`.
395
+ callback_on_step_end_tensor_inputs (`List`, *optional*):
396
+ The list of tensor inputs for the `callback_on_step_end` function. The tensors specified in the list
397
+ will be passed as `callback_kwargs` argument. You will only be able to include variables listed in the
398
+ `._callback_tensor_inputs` attribute of your pipeine class.
399
+
400
+ Examples:
401
+
402
+ Returns:
403
+ [`~pipelines.stable_diffusion.StableDiffusionPipelineOutput`] or `tuple`:
404
+ If `return_dict` is `True`, [`~pipelines.stable_diffusion.StableDiffusionPipelineOutput`] is returned,
405
+ otherwise a `tuple` is returned containing the output images.
406
+ """
407
+
408
+ callback = kwargs.pop("callback", None)
409
+ callback_steps = kwargs.pop("callback_steps", None)
410
+
411
+ if callback is not None:
412
+ deprecate(
413
+ "callback",
414
+ "1.0.0",
415
+ "Passing `callback` as an input argument to `__call__` is deprecated, consider using `callback_on_step_end`",
416
+ )
417
+ if callback_steps is not None:
418
+ deprecate(
419
+ "callback_steps",
420
+ "1.0.0",
421
+ "Passing `callback_steps` as an input argument to `__call__` is deprecated, consider using `callback_on_step_end`",
422
+ )
423
+
424
+ controlnet = self.controlnet._orig_mod if is_compiled_module(self.controlnet) else self.controlnet
425
+
426
+ # align format for control guidance
427
+ if not isinstance(control_guidance_start, list) and isinstance(control_guidance_end, list):
428
+ control_guidance_start = len(control_guidance_end) * [control_guidance_start]
429
+ elif not isinstance(control_guidance_end, list) and isinstance(control_guidance_start, list):
430
+ control_guidance_end = len(control_guidance_start) * [control_guidance_end]
431
+ elif not isinstance(control_guidance_start, list) and not isinstance(control_guidance_end, list):
432
+ mult = len(controlnet.nets) if isinstance(controlnet, MultiControlNetModel) else 1
433
+ control_guidance_start, control_guidance_end = (
434
+ mult * [control_guidance_start],
435
+ mult * [control_guidance_end],
436
+ )
437
+
438
+ # 1. Check inputs. Raise error if not correct
439
+ self.check_inputs(
440
+ prompt,
441
+ prompt_2,
442
+ image,
443
+ callback_steps,
444
+ negative_prompt,
445
+ negative_prompt_2,
446
+ prompt_embeds,
447
+ negative_prompt_embeds,
448
+ pooled_prompt_embeds,
449
+ negative_pooled_prompt_embeds,
450
+ controlnet_conditioning_scale,
451
+ control_guidance_start,
452
+ control_guidance_end,
453
+ callback_on_step_end_tensor_inputs,
454
+ )
455
+
456
+ self._guidance_scale = guidance_scale
457
+ self._clip_skip = clip_skip
458
+ self._cross_attention_kwargs = cross_attention_kwargs
459
+
460
+ # 2. Define call parameters
461
+ if prompt is not None and isinstance(prompt, str):
462
+ batch_size = 1
463
+ elif prompt is not None and isinstance(prompt, list):
464
+ batch_size = len(prompt)
465
+ else:
466
+ batch_size = prompt_embeds.shape[0]
467
+
468
+ device = self._execution_device
469
+
470
+ if isinstance(controlnet, MultiControlNetModel) and isinstance(controlnet_conditioning_scale, float):
471
+ controlnet_conditioning_scale = [controlnet_conditioning_scale] * len(controlnet.nets)
472
+
473
+ global_pool_conditions = (
474
+ controlnet.config.global_pool_conditions
475
+ if isinstance(controlnet, ControlNetModel)
476
+ else controlnet.nets[0].config.global_pool_conditions
477
+ )
478
+ guess_mode = guess_mode or global_pool_conditions
479
+
480
+ # 3.1 Encode input prompt
481
+ text_encoder_lora_scale = (
482
+ self.cross_attention_kwargs.get("scale", None) if self.cross_attention_kwargs is not None else None
483
+ )
484
+ (
485
+ prompt_embeds,
486
+ negative_prompt_embeds,
487
+ pooled_prompt_embeds,
488
+ negative_pooled_prompt_embeds,
489
+ ) = self.encode_prompt(
490
+ prompt,
491
+ prompt_2,
492
+ device,
493
+ num_images_per_prompt,
494
+ self.do_classifier_free_guidance,
495
+ negative_prompt,
496
+ negative_prompt_2,
497
+ prompt_embeds=prompt_embeds,
498
+ negative_prompt_embeds=negative_prompt_embeds,
499
+ pooled_prompt_embeds=pooled_prompt_embeds,
500
+ negative_pooled_prompt_embeds=negative_pooled_prompt_embeds,
501
+ lora_scale=text_encoder_lora_scale,
502
+ clip_skip=self.clip_skip,
503
+ )
504
+
505
+ # 3.2 Encode image prompt
506
+ prompt_image_emb = self._encode_prompt_image_emb(image_embeds,
507
+ device,
508
+ self.unet.dtype,
509
+ self.do_classifier_free_guidance)
510
+
511
+ # 4. Prepare image
512
+ if isinstance(controlnet, ControlNetModel):
513
+ image = self.prepare_image(
514
+ image=image,
515
+ width=width,
516
+ height=height,
517
+ batch_size=batch_size * num_images_per_prompt,
518
+ num_images_per_prompt=num_images_per_prompt,
519
+ device=device,
520
+ dtype=controlnet.dtype,
521
+ do_classifier_free_guidance=self.do_classifier_free_guidance,
522
+ guess_mode=guess_mode,
523
+ )
524
+ height, width = image.shape[-2:]
525
+ elif isinstance(controlnet, MultiControlNetModel):
526
+ images = []
527
+
528
+ for image_ in image:
529
+ image_ = self.prepare_image(
530
+ image=image_,
531
+ width=width,
532
+ height=height,
533
+ batch_size=batch_size * num_images_per_prompt,
534
+ num_images_per_prompt=num_images_per_prompt,
535
+ device=device,
536
+ dtype=controlnet.dtype,
537
+ do_classifier_free_guidance=self.do_classifier_free_guidance,
538
+ guess_mode=guess_mode,
539
+ )
540
+
541
+ images.append(image_)
542
+
543
+ image = images
544
+ height, width = image[0].shape[-2:]
545
+ else:
546
+ assert False
547
+
548
+ # 5. Prepare timesteps
549
+ self.scheduler.set_timesteps(num_inference_steps, device=device)
550
+ timesteps = self.scheduler.timesteps
551
+ self._num_timesteps = len(timesteps)
552
+
553
+ # 6. Prepare latent variables
554
+ num_channels_latents = self.unet.config.in_channels
555
+ latents = self.prepare_latents(
556
+ batch_size * num_images_per_prompt,
557
+ num_channels_latents,
558
+ height,
559
+ width,
560
+ prompt_embeds.dtype,
561
+ device,
562
+ generator,
563
+ latents,
564
+ )
565
+
566
+ # 6.5 Optionally get Guidance Scale Embedding
567
+ timestep_cond = None
568
+ if self.unet.config.time_cond_proj_dim is not None:
569
+ guidance_scale_tensor = torch.tensor(self.guidance_scale - 1).repeat(batch_size * num_images_per_prompt)
570
+ timestep_cond = self.get_guidance_scale_embedding(
571
+ guidance_scale_tensor, embedding_dim=self.unet.config.time_cond_proj_dim
572
+ ).to(device=device, dtype=latents.dtype)
573
+
574
+ # 7. Prepare extra step kwargs. TODO: Logic should ideally just be moved out of the pipeline
575
+ extra_step_kwargs = self.prepare_extra_step_kwargs(generator, eta)
576
+
577
+ # 7.1 Create tensor stating which controlnets to keep
578
+ controlnet_keep = []
579
+ for i in range(len(timesteps)):
580
+ keeps = [
581
+ 1.0 - float(i / len(timesteps) < s or (i + 1) / len(timesteps) > e)
582
+ for s, e in zip(control_guidance_start, control_guidance_end)
583
+ ]
584
+ controlnet_keep.append(keeps[0] if isinstance(controlnet, ControlNetModel) else keeps)
585
+
586
+ # 7.2 Prepare added time ids & embeddings
587
+ if isinstance(image, list):
588
+ original_size = original_size or image[0].shape[-2:]
589
+ else:
590
+ original_size = original_size or image.shape[-2:]
591
+ target_size = target_size or (height, width)
592
+
593
+ add_text_embeds = pooled_prompt_embeds
594
+ if self.text_encoder_2 is None:
595
+ text_encoder_projection_dim = int(pooled_prompt_embeds.shape[-1])
596
+ else:
597
+ text_encoder_projection_dim = self.text_encoder_2.config.projection_dim
598
+
599
+ add_time_ids = self._get_add_time_ids(
600
+ original_size,
601
+ crops_coords_top_left,
602
+ target_size,
603
+ dtype=prompt_embeds.dtype,
604
+ text_encoder_projection_dim=text_encoder_projection_dim,
605
+ )
606
+
607
+ if negative_original_size is not None and negative_target_size is not None:
608
+ negative_add_time_ids = self._get_add_time_ids(
609
+ negative_original_size,
610
+ negative_crops_coords_top_left,
611
+ negative_target_size,
612
+ dtype=prompt_embeds.dtype,
613
+ text_encoder_projection_dim=text_encoder_projection_dim,
614
+ )
615
+ else:
616
+ negative_add_time_ids = add_time_ids
617
+
618
+ if self.do_classifier_free_guidance:
619
+ prompt_embeds = torch.cat([negative_prompt_embeds, prompt_embeds], dim=0)
620
+ add_text_embeds = torch.cat([negative_pooled_prompt_embeds, add_text_embeds], dim=0)
621
+ add_time_ids = torch.cat([negative_add_time_ids, add_time_ids], dim=0)
622
+
623
+ prompt_embeds = prompt_embeds.to(device)
624
+ add_text_embeds = add_text_embeds.to(device)
625
+ add_time_ids = add_time_ids.to(device).repeat(batch_size * num_images_per_prompt, 1)
626
+ encoder_hidden_states = torch.cat([prompt_embeds, prompt_image_emb], dim=1)
627
+
628
+ # 8. Denoising loop
629
+ num_warmup_steps = len(timesteps) - num_inference_steps * self.scheduler.order
630
+ is_unet_compiled = is_compiled_module(self.unet)
631
+ is_controlnet_compiled = is_compiled_module(self.controlnet)
632
+ is_torch_higher_equal_2_1 = is_torch_version(">=", "2.1")
633
+
634
+ with self.progress_bar(total=num_inference_steps) as progress_bar:
635
+ for i, t in enumerate(timesteps):
636
+ # Relevant thread:
637
+ # https://dev-discuss.pytorch.org/t/cudagraphs-in-pytorch-2-0/1428
638
+ if (is_unet_compiled and is_controlnet_compiled) and is_torch_higher_equal_2_1:
639
+ torch._inductor.cudagraph_mark_step_begin()
640
+ # expand the latents if we are doing classifier free guidance
641
+ latent_model_input = torch.cat([latents] * 2) if self.do_classifier_free_guidance else latents
642
+ latent_model_input = self.scheduler.scale_model_input(latent_model_input, t)
643
+
644
+ added_cond_kwargs = {"text_embeds": add_text_embeds, "time_ids": add_time_ids}
645
+
646
+ # controlnet(s) inference
647
+ if guess_mode and self.do_classifier_free_guidance:
648
+ # Infer ControlNet only for the conditional batch.
649
+ control_model_input = latents
650
+ control_model_input = self.scheduler.scale_model_input(control_model_input, t)
651
+ controlnet_prompt_embeds = prompt_embeds.chunk(2)[1]
652
+ controlnet_added_cond_kwargs = {
653
+ "text_embeds": add_text_embeds.chunk(2)[1],
654
+ "time_ids": add_time_ids.chunk(2)[1],
655
+ }
656
+ else:
657
+ control_model_input = latent_model_input
658
+ controlnet_prompt_embeds = prompt_embeds
659
+ controlnet_added_cond_kwargs = added_cond_kwargs
660
+
661
+ if isinstance(controlnet_keep[i], list):
662
+ cond_scale = [c * s for c, s in zip(controlnet_conditioning_scale, controlnet_keep[i])]
663
+ else:
664
+ controlnet_cond_scale = controlnet_conditioning_scale
665
+ if isinstance(controlnet_cond_scale, list):
666
+ controlnet_cond_scale = controlnet_cond_scale[0]
667
+ cond_scale = controlnet_cond_scale * controlnet_keep[i]
668
+
669
+ down_block_res_samples, mid_block_res_sample = self.controlnet(
670
+ control_model_input,
671
+ t,
672
+ encoder_hidden_states=prompt_image_emb,
673
+ controlnet_cond=image,
674
+ conditioning_scale=cond_scale,
675
+ guess_mode=guess_mode,
676
+ added_cond_kwargs=controlnet_added_cond_kwargs,
677
+ return_dict=False,
678
+ )
679
+
680
+ if guess_mode and self.do_classifier_free_guidance:
681
+ # Infered ControlNet only for the conditional batch.
682
+ # To apply the output of ControlNet to both the unconditional and conditional batches,
683
+ # add 0 to the unconditional batch to keep it unchanged.
684
+ down_block_res_samples = [torch.cat([torch.zeros_like(d), d]) for d in down_block_res_samples]
685
+ mid_block_res_sample = torch.cat([torch.zeros_like(mid_block_res_sample), mid_block_res_sample])
686
+
687
+ # predict the noise residual
688
+ noise_pred = self.unet(
689
+ latent_model_input,
690
+ t,
691
+ encoder_hidden_states=encoder_hidden_states,
692
+ timestep_cond=timestep_cond,
693
+ cross_attention_kwargs=self.cross_attention_kwargs,
694
+ down_block_additional_residuals=down_block_res_samples,
695
+ mid_block_additional_residual=mid_block_res_sample,
696
+ added_cond_kwargs=added_cond_kwargs,
697
+ return_dict=False,
698
+ )[0]
699
+
700
+ # perform guidance
701
+ if self.do_classifier_free_guidance:
702
+ noise_pred_uncond, noise_pred_text = noise_pred.chunk(2)
703
+ noise_pred = noise_pred_uncond + guidance_scale * (noise_pred_text - noise_pred_uncond)
704
+
705
+ # compute the previous noisy sample x_t -> x_t-1
706
+ latents = self.scheduler.step(noise_pred, t, latents, **extra_step_kwargs, return_dict=False)[0]
707
+
708
+ if callback_on_step_end is not None:
709
+ callback_kwargs = {}
710
+ for k in callback_on_step_end_tensor_inputs:
711
+ callback_kwargs[k] = locals()[k]
712
+ callback_outputs = callback_on_step_end(self, i, t, callback_kwargs)
713
+
714
+ latents = callback_outputs.pop("latents", latents)
715
+ prompt_embeds = callback_outputs.pop("prompt_embeds", prompt_embeds)
716
+ negative_prompt_embeds = callback_outputs.pop("negative_prompt_embeds", negative_prompt_embeds)
717
+
718
+ # call the callback, if provided
719
+ if i == len(timesteps) - 1 or ((i + 1) > num_warmup_steps and (i + 1) % self.scheduler.order == 0):
720
+ progress_bar.update()
721
+ if callback is not None and i % callback_steps == 0:
722
+ step_idx = i // getattr(self.scheduler, "order", 1)
723
+ callback(step_idx, t, latents)
724
+
725
+ if not output_type == "latent":
726
+ # make sure the VAE is in float32 mode, as it overflows in float16
727
+ needs_upcasting = self.vae.dtype == torch.float16 and self.vae.config.force_upcast
728
+ if needs_upcasting:
729
+ self.upcast_vae()
730
+ latents = latents.to(next(iter(self.vae.post_quant_conv.parameters())).dtype)
731
+
732
+ image = self.vae.decode(latents / self.vae.config.scaling_factor, return_dict=False)[0]
733
+
734
+ # cast back to fp16 if needed
735
+ if needs_upcasting:
736
+ self.vae.to(dtype=torch.float16)
737
+ else:
738
+ image = latents
739
+
740
+ if not output_type == "latent":
741
+ # apply watermark if available
742
+ if self.watermark is not None:
743
+ image = self.watermark.apply_watermark(image)
744
+
745
+ image = self.image_processor.postprocess(image, output_type=output_type)
746
+
747
+ # Offload all models
748
+ self.maybe_free_model_hooks()
749
+
750
+ if not return_dict:
751
+ return (image,)
752
+
753
+ return StableDiffusionXLPipelineOutput(images=image)
ComfyUI-InstantID/requirements.txt ADDED
@@ -0,0 +1,6 @@
 
 
 
 
 
 
 
1
+ opencv-python
2
+ transformers
3
+ accelerate
4
+ insightface
5
+ diffusers
6
+ onnxruntime-gpu
ComfyUI-InstantID/style_template.py ADDED
@@ -0,0 +1,49 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ style_list = [
2
+ {
3
+ "name": "(No style)",
4
+ "prompt": "{prompt}",
5
+ "negative_prompt": "",
6
+ },
7
+ {
8
+ "name": "Watercolor",
9
+ "prompt": "watercolor painting, {prompt}. vibrant, beautiful, painterly, detailed, textural, artistic",
10
+ "negative_prompt": "(lowres, low quality, worst quality:1.2), (text:1.2), watermark, anime, photorealistic, 35mm film, deformed, glitch, low contrast, noisy",
11
+ },
12
+ {
13
+ "name": "Film Noir",
14
+ "prompt": "film noir style, ink sketch|vector, {prompt} highly detailed, sharp focus, ultra sharpness, monochrome, high contrast, dramatic shadows, 1940s style, mysterious, cinematic",
15
+ "negative_prompt": "(lowres, low quality, worst quality:1.2), (text:1.2), watermark, (frame:1.2), deformed, ugly, deformed eyes, blur, out of focus, blurry, deformed cat, deformed, photo, anthropomorphic cat, monochrome, photo, pet collar, gun, weapon, blue, 3d, drones, drone, buildings in background, green",
16
+ },
17
+ {
18
+ "name": "Neon",
19
+ "prompt": "masterpiece painting, buildings in the backdrop, kaleidoscope, lilac orange blue cream fuchsia bright vivid gradient colors, the scene is cinematic, {prompt}, emotional realism, double exposure, watercolor ink pencil, graded wash, color layering, magic realism, figurative painting, intricate motifs, organic tracery, polished",
20
+ "negative_prompt": "(lowres, low quality, worst quality:1.2), (text:1.2), watermark, (frame:1.2), deformed, ugly, deformed eyes, blur, out of focus, blurry, deformed cat, deformed, photo, anthropomorphic cat, monochrome, photo, pet collar, gun, weapon, blue, 3d, drones, drone, buildings in background, green",
21
+ },
22
+ {
23
+ "name": "Jungle",
24
+ "prompt": 'waist-up "{prompt} in a Jungle" by Syd Mead, tangerine cold color palette, muted colors, detailed, 8k,photo r3al,dripping paint,3d toon style,3d style,Movie Still',
25
+ "negative_prompt": "(lowres, low quality, worst quality:1.2), (text:1.2), watermark, (frame:1.2), deformed, ugly, deformed eyes, blur, out of focus, blurry, deformed cat, deformed, photo, anthropomorphic cat, monochrome, photo, pet collar, gun, weapon, blue, 3d, drones, drone, buildings in background, green",
26
+ },
27
+ {
28
+ "name": "Mars",
29
+ "prompt": "{prompt}, Post-apocalyptic. Mars Colony, Scavengers roam the wastelands searching for valuable resources, rovers, bright morning sunlight shining, (detailed) (intricate) (8k) (HDR) (cinematic lighting) (sharp focus)",
30
+ "negative_prompt": "(lowres, low quality, worst quality:1.2), (text:1.2), watermark, (frame:1.2), deformed, ugly, deformed eyes, blur, out of focus, blurry, deformed cat, deformed, photo, anthropomorphic cat, monochrome, photo, pet collar, gun, weapon, blue, 3d, drones, drone, buildings in background, green",
31
+ },
32
+ {
33
+ "name": "Vibrant Color",
34
+ "prompt": "vibrant colorful, ink sketch|vector|2d colors, at nightfall, sharp focus, {prompt}, highly detailed, sharp focus, the clouds,colorful,ultra sharpness",
35
+ "negative_prompt": "(lowres, low quality, worst quality:1.2), (text:1.2), watermark, (frame:1.2), deformed, ugly, deformed eyes, blur, out of focus, blurry, deformed cat, deformed, photo, anthropomorphic cat, monochrome, photo, pet collar, gun, weapon, blue, 3d, drones, drone, buildings in background, green",
36
+ },
37
+ {
38
+ "name": "Snow",
39
+ "prompt": "cinema 4d render, {prompt}, high contrast, vibrant and saturated, sico style, surrounded by magical glow,floating ice shards, snow crystals, cold, windy background, frozen natural landscape in background cinematic atmosphere,highly detailed, sharp focus, intricate design, 3d, unreal engine, octane render, CG best quality, highres, photorealistic, dramatic lighting, artstation, concept art, cinematic, epic Steven Spielberg movie still, sharp focus, smoke, sparks, art by pascal blanche and greg rutkowski and repin, trending on artstation, hyperrealism painting, matte painting, 4k resolution",
40
+ "negative_prompt": "(lowres, low quality, worst quality:1.2), (text:1.2), watermark, (frame:1.2), deformed, ugly, deformed eyes, blur, out of focus, blurry, deformed cat, deformed, photo, anthropomorphic cat, monochrome, photo, pet collar, gun, weapon, blue, 3d, drones, drone, buildings in background, green",
41
+ },
42
+ {
43
+ "name": "Line art",
44
+ "prompt": "line art drawing {prompt} . professional, sleek, modern, minimalist, graphic, line art, vector graphics",
45
+ "negative_prompt": "anime, photorealistic, 35mm film, deformed, glitch, blurry, noisy, off-center, deformed, cross-eyed, closed eyes, bad anatomy, ugly, disfigured, mutated, realism, realistic, impressionism, expressionism, oil, acrylic",
46
+ },
47
+ ]
48
+
49
+ styles = {k["name"]: (k["prompt"], k["negative_prompt"]) for k in style_list}
ComfyUI-KJNodes/.github/FUNDING.yml ADDED
@@ -0,0 +1,2 @@
 
 
 
1
+ github: [kijai]
2
+ custom: ["https://www.paypal.me/kijaidesign"]
ComfyUI-KJNodes/.github/workflows/publish.yml ADDED
@@ -0,0 +1,21 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ name: Publish to Comfy registry
2
+ on:
3
+ workflow_dispatch:
4
+ push:
5
+ branches:
6
+ - main
7
+ paths:
8
+ - "pyproject.toml"
9
+
10
+ jobs:
11
+ publish-node:
12
+ name: Publish Custom Node to registry
13
+ runs-on: ubuntu-latest
14
+ steps:
15
+ - name: Check out code
16
+ uses: actions/checkout@v4
17
+ - name: Publish Custom Node
18
+ uses: Comfy-Org/publish-node-action@main
19
+ with:
20
+ ## Add your own personal access token to your Github Repository secrets and reference it here.
21
+ personal_access_token: ${{ secrets.REGISTRY_ACCESS_TOKEN }}
ComfyUI-KJNodes/.gitignore ADDED
@@ -0,0 +1,11 @@
 
 
 
 
 
 
 
 
 
 
 
 
1
+ __pycache__
2
+ /venv
3
+ *.code-workspace
4
+ .history
5
+ .vscode
6
+ *.ckpt
7
+ *.pth
8
+ types
9
+ models
10
+ jsconfig.json
11
+ custom_dimensions.json
ComfyUI-KJNodes/LICENSE ADDED
@@ -0,0 +1,674 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ GNU GENERAL PUBLIC LICENSE
2
+ Version 3, 29 June 2007
3
+
4
+ Copyright (C) 2007 Free Software Foundation, Inc. <https://fsf.org/>
5
+ Everyone is permitted to copy and distribute verbatim copies
6
+ of this license document, but changing it is not allowed.
7
+
8
+ Preamble
9
+
10
+ The GNU General Public License is a free, copyleft license for
11
+ software and other kinds of works.
12
+
13
+ The licenses for most software and other practical works are designed
14
+ to take away your freedom to share and change the works. By contrast,
15
+ the GNU General Public License is intended to guarantee your freedom to
16
+ share and change all versions of a program--to make sure it remains free
17
+ software for all its users. We, the Free Software Foundation, use the
18
+ GNU General Public License for most of our software; it applies also to
19
+ any other work released this way by its authors. You can apply it to
20
+ your programs, too.
21
+
22
+ When we speak of free software, we are referring to freedom, not
23
+ price. Our General Public Licenses are designed to make sure that you
24
+ have the freedom to distribute copies of free software (and charge for
25
+ them if you wish), that you receive source code or can get it if you
26
+ want it, that you can change the software or use pieces of it in new
27
+ free programs, and that you know you can do these things.
28
+
29
+ To protect your rights, we need to prevent others from denying you
30
+ these rights or asking you to surrender the rights. Therefore, you have
31
+ certain responsibilities if you distribute copies of the software, or if
32
+ you modify it: responsibilities to respect the freedom of others.
33
+
34
+ For example, if you distribute copies of such a program, whether
35
+ gratis or for a fee, you must pass on to the recipients the same
36
+ freedoms that you received. You must make sure that they, too, receive
37
+ or can get the source code. And you must show them these terms so they
38
+ know their rights.
39
+
40
+ Developers that use the GNU GPL protect your rights with two steps:
41
+ (1) assert copyright on the software, and (2) offer you this License
42
+ giving you legal permission to copy, distribute and/or modify it.
43
+
44
+ For the developers' and authors' protection, the GPL clearly explains
45
+ that there is no warranty for this free software. For both users' and
46
+ authors' sake, the GPL requires that modified versions be marked as
47
+ changed, so that their problems will not be attributed erroneously to
48
+ authors of previous versions.
49
+
50
+ Some devices are designed to deny users access to install or run
51
+ modified versions of the software inside them, although the manufacturer
52
+ can do so. This is fundamentally incompatible with the aim of
53
+ protecting users' freedom to change the software. The systematic
54
+ pattern of such abuse occurs in the area of products for individuals to
55
+ use, which is precisely where it is most unacceptable. Therefore, we
56
+ have designed this version of the GPL to prohibit the practice for those
57
+ products. If such problems arise substantially in other domains, we
58
+ stand ready to extend this provision to those domains in future versions
59
+ of the GPL, as needed to protect the freedom of users.
60
+
61
+ Finally, every program is threatened constantly by software patents.
62
+ States should not allow patents to restrict development and use of
63
+ software on general-purpose computers, but in those that do, we wish to
64
+ avoid the special danger that patents applied to a free program could
65
+ make it effectively proprietary. To prevent this, the GPL assures that
66
+ patents cannot be used to render the program non-free.
67
+
68
+ The precise terms and conditions for copying, distribution and
69
+ modification follow.
70
+
71
+ TERMS AND CONDITIONS
72
+
73
+ 0. Definitions.
74
+
75
+ "This License" refers to version 3 of the GNU General Public License.
76
+
77
+ "Copyright" also means copyright-like laws that apply to other kinds of
78
+ works, such as semiconductor masks.
79
+
80
+ "The Program" refers to any copyrightable work licensed under this
81
+ License. Each licensee is addressed as "you". "Licensees" and
82
+ "recipients" may be individuals or organizations.
83
+
84
+ To "modify" a work means to copy from or adapt all or part of the work
85
+ in a fashion requiring copyright permission, other than the making of an
86
+ exact copy. The resulting work is called a "modified version" of the
87
+ earlier work or a work "based on" the earlier work.
88
+
89
+ A "covered work" means either the unmodified Program or a work based
90
+ on the Program.
91
+
92
+ To "propagate" a work means to do anything with it that, without
93
+ permission, would make you directly or secondarily liable for
94
+ infringement under applicable copyright law, except executing it on a
95
+ computer or modifying a private copy. Propagation includes copying,
96
+ distribution (with or without modification), making available to the
97
+ public, and in some countries other activities as well.
98
+
99
+ To "convey" a work means any kind of propagation that enables other
100
+ parties to make or receive copies. Mere interaction with a user through
101
+ a computer network, with no transfer of a copy, is not conveying.
102
+
103
+ An interactive user interface displays "Appropriate Legal Notices"
104
+ to the extent that it includes a convenient and prominently visible
105
+ feature that (1) displays an appropriate copyright notice, and (2)
106
+ tells the user that there is no warranty for the work (except to the
107
+ extent that warranties are provided), that licensees may convey the
108
+ work under this License, and how to view a copy of this License. If
109
+ the interface presents a list of user commands or options, such as a
110
+ menu, a prominent item in the list meets this criterion.
111
+
112
+ 1. Source Code.
113
+
114
+ The "source code" for a work means the preferred form of the work
115
+ for making modifications to it. "Object code" means any non-source
116
+ form of a work.
117
+
118
+ A "Standard Interface" means an interface that either is an official
119
+ standard defined by a recognized standards body, or, in the case of
120
+ interfaces specified for a particular programming language, one that
121
+ is widely used among developers working in that language.
122
+
123
+ The "System Libraries" of an executable work include anything, other
124
+ than the work as a whole, that (a) is included in the normal form of
125
+ packaging a Major Component, but which is not part of that Major
126
+ Component, and (b) serves only to enable use of the work with that
127
+ Major Component, or to implement a Standard Interface for which an
128
+ implementation is available to the public in source code form. A
129
+ "Major Component", in this context, means a major essential component
130
+ (kernel, window system, and so on) of the specific operating system
131
+ (if any) on which the executable work runs, or a compiler used to
132
+ produce the work, or an object code interpreter used to run it.
133
+
134
+ The "Corresponding Source" for a work in object code form means all
135
+ the source code needed to generate, install, and (for an executable
136
+ work) run the object code and to modify the work, including scripts to
137
+ control those activities. However, it does not include the work's
138
+ System Libraries, or general-purpose tools or generally available free
139
+ programs which are used unmodified in performing those activities but
140
+ which are not part of the work. For example, Corresponding Source
141
+ includes interface definition files associated with source files for
142
+ the work, and the source code for shared libraries and dynamically
143
+ linked subprograms that the work is specifically designed to require,
144
+ such as by intimate data communication or control flow between those
145
+ subprograms and other parts of the work.
146
+
147
+ The Corresponding Source need not include anything that users
148
+ can regenerate automatically from other parts of the Corresponding
149
+ Source.
150
+
151
+ The Corresponding Source for a work in source code form is that
152
+ same work.
153
+
154
+ 2. Basic Permissions.
155
+
156
+ All rights granted under this License are granted for the term of
157
+ copyright on the Program, and are irrevocable provided the stated
158
+ conditions are met. This License explicitly affirms your unlimited
159
+ permission to run the unmodified Program. The output from running a
160
+ covered work is covered by this License only if the output, given its
161
+ content, constitutes a covered work. This License acknowledges your
162
+ rights of fair use or other equivalent, as provided by copyright law.
163
+
164
+ You may make, run and propagate covered works that you do not
165
+ convey, without conditions so long as your license otherwise remains
166
+ in force. You may convey covered works to others for the sole purpose
167
+ of having them make modifications exclusively for you, or provide you
168
+ with facilities for running those works, provided that you comply with
169
+ the terms of this License in conveying all material for which you do
170
+ not control copyright. Those thus making or running the covered works
171
+ for you must do so exclusively on your behalf, under your direction
172
+ and control, on terms that prohibit them from making any copies of
173
+ your copyrighted material outside their relationship with you.
174
+
175
+ Conveying under any other circumstances is permitted solely under
176
+ the conditions stated below. Sublicensing is not allowed; section 10
177
+ makes it unnecessary.
178
+
179
+ 3. Protecting Users' Legal Rights From Anti-Circumvention Law.
180
+
181
+ No covered work shall be deemed part of an effective technological
182
+ measure under any applicable law fulfilling obligations under article
183
+ 11 of the WIPO copyright treaty adopted on 20 December 1996, or
184
+ similar laws prohibiting or restricting circumvention of such
185
+ measures.
186
+
187
+ When you convey a covered work, you waive any legal power to forbid
188
+ circumvention of technological measures to the extent such circumvention
189
+ is effected by exercising rights under this License with respect to
190
+ the covered work, and you disclaim any intention to limit operation or
191
+ modification of the work as a means of enforcing, against the work's
192
+ users, your or third parties' legal rights to forbid circumvention of
193
+ technological measures.
194
+
195
+ 4. Conveying Verbatim Copies.
196
+
197
+ You may convey verbatim copies of the Program's source code as you
198
+ receive it, in any medium, provided that you conspicuously and
199
+ appropriately publish on each copy an appropriate copyright notice;
200
+ keep intact all notices stating that this License and any
201
+ non-permissive terms added in accord with section 7 apply to the code;
202
+ keep intact all notices of the absence of any warranty; and give all
203
+ recipients a copy of this License along with the Program.
204
+
205
+ You may charge any price or no price for each copy that you convey,
206
+ and you may offer support or warranty protection for a fee.
207
+
208
+ 5. Conveying Modified Source Versions.
209
+
210
+ You may convey a work based on the Program, or the modifications to
211
+ produce it from the Program, in the form of source code under the
212
+ terms of section 4, provided that you also meet all of these conditions:
213
+
214
+ a) The work must carry prominent notices stating that you modified
215
+ it, and giving a relevant date.
216
+
217
+ b) The work must carry prominent notices stating that it is
218
+ released under this License and any conditions added under section
219
+ 7. This requirement modifies the requirement in section 4 to
220
+ "keep intact all notices".
221
+
222
+ c) You must license the entire work, as a whole, under this
223
+ License to anyone who comes into possession of a copy. This
224
+ License will therefore apply, along with any applicable section 7
225
+ additional terms, to the whole of the work, and all its parts,
226
+ regardless of how they are packaged. This License gives no
227
+ permission to license the work in any other way, but it does not
228
+ invalidate such permission if you have separately received it.
229
+
230
+ d) If the work has interactive user interfaces, each must display
231
+ Appropriate Legal Notices; however, if the Program has interactive
232
+ interfaces that do not display Appropriate Legal Notices, your
233
+ work need not make them do so.
234
+
235
+ A compilation of a covered work with other separate and independent
236
+ works, which are not by their nature extensions of the covered work,
237
+ and which are not combined with it such as to form a larger program,
238
+ in or on a volume of a storage or distribution medium, is called an
239
+ "aggregate" if the compilation and its resulting copyright are not
240
+ used to limit the access or legal rights of the compilation's users
241
+ beyond what the individual works permit. Inclusion of a covered work
242
+ in an aggregate does not cause this License to apply to the other
243
+ parts of the aggregate.
244
+
245
+ 6. Conveying Non-Source Forms.
246
+
247
+ You may convey a covered work in object code form under the terms
248
+ of sections 4 and 5, provided that you also convey the
249
+ machine-readable Corresponding Source under the terms of this License,
250
+ in one of these ways:
251
+
252
+ a) Convey the object code in, or embodied in, a physical product
253
+ (including a physical distribution medium), accompanied by the
254
+ Corresponding Source fixed on a durable physical medium
255
+ customarily used for software interchange.
256
+
257
+ b) Convey the object code in, or embodied in, a physical product
258
+ (including a physical distribution medium), accompanied by a
259
+ written offer, valid for at least three years and valid for as
260
+ long as you offer spare parts or customer support for that product
261
+ model, to give anyone who possesses the object code either (1) a
262
+ copy of the Corresponding Source for all the software in the
263
+ product that is covered by this License, on a durable physical
264
+ medium customarily used for software interchange, for a price no
265
+ more than your reasonable cost of physically performing this
266
+ conveying of source, or (2) access to copy the
267
+ Corresponding Source from a network server at no charge.
268
+
269
+ c) Convey individual copies of the object code with a copy of the
270
+ written offer to provide the Corresponding Source. This
271
+ alternative is allowed only occasionally and noncommercially, and
272
+ only if you received the object code with such an offer, in accord
273
+ with subsection 6b.
274
+
275
+ d) Convey the object code by offering access from a designated
276
+ place (gratis or for a charge), and offer equivalent access to the
277
+ Corresponding Source in the same way through the same place at no
278
+ further charge. You need not require recipients to copy the
279
+ Corresponding Source along with the object code. If the place to
280
+ copy the object code is a network server, the Corresponding Source
281
+ may be on a different server (operated by you or a third party)
282
+ that supports equivalent copying facilities, provided you maintain
283
+ clear directions next to the object code saying where to find the
284
+ Corresponding Source. Regardless of what server hosts the
285
+ Corresponding Source, you remain obligated to ensure that it is
286
+ available for as long as needed to satisfy these requirements.
287
+
288
+ e) Convey the object code using peer-to-peer transmission, provided
289
+ you inform other peers where the object code and Corresponding
290
+ Source of the work are being offered to the general public at no
291
+ charge under subsection 6d.
292
+
293
+ A separable portion of the object code, whose source code is excluded
294
+ from the Corresponding Source as a System Library, need not be
295
+ included in conveying the object code work.
296
+
297
+ A "User Product" is either (1) a "consumer product", which means any
298
+ tangible personal property which is normally used for personal, family,
299
+ or household purposes, or (2) anything designed or sold for incorporation
300
+ into a dwelling. In determining whether a product is a consumer product,
301
+ doubtful cases shall be resolved in favor of coverage. For a particular
302
+ product received by a particular user, "normally used" refers to a
303
+ typical or common use of that class of product, regardless of the status
304
+ of the particular user or of the way in which the particular user
305
+ actually uses, or expects or is expected to use, the product. A product
306
+ is a consumer product regardless of whether the product has substantial
307
+ commercial, industrial or non-consumer uses, unless such uses represent
308
+ the only significant mode of use of the product.
309
+
310
+ "Installation Information" for a User Product means any methods,
311
+ procedures, authorization keys, or other information required to install
312
+ and execute modified versions of a covered work in that User Product from
313
+ a modified version of its Corresponding Source. The information must
314
+ suffice to ensure that the continued functioning of the modified object
315
+ code is in no case prevented or interfered with solely because
316
+ modification has been made.
317
+
318
+ If you convey an object code work under this section in, or with, or
319
+ specifically for use in, a User Product, and the conveying occurs as
320
+ part of a transaction in which the right of possession and use of the
321
+ User Product is transferred to the recipient in perpetuity or for a
322
+ fixed term (regardless of how the transaction is characterized), the
323
+ Corresponding Source conveyed under this section must be accompanied
324
+ by the Installation Information. But this requirement does not apply
325
+ if neither you nor any third party retains the ability to install
326
+ modified object code on the User Product (for example, the work has
327
+ been installed in ROM).
328
+
329
+ The requirement to provide Installation Information does not include a
330
+ requirement to continue to provide support service, warranty, or updates
331
+ for a work that has been modified or installed by the recipient, or for
332
+ the User Product in which it has been modified or installed. Access to a
333
+ network may be denied when the modification itself materially and
334
+ adversely affects the operation of the network or violates the rules and
335
+ protocols for communication across the network.
336
+
337
+ Corresponding Source conveyed, and Installation Information provided,
338
+ in accord with this section must be in a format that is publicly
339
+ documented (and with an implementation available to the public in
340
+ source code form), and must require no special password or key for
341
+ unpacking, reading or copying.
342
+
343
+ 7. Additional Terms.
344
+
345
+ "Additional permissions" are terms that supplement the terms of this
346
+ License by making exceptions from one or more of its conditions.
347
+ Additional permissions that are applicable to the entire Program shall
348
+ be treated as though they were included in this License, to the extent
349
+ that they are valid under applicable law. If additional permissions
350
+ apply only to part of the Program, that part may be used separately
351
+ under those permissions, but the entire Program remains governed by
352
+ this License without regard to the additional permissions.
353
+
354
+ When you convey a copy of a covered work, you may at your option
355
+ remove any additional permissions from that copy, or from any part of
356
+ it. (Additional permissions may be written to require their own
357
+ removal in certain cases when you modify the work.) You may place
358
+ additional permissions on material, added by you to a covered work,
359
+ for which you have or can give appropriate copyright permission.
360
+
361
+ Notwithstanding any other provision of this License, for material you
362
+ add to a covered work, you may (if authorized by the copyright holders of
363
+ that material) supplement the terms of this License with terms:
364
+
365
+ a) Disclaiming warranty or limiting liability differently from the
366
+ terms of sections 15 and 16 of this License; or
367
+
368
+ b) Requiring preservation of specified reasonable legal notices or
369
+ author attributions in that material or in the Appropriate Legal
370
+ Notices displayed by works containing it; or
371
+
372
+ c) Prohibiting misrepresentation of the origin of that material, or
373
+ requiring that modified versions of such material be marked in
374
+ reasonable ways as different from the original version; or
375
+
376
+ d) Limiting the use for publicity purposes of names of licensors or
377
+ authors of the material; or
378
+
379
+ e) Declining to grant rights under trademark law for use of some
380
+ trade names, trademarks, or service marks; or
381
+
382
+ f) Requiring indemnification of licensors and authors of that
383
+ material by anyone who conveys the material (or modified versions of
384
+ it) with contractual assumptions of liability to the recipient, for
385
+ any liability that these contractual assumptions directly impose on
386
+ those licensors and authors.
387
+
388
+ All other non-permissive additional terms are considered "further
389
+ restrictions" within the meaning of section 10. If the Program as you
390
+ received it, or any part of it, contains a notice stating that it is
391
+ governed by this License along with a term that is a further
392
+ restriction, you may remove that term. If a license document contains
393
+ a further restriction but permits relicensing or conveying under this
394
+ License, you may add to a covered work material governed by the terms
395
+ of that license document, provided that the further restriction does
396
+ not survive such relicensing or conveying.
397
+
398
+ If you add terms to a covered work in accord with this section, you
399
+ must place, in the relevant source files, a statement of the
400
+ additional terms that apply to those files, or a notice indicating
401
+ where to find the applicable terms.
402
+
403
+ Additional terms, permissive or non-permissive, may be stated in the
404
+ form of a separately written license, or stated as exceptions;
405
+ the above requirements apply either way.
406
+
407
+ 8. Termination.
408
+
409
+ You may not propagate or modify a covered work except as expressly
410
+ provided under this License. Any attempt otherwise to propagate or
411
+ modify it is void, and will automatically terminate your rights under
412
+ this License (including any patent licenses granted under the third
413
+ paragraph of section 11).
414
+
415
+ However, if you cease all violation of this License, then your
416
+ license from a particular copyright holder is reinstated (a)
417
+ provisionally, unless and until the copyright holder explicitly and
418
+ finally terminates your license, and (b) permanently, if the copyright
419
+ holder fails to notify you of the violation by some reasonable means
420
+ prior to 60 days after the cessation.
421
+
422
+ Moreover, your license from a particular copyright holder is
423
+ reinstated permanently if the copyright holder notifies you of the
424
+ violation by some reasonable means, this is the first time you have
425
+ received notice of violation of this License (for any work) from that
426
+ copyright holder, and you cure the violation prior to 30 days after
427
+ your receipt of the notice.
428
+
429
+ Termination of your rights under this section does not terminate the
430
+ licenses of parties who have received copies or rights from you under
431
+ this License. If your rights have been terminated and not permanently
432
+ reinstated, you do not qualify to receive new licenses for the same
433
+ material under section 10.
434
+
435
+ 9. Acceptance Not Required for Having Copies.
436
+
437
+ You are not required to accept this License in order to receive or
438
+ run a copy of the Program. Ancillary propagation of a covered work
439
+ occurring solely as a consequence of using peer-to-peer transmission
440
+ to receive a copy likewise does not require acceptance. However,
441
+ nothing other than this License grants you permission to propagate or
442
+ modify any covered work. These actions infringe copyright if you do
443
+ not accept this License. Therefore, by modifying or propagating a
444
+ covered work, you indicate your acceptance of this License to do so.
445
+
446
+ 10. Automatic Licensing of Downstream Recipients.
447
+
448
+ Each time you convey a covered work, the recipient automatically
449
+ receives a license from the original licensors, to run, modify and
450
+ propagate that work, subject to this License. You are not responsible
451
+ for enforcing compliance by third parties with this License.
452
+
453
+ An "entity transaction" is a transaction transferring control of an
454
+ organization, or substantially all assets of one, or subdividing an
455
+ organization, or merging organizations. If propagation of a covered
456
+ work results from an entity transaction, each party to that
457
+ transaction who receives a copy of the work also receives whatever
458
+ licenses to the work the party's predecessor in interest had or could
459
+ give under the previous paragraph, plus a right to possession of the
460
+ Corresponding Source of the work from the predecessor in interest, if
461
+ the predecessor has it or can get it with reasonable efforts.
462
+
463
+ You may not impose any further restrictions on the exercise of the
464
+ rights granted or affirmed under this License. For example, you may
465
+ not impose a license fee, royalty, or other charge for exercise of
466
+ rights granted under this License, and you may not initiate litigation
467
+ (including a cross-claim or counterclaim in a lawsuit) alleging that
468
+ any patent claim is infringed by making, using, selling, offering for
469
+ sale, or importing the Program or any portion of it.
470
+
471
+ 11. Patents.
472
+
473
+ A "contributor" is a copyright holder who authorizes use under this
474
+ License of the Program or a work on which the Program is based. The
475
+ work thus licensed is called the contributor's "contributor version".
476
+
477
+ A contributor's "essential patent claims" are all patent claims
478
+ owned or controlled by the contributor, whether already acquired or
479
+ hereafter acquired, that would be infringed by some manner, permitted
480
+ by this License, of making, using, or selling its contributor version,
481
+ but do not include claims that would be infringed only as a
482
+ consequence of further modification of the contributor version. For
483
+ purposes of this definition, "control" includes the right to grant
484
+ patent sublicenses in a manner consistent with the requirements of
485
+ this License.
486
+
487
+ Each contributor grants you a non-exclusive, worldwide, royalty-free
488
+ patent license under the contributor's essential patent claims, to
489
+ make, use, sell, offer for sale, import and otherwise run, modify and
490
+ propagate the contents of its contributor version.
491
+
492
+ In the following three paragraphs, a "patent license" is any express
493
+ agreement or commitment, however denominated, not to enforce a patent
494
+ (such as an express permission to practice a patent or covenant not to
495
+ sue for patent infringement). To "grant" such a patent license to a
496
+ party means to make such an agreement or commitment not to enforce a
497
+ patent against the party.
498
+
499
+ If you convey a covered work, knowingly relying on a patent license,
500
+ and the Corresponding Source of the work is not available for anyone
501
+ to copy, free of charge and under the terms of this License, through a
502
+ publicly available network server or other readily accessible means,
503
+ then you must either (1) cause the Corresponding Source to be so
504
+ available, or (2) arrange to deprive yourself of the benefit of the
505
+ patent license for this particular work, or (3) arrange, in a manner
506
+ consistent with the requirements of this License, to extend the patent
507
+ license to downstream recipients. "Knowingly relying" means you have
508
+ actual knowledge that, but for the patent license, your conveying the
509
+ covered work in a country, or your recipient's use of the covered work
510
+ in a country, would infringe one or more identifiable patents in that
511
+ country that you have reason to believe are valid.
512
+
513
+ If, pursuant to or in connection with a single transaction or
514
+ arrangement, you convey, or propagate by procuring conveyance of, a
515
+ covered work, and grant a patent license to some of the parties
516
+ receiving the covered work authorizing them to use, propagate, modify
517
+ or convey a specific copy of the covered work, then the patent license
518
+ you grant is automatically extended to all recipients of the covered
519
+ work and works based on it.
520
+
521
+ A patent license is "discriminatory" if it does not include within
522
+ the scope of its coverage, prohibits the exercise of, or is
523
+ conditioned on the non-exercise of one or more of the rights that are
524
+ specifically granted under this License. You may not convey a covered
525
+ work if you are a party to an arrangement with a third party that is
526
+ in the business of distributing software, under which you make payment
527
+ to the third party based on the extent of your activity of conveying
528
+ the work, and under which the third party grants, to any of the
529
+ parties who would receive the covered work from you, a discriminatory
530
+ patent license (a) in connection with copies of the covered work
531
+ conveyed by you (or copies made from those copies), or (b) primarily
532
+ for and in connection with specific products or compilations that
533
+ contain the covered work, unless you entered into that arrangement,
534
+ or that patent license was granted, prior to 28 March 2007.
535
+
536
+ Nothing in this License shall be construed as excluding or limiting
537
+ any implied license or other defenses to infringement that may
538
+ otherwise be available to you under applicable patent law.
539
+
540
+ 12. No Surrender of Others' Freedom.
541
+
542
+ If conditions are imposed on you (whether by court order, agreement or
543
+ otherwise) that contradict the conditions of this License, they do not
544
+ excuse you from the conditions of this License. If you cannot convey a
545
+ covered work so as to satisfy simultaneously your obligations under this
546
+ License and any other pertinent obligations, then as a consequence you may
547
+ not convey it at all. For example, if you agree to terms that obligate you
548
+ to collect a royalty for further conveying from those to whom you convey
549
+ the Program, the only way you could satisfy both those terms and this
550
+ License would be to refrain entirely from conveying the Program.
551
+
552
+ 13. Use with the GNU Affero General Public License.
553
+
554
+ Notwithstanding any other provision of this License, you have
555
+ permission to link or combine any covered work with a work licensed
556
+ under version 3 of the GNU Affero General Public License into a single
557
+ combined work, and to convey the resulting work. The terms of this
558
+ License will continue to apply to the part which is the covered work,
559
+ but the special requirements of the GNU Affero General Public License,
560
+ section 13, concerning interaction through a network will apply to the
561
+ combination as such.
562
+
563
+ 14. Revised Versions of this License.
564
+
565
+ The Free Software Foundation may publish revised and/or new versions of
566
+ the GNU General Public License from time to time. Such new versions will
567
+ be similar in spirit to the present version, but may differ in detail to
568
+ address new problems or concerns.
569
+
570
+ Each version is given a distinguishing version number. If the
571
+ Program specifies that a certain numbered version of the GNU General
572
+ Public License "or any later version" applies to it, you have the
573
+ option of following the terms and conditions either of that numbered
574
+ version or of any later version published by the Free Software
575
+ Foundation. If the Program does not specify a version number of the
576
+ GNU General Public License, you may choose any version ever published
577
+ by the Free Software Foundation.
578
+
579
+ If the Program specifies that a proxy can decide which future
580
+ versions of the GNU General Public License can be used, that proxy's
581
+ public statement of acceptance of a version permanently authorizes you
582
+ to choose that version for the Program.
583
+
584
+ Later license versions may give you additional or different
585
+ permissions. However, no additional obligations are imposed on any
586
+ author or copyright holder as a result of your choosing to follow a
587
+ later version.
588
+
589
+ 15. Disclaimer of Warranty.
590
+
591
+ THERE IS NO WARRANTY FOR THE PROGRAM, TO THE EXTENT PERMITTED BY
592
+ APPLICABLE LAW. EXCEPT WHEN OTHERWISE STATED IN WRITING THE COPYRIGHT
593
+ HOLDERS AND/OR OTHER PARTIES PROVIDE THE PROGRAM "AS IS" WITHOUT WARRANTY
594
+ OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING, BUT NOT LIMITED TO,
595
+ THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
596
+ PURPOSE. THE ENTIRE RISK AS TO THE QUALITY AND PERFORMANCE OF THE PROGRAM
597
+ IS WITH YOU. SHOULD THE PROGRAM PROVE DEFECTIVE, YOU ASSUME THE COST OF
598
+ ALL NECESSARY SERVICING, REPAIR OR CORRECTION.
599
+
600
+ 16. Limitation of Liability.
601
+
602
+ IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW OR AGREED TO IN WRITING
603
+ WILL ANY COPYRIGHT HOLDER, OR ANY OTHER PARTY WHO MODIFIES AND/OR CONVEYS
604
+ THE PROGRAM AS PERMITTED ABOVE, BE LIABLE TO YOU FOR DAMAGES, INCLUDING ANY
605
+ GENERAL, SPECIAL, INCIDENTAL OR CONSEQUENTIAL DAMAGES ARISING OUT OF THE
606
+ USE OR INABILITY TO USE THE PROGRAM (INCLUDING BUT NOT LIMITED TO LOSS OF
607
+ DATA OR DATA BEING RENDERED INACCURATE OR LOSSES SUSTAINED BY YOU OR THIRD
608
+ PARTIES OR A FAILURE OF THE PROGRAM TO OPERATE WITH ANY OTHER PROGRAMS),
609
+ EVEN IF SUCH HOLDER OR OTHER PARTY HAS BEEN ADVISED OF THE POSSIBILITY OF
610
+ SUCH DAMAGES.
611
+
612
+ 17. Interpretation of Sections 15 and 16.
613
+
614
+ If the disclaimer of warranty and limitation of liability provided
615
+ above cannot be given local legal effect according to their terms,
616
+ reviewing courts shall apply local law that most closely approximates
617
+ an absolute waiver of all civil liability in connection with the
618
+ Program, unless a warranty or assumption of liability accompanies a
619
+ copy of the Program in return for a fee.
620
+
621
+ END OF TERMS AND CONDITIONS
622
+
623
+ How to Apply These Terms to Your New Programs
624
+
625
+ If you develop a new program, and you want it to be of the greatest
626
+ possible use to the public, the best way to achieve this is to make it
627
+ free software which everyone can redistribute and change under these terms.
628
+
629
+ To do so, attach the following notices to the program. It is safest
630
+ to attach them to the start of each source file to most effectively
631
+ state the exclusion of warranty; and each file should have at least
632
+ the "copyright" line and a pointer to where the full notice is found.
633
+
634
+ <one line to give the program's name and a brief idea of what it does.>
635
+ Copyright (C) <year> <name of author>
636
+
637
+ This program is free software: you can redistribute it and/or modify
638
+ it under the terms of the GNU General Public License as published by
639
+ the Free Software Foundation, either version 3 of the License, or
640
+ (at your option) any later version.
641
+
642
+ This program is distributed in the hope that it will be useful,
643
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
644
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
645
+ GNU General Public License for more details.
646
+
647
+ You should have received a copy of the GNU General Public License
648
+ along with this program. If not, see <https://www.gnu.org/licenses/>.
649
+
650
+ Also add information on how to contact you by electronic and paper mail.
651
+
652
+ If the program does terminal interaction, make it output a short
653
+ notice like this when it starts in an interactive mode:
654
+
655
+ <program> Copyright (C) <year> <name of author>
656
+ This program comes with ABSOLUTELY NO WARRANTY; for details type `show w'.
657
+ This is free software, and you are welcome to redistribute it
658
+ under certain conditions; type `show c' for details.
659
+
660
+ The hypothetical commands `show w' and `show c' should show the appropriate
661
+ parts of the General Public License. Of course, your program's commands
662
+ might be different; for a GUI interface, you would use an "about box".
663
+
664
+ You should also get your employer (if you work as a programmer) or school,
665
+ if any, to sign a "copyright disclaimer" for the program, if necessary.
666
+ For more information on this, and how to apply and follow the GNU GPL, see
667
+ <https://www.gnu.org/licenses/>.
668
+
669
+ The GNU General Public License does not permit incorporating your program
670
+ into proprietary programs. If your program is a subroutine library, you
671
+ may consider it more useful to permit linking proprietary applications with
672
+ the library. If this is what you want to do, use the GNU Lesser General
673
+ Public License instead of this License. But first, please read
674
+ <https://www.gnu.org/licenses/why-not-lgpl.html>.
ComfyUI-KJNodes/README.md ADDED
@@ -0,0 +1,65 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ # KJNodes for ComfyUI
2
+
3
+ Various quality of life and masking related -nodes and scripts made by combining functionality of existing nodes for ComfyUI.
4
+
5
+ I know I'm bad at documentation, especially this project that has grown from random practice nodes to... too many lines in one file.
6
+ I have however started to add descriptions to the nodes themselves, there's a small ? you can click for info what the node does.
7
+ This is still work in progress, like everything else.
8
+
9
+ # Installation
10
+ 1. Clone this repo into `custom_nodes` folder.
11
+ 2. Install dependencies: `pip install -r requirements.txt`
12
+ or if you use the portable install, run this in ComfyUI_windows_portable -folder:
13
+
14
+ `python_embeded\python.exe -m pip install -r ComfyUI\custom_nodes\ComfyUI-KJNodes\requirements.txt`
15
+
16
+
17
+ ## Javascript
18
+
19
+ ### browserstatus.js
20
+ Sets the favicon to green circle when not processing anything, sets it to red when processing and shows progress percentage and the lenghth of your queue.
21
+ Default off, needs to be enabled from options, overrides Custom-Scripts favicon when enabled.
22
+
23
+ ## Nodes:
24
+
25
+ ### Set/Get
26
+
27
+ Javascript nodes to set and get constants to reduce unnecessary lines. Takes in and returns anything, purely visual nodes.
28
+ On the right click menu of these nodes there's now an options to visualize the paths, as well as option to jump to the corresponding node on the other end.
29
+
30
+ **Known limitations**:
31
+ - Will not work with any node that dynamically sets it's outpute, such as reroute or other Set/Get node
32
+ - Will not work when directly connected to a bypassed node
33
+ - Other possible conflicts with javascript based nodes.
34
+
35
+ ### ColorToMask
36
+
37
+ RBG color value to mask, works with batches and AnimateDiff.
38
+
39
+ ### ConditioningMultiCombine
40
+
41
+ Combine any number of conditions, saves space.
42
+
43
+ ### ConditioningSetMaskAndCombine
44
+
45
+ Mask and combine two sets of conditions, saves space.
46
+
47
+ ### GrowMaskWithBlur
48
+
49
+ Grows or shrinks (with negative values) mask, option to invert input, returns mask and inverted mask. Additionally Blurs the mask, this is a slow operation especially with big batches.
50
+
51
+ ### RoundMask
52
+
53
+ ![image](https://github.com/kijai/ComfyUI-KJNodes/assets/40791699/52c85202-f74e-4b96-9dac-c8bda5ddcc40)
54
+
55
+ ### WidgetToString
56
+ Outputs the value of a widget on any node as a string
57
+ ![example of use](docs/images/2024-04-03_20_49_29-ComfyUI.png)
58
+
59
+ Enable node id display from Manager menu, to get the ID of the node you want to read a widget from:
60
+ ![enable node id display](docs/images/319121636-706b5081-9120-4a29-bd76-901691ada688.png)
61
+
62
+ Use the node id of the target node, and add the name of the widget to read from
63
+ ![use node id and widget name](docs/images/319121566-05f66385-7568-4b1f-8bbc-11053660b02f.png)
64
+
65
+ Recreating or reloading the target node will change its id, and the WidgetToString node will no longer be able to find it until you update the node id value with the new id.
ComfyUI-KJNodes/__init__.py ADDED
@@ -0,0 +1,195 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ from .nodes.nodes import *
2
+ from .nodes.curve_nodes import *
3
+ from .nodes.batchcrop_nodes import *
4
+ from .nodes.audioscheduler_nodes import *
5
+ from .nodes.image_nodes import *
6
+ from .nodes.intrinsic_lora_nodes import *
7
+ from .nodes.mask_nodes import *
8
+ NODE_CONFIG = {
9
+ #constants
10
+ "BOOLConstant": {"class": BOOLConstant, "name": "BOOL Constant"},
11
+ "INTConstant": {"class": INTConstant, "name": "INT Constant"},
12
+ "FloatConstant": {"class": FloatConstant, "name": "Float Constant"},
13
+ "StringConstant": {"class": StringConstant, "name": "String Constant"},
14
+ "StringConstantMultiline": {"class": StringConstantMultiline, "name": "String Constant Multiline"},
15
+ #conditioning
16
+ "ConditioningMultiCombine": {"class": ConditioningMultiCombine, "name": "Conditioning Multi Combine"},
17
+ "ConditioningSetMaskAndCombine": {"class": ConditioningSetMaskAndCombine, "name": "ConditioningSetMaskAndCombine"},
18
+ "ConditioningSetMaskAndCombine3": {"class": ConditioningSetMaskAndCombine3, "name": "ConditioningSetMaskAndCombine3"},
19
+ "ConditioningSetMaskAndCombine4": {"class": ConditioningSetMaskAndCombine4, "name": "ConditioningSetMaskAndCombine4"},
20
+ "ConditioningSetMaskAndCombine5": {"class": ConditioningSetMaskAndCombine5, "name": "ConditioningSetMaskAndCombine5"},
21
+ "CondPassThrough": {"class": CondPassThrough},
22
+ #masking
23
+ "DownloadAndLoadCLIPSeg": {"class": DownloadAndLoadCLIPSeg, "name": "(Down)load CLIPSeg"},
24
+ "BatchCLIPSeg": {"class": BatchCLIPSeg, "name": "Batch CLIPSeg"},
25
+ "ColorToMask": {"class": ColorToMask, "name": "Color To Mask"},
26
+ "CreateGradientMask": {"class": CreateGradientMask, "name": "Create Gradient Mask"},
27
+ "CreateTextMask": {"class": CreateTextMask, "name": "Create Text Mask"},
28
+ "CreateAudioMask": {"class": CreateAudioMask, "name": "Create Audio Mask"},
29
+ "CreateFadeMask": {"class": CreateFadeMask, "name": "Create Fade Mask"},
30
+ "CreateFadeMaskAdvanced": {"class": CreateFadeMaskAdvanced, "name": "Create Fade Mask Advanced"},
31
+ "CreateFluidMask": {"class": CreateFluidMask, "name": "Create Fluid Mask"},
32
+ "CreateShapeMask": {"class": CreateShapeMask, "name": "Create Shape Mask"},
33
+ "CreateVoronoiMask": {"class": CreateVoronoiMask, "name": "Create Voronoi Mask"},
34
+ "CreateMagicMask": {"class": CreateMagicMask, "name": "Create Magic Mask"},
35
+ "GetMaskSizeAndCount": {"class": GetMaskSizeAndCount, "name": "Get Mask Size & Count"},
36
+ "GrowMaskWithBlur": {"class": GrowMaskWithBlur, "name": "Grow Mask With Blur"},
37
+ "MaskBatchMulti": {"class": MaskBatchMulti, "name": "Mask Batch Multi"},
38
+ "OffsetMask": {"class": OffsetMask, "name": "Offset Mask"},
39
+ "RemapMaskRange": {"class": RemapMaskRange, "name": "Remap Mask Range"},
40
+ "ResizeMask": {"class": ResizeMask, "name": "Resize Mask"},
41
+ "RoundMask": {"class": RoundMask, "name": "Round Mask"},
42
+ #images
43
+ "AddLabel": {"class": AddLabel, "name": "Add Label"},
44
+ "ColorMatch": {"class": ColorMatch, "name": "Color Match"},
45
+ "CrossFadeImages": {"class": CrossFadeImages, "name": "Cross Fade Images"},
46
+ "CrossFadeImagesMulti": {"class": CrossFadeImagesMulti, "name": "Cross Fade Images Multi"},
47
+ "GetImagesFromBatchIndexed": {"class": GetImagesFromBatchIndexed, "name": "Get Images From Batch Indexed"},
48
+ "GetImageRangeFromBatch": {"class": GetImageRangeFromBatch, "name": "Get Image or Mask Range From Batch"},
49
+ "GetImageSizeAndCount": {"class": GetImageSizeAndCount, "name": "Get Image Size & Count"},
50
+ "FastPreview": {"class": FastPreview, "name": "Fast Preview"},
51
+ "ImageAndMaskPreview": {"class": ImageAndMaskPreview},
52
+ "ImageAddMulti": {"class": ImageAddMulti, "name": "Image Add Multi"},
53
+ "ImageBatchMulti": {"class": ImageBatchMulti, "name": "Image Batch Multi"},
54
+ "ImageBatchRepeatInterleaving": {"class": ImageBatchRepeatInterleaving},
55
+ "ImageBatchTestPattern": {"class": ImageBatchTestPattern, "name": "Image Batch Test Pattern"},
56
+ "ImageConcanate": {"class": ImageConcanate, "name": "Image Concatenate"},
57
+ "ImageConcatFromBatch": {"class": ImageConcatFromBatch, "name": "Image Concatenate From Batch"},
58
+ "ImageConcatMulti": {"class": ImageConcatMulti, "name": "Image Concatenate Multi"},
59
+ "ImageCropByMaskAndResize": {"class": ImageCropByMaskAndResize, "name": "Image Crop By Mask And Resize"},
60
+ "ImageUncropByMask": {"class": ImageUncropByMask, "name": "Image Uncrop By Mask"},
61
+ "ImageGrabPIL": {"class": ImageGrabPIL, "name": "Image Grab PIL"},
62
+ "ImageGridComposite2x2": {"class": ImageGridComposite2x2, "name": "Image Grid Composite 2x2"},
63
+ "ImageGridComposite3x3": {"class": ImageGridComposite3x3, "name": "Image Grid Composite 3x3"},
64
+ "ImageGridtoBatch": {"class": ImageGridtoBatch, "name": "Image Grid To Batch"},
65
+ "ImageNormalize_Neg1_To_1": {"class": ImageNormalize_Neg1_To_1, "name": "Image Normalize -1 to 1"},
66
+ "ImagePass": {"class": ImagePass},
67
+ "ImagePadForOutpaintMasked": {"class": ImagePadForOutpaintMasked, "name": "Image Pad For Outpaint Masked"},
68
+ "ImagePadForOutpaintTargetSize": {"class": ImagePadForOutpaintTargetSize, "name": "Image Pad For Outpaint Target Size"},
69
+ "ImageResizeKJ": {"class": ImageResizeKJ, "name": "Resize Image"},
70
+ "ImageUpscaleWithModelBatched": {"class": ImageUpscaleWithModelBatched, "name": "Image Upscale With Model Batched"},
71
+ "InsertImagesToBatchIndexed": {"class": InsertImagesToBatchIndexed, "name": "Insert Images To Batch Indexed"},
72
+ "LoadAndResizeImage": {"class": LoadAndResizeImage, "name": "Load & Resize Image"},
73
+ "LoadImagesFromFolderKJ": {"class": LoadImagesFromFolderKJ, "name": "Load Images From Folder (KJ)"},
74
+ "MergeImageChannels": {"class": MergeImageChannels, "name": "Merge Image Channels"},
75
+ "PreviewAnimation": {"class": PreviewAnimation, "name": "Preview Animation"},
76
+ "RemapImageRange": {"class": RemapImageRange, "name": "Remap Image Range"},
77
+ "ReverseImageBatch": {"class": ReverseImageBatch, "name": "Reverse Image Batch"},
78
+ "ReplaceImagesInBatch": {"class": ReplaceImagesInBatch, "name": "Replace Images In Batch"},
79
+ "SaveImageWithAlpha": {"class": SaveImageWithAlpha, "name": "Save Image With Alpha"},
80
+ "SaveImageKJ": {"class": SaveImageKJ, "name": "Save Image KJ"},
81
+ "ShuffleImageBatch": {"class": ShuffleImageBatch, "name": "Shuffle Image Batch"},
82
+ "SplitImageChannels": {"class": SplitImageChannels, "name": "Split Image Channels"},
83
+ "TransitionImagesMulti": {"class": TransitionImagesMulti, "name": "Transition Images Multi"},
84
+ "TransitionImagesInBatch": {"class": TransitionImagesInBatch, "name": "Transition Images In Batch"},
85
+ #batch cropping
86
+ "BatchCropFromMask": {"class": BatchCropFromMask, "name": "Batch Crop From Mask"},
87
+ "BatchCropFromMaskAdvanced": {"class": BatchCropFromMaskAdvanced, "name": "Batch Crop From Mask Advanced"},
88
+ "FilterZeroMasksAndCorrespondingImages": {"class": FilterZeroMasksAndCorrespondingImages},
89
+ "InsertImageBatchByIndexes": {"class": InsertImageBatchByIndexes, "name": "Insert Image Batch By Indexes"},
90
+ "BatchUncrop": {"class": BatchUncrop, "name": "Batch Uncrop"},
91
+ "BatchUncropAdvanced": {"class": BatchUncropAdvanced, "name": "Batch Uncrop Advanced"},
92
+ "SplitBboxes": {"class": SplitBboxes, "name": "Split Bboxes"},
93
+ "BboxToInt": {"class": BboxToInt, "name": "Bbox To Int"},
94
+ "BboxVisualize": {"class": BboxVisualize, "name": "Bbox Visualize"},
95
+ #noise
96
+ "GenerateNoise": {"class": GenerateNoise, "name": "Generate Noise"},
97
+ "FlipSigmasAdjusted": {"class": FlipSigmasAdjusted, "name": "Flip Sigmas Adjusted"},
98
+ "InjectNoiseToLatent": {"class": InjectNoiseToLatent, "name": "Inject Noise To Latent"},
99
+ "CustomSigmas": {"class": CustomSigmas, "name": "Custom Sigmas"},
100
+ #utility
101
+ "WidgetToString": {"class": WidgetToString, "name": "Widget To String"},
102
+ "DummyOut": {"class": DummyOut, "name": "Dummy Out"},
103
+ "GetLatentsFromBatchIndexed": {"class": GetLatentsFromBatchIndexed, "name": "Get Latents From Batch Indexed"},
104
+ "ScaleBatchPromptSchedule": {"class": ScaleBatchPromptSchedule, "name": "Scale Batch Prompt Schedule"},
105
+ "CameraPoseVisualizer": {"class": CameraPoseVisualizer, "name": "Camera Pose Visualizer"},
106
+ "AppendStringsToList": {"class": AppendStringsToList, "name": "Append Strings To List"},
107
+ "JoinStrings": {"class": JoinStrings, "name": "Join Strings"},
108
+ "JoinStringMulti": {"class": JoinStringMulti, "name": "Join String Multi"},
109
+ "SomethingToString": {"class": SomethingToString, "name": "Something To String"},
110
+ "Sleep": {"class": Sleep, "name": "Sleep"},
111
+ "VRAM_Debug": {"class": VRAM_Debug, "name": "VRAM Debug"},
112
+ "SomethingToString": {"class": SomethingToString, "name": "Something To String"},
113
+ "EmptyLatentImagePresets": {"class": EmptyLatentImagePresets, "name": "Empty Latent Image Presets"},
114
+ "EmptyLatentImageCustomPresets": {"class": EmptyLatentImageCustomPresets, "name": "Empty Latent Image Custom Presets"},
115
+ "ModelPassThrough": {"class": ModelPassThrough, "name": "ModelPass"},
116
+ "ModelSaveKJ": {"class": ModelSaveKJ, "name": "Model Save KJ"},
117
+ "SetShakkerLabsUnionControlNetType": {"class": SetShakkerLabsUnionControlNetType, "name": "Set Shakker Labs Union ControlNet Type"},
118
+ #audioscheduler stuff
119
+ "NormalizedAmplitudeToMask": {"class": NormalizedAmplitudeToMask},
120
+ "NormalizedAmplitudeToFloatList": {"class": NormalizedAmplitudeToFloatList},
121
+ "OffsetMaskByNormalizedAmplitude": {"class": OffsetMaskByNormalizedAmplitude},
122
+ "ImageTransformByNormalizedAmplitude": {"class": ImageTransformByNormalizedAmplitude},
123
+ #curve nodes
124
+ "SplineEditor": {"class": SplineEditor, "name": "Spline Editor"},
125
+ "CreateShapeImageOnPath": {"class": CreateShapeImageOnPath, "name": "Create Shape Image On Path"},
126
+ "CreateShapeMaskOnPath": {"class": CreateShapeMaskOnPath, "name": "Create Shape Mask On Path"},
127
+ "CreateTextOnPath": {"class": CreateTextOnPath, "name": "Create Text On Path"},
128
+ "CreateGradientFromCoords": {"class": CreateGradientFromCoords, "name": "Create Gradient From Coords"},
129
+ "GradientToFloat": {"class": GradientToFloat, "name": "Gradient To Float"},
130
+ "WeightScheduleExtend": {"class": WeightScheduleExtend, "name": "Weight Schedule Extend"},
131
+ "MaskOrImageToWeight": {"class": MaskOrImageToWeight, "name": "Mask Or Image To Weight"},
132
+ "WeightScheduleConvert": {"class": WeightScheduleConvert, "name": "Weight Schedule Convert"},
133
+ "FloatToMask": {"class": FloatToMask, "name": "Float To Mask"},
134
+ "FloatToSigmas": {"class": FloatToSigmas, "name": "Float To Sigmas"},
135
+ "SigmasToFloat": {"class": SigmasToFloat, "name": "Sigmas To Float"},
136
+ "PlotCoordinates": {"class": PlotCoordinates, "name": "Plot Coordinates"},
137
+ "InterpolateCoords": {"class": InterpolateCoords, "name": "Interpolate Coords"},
138
+ "PointsEditor": {"class": PointsEditor, "name": "Points Editor"},
139
+ #experimental
140
+ "StabilityAPI_SD3": {"class": StabilityAPI_SD3, "name": "Stability API SD3"},
141
+ "SoundReactive": {"class": SoundReactive, "name": "Sound Reactive"},
142
+ "StableZero123_BatchSchedule": {"class": StableZero123_BatchSchedule, "name": "Stable Zero123 Batch Schedule"},
143
+ "SV3D_BatchSchedule": {"class": SV3D_BatchSchedule, "name": "SV3D Batch Schedule"},
144
+ "LoadResAdapterNormalization": {"class": LoadResAdapterNormalization},
145
+ "Superprompt": {"class": Superprompt, "name": "Superprompt"},
146
+ "GLIGENTextBoxApplyBatchCoords": {"class": GLIGENTextBoxApplyBatchCoords},
147
+ "Intrinsic_lora_sampling": {"class": Intrinsic_lora_sampling, "name": "Intrinsic Lora Sampling"},
148
+ "CheckpointPerturbWeights": {"class": CheckpointPerturbWeights, "name": "CheckpointPerturbWeights"},
149
+ "Screencap_mss": {"class": Screencap_mss, "name": "Screencap mss"},
150
+ "WebcamCaptureCV2": {"class": WebcamCaptureCV2, "name": "Webcam Capture CV2"},
151
+ "DifferentialDiffusionAdvanced": {"class": DifferentialDiffusionAdvanced, "name": "Differential Diffusion Advanced"},
152
+ "FluxBlockLoraLoader": {"class": FluxBlockLoraLoader, "name": "Flux Block Lora Loader"},
153
+ "FluxBlockLoraSelect": {"class": FluxBlockLoraSelect, "name": "Flux Block Lora Select"},
154
+ "CustomControlNetWeightsFluxFromList": {"class": CustomControlNetWeightsFluxFromList, "name": "Custom ControlNet Weights Flux From List"},
155
+ "CheckpointLoaderKJ": {"class": CheckpointLoaderKJ, "name": "CheckpointLoaderKJ"},
156
+ "TorchCompileModelFluxAdvanced": {"class": TorchCompileModelFluxAdvanced, "name": "TorchCompileModelFluxAdvanced"},
157
+ "TorchCompileVAE": {"class": TorchCompileVAE, "name": "TorchCompileVAE"},
158
+ "TorchCompileControlNet": {"class": TorchCompileControlNet, "name": "TorchCompileControlNet"},
159
+ "PatchModelPatcherOrder": {"class": PatchModelPatcherOrder, "name": "Patch Model Patcher Order"},
160
+
161
+ #instance diffusion
162
+ "CreateInstanceDiffusionTracking": {"class": CreateInstanceDiffusionTracking},
163
+ "AppendInstanceDiffusionTracking": {"class": AppendInstanceDiffusionTracking},
164
+ "DrawInstanceDiffusionTracking": {"class": DrawInstanceDiffusionTracking},
165
+ }
166
+
167
+ def generate_node_mappings(node_config):
168
+ node_class_mappings = {}
169
+ node_display_name_mappings = {}
170
+
171
+ for node_name, node_info in node_config.items():
172
+ node_class_mappings[node_name] = node_info["class"]
173
+ node_display_name_mappings[node_name] = node_info.get("name", node_info["class"].__name__)
174
+
175
+ return node_class_mappings, node_display_name_mappings
176
+
177
+ NODE_CLASS_MAPPINGS, NODE_DISPLAY_NAME_MAPPINGS = generate_node_mappings(NODE_CONFIG)
178
+
179
+ __all__ = ["NODE_CLASS_MAPPINGS", "NODE_DISPLAY_NAME_MAPPINGS", "WEB_DIRECTORY"]
180
+
181
+ WEB_DIRECTORY = "./web"
182
+
183
+ from aiohttp import web
184
+ from server import PromptServer
185
+ from pathlib import Path
186
+
187
+ if hasattr(PromptServer, "instance"):
188
+ try:
189
+ # NOTE: we add an extra static path to avoid comfy mechanism
190
+ # that loads every script in web.
191
+ PromptServer.instance.app.add_routes(
192
+ [web.static("/kjweb_async", (Path(__file__).parent.absolute() / "kjweb_async").as_posix())]
193
+ )
194
+ except:
195
+ pass
ComfyUI-KJNodes/__pycache__/__init__.cpython-312.pyc ADDED
Binary file (12.7 kB). View file
 
ComfyUI-KJNodes/config.json ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ {
2
+ "sai_api_key": "your_api_key_here"
3
+ }
ComfyUI-KJNodes/custom_dimensions.json ADDED
@@ -0,0 +1,22 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ [
2
+ {
3
+ "label": "SD",
4
+ "value": "512x512"
5
+ },
6
+ {
7
+ "label": "HD",
8
+ "value": "768x768"
9
+ },
10
+ {
11
+ "label": "Full HD",
12
+ "value": "1024x1024"
13
+ },
14
+ {
15
+ "label": "4k",
16
+ "value": "2048x2048"
17
+ },
18
+ {
19
+ "label": "SVD",
20
+ "value": "1024x576"
21
+ }
22
+ ]
ComfyUI-KJNodes/docs/images/2024-04-03_20_49_29-ComfyUI.png ADDED
ComfyUI-KJNodes/docs/images/319121566-05f66385-7568-4b1f-8bbc-11053660b02f.png ADDED
ComfyUI-KJNodes/docs/images/319121636-706b5081-9120-4a29-bd76-901691ada688.png ADDED
ComfyUI-KJNodes/fonts/FreeMono.ttf ADDED
Binary file (344 kB). View file
 
ComfyUI-KJNodes/fonts/FreeMonoBoldOblique.otf ADDED
Binary file (238 kB). View file
 
ComfyUI-KJNodes/fonts/TTNorms-Black.otf ADDED
Binary file (153 kB). View file
 
ComfyUI-KJNodes/intrinsic_loras/intrinsic_lora_sd15_albedo.safetensors ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:d897f04ff2bb452e29a8f2a3c5c3cd5c55e95f314242cd645fbbe24a5ac59961
3
+ size 6416109
ComfyUI-KJNodes/intrinsic_loras/intrinsic_lora_sd15_depth.safetensors ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:f199d6bf3180fe7271073c3769dcb764b40f35f41b30fcb183ae5bf4b6a9997f
3
+ size 6416109
ComfyUI-KJNodes/intrinsic_loras/intrinsic_lora_sd15_normal.safetensors ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:02934db0a0b92a9cdda402e42548560beda7d31b268e561dbc6815551e876268
3
+ size 6416109
ComfyUI-KJNodes/intrinsic_loras/intrinsic_lora_sd15_shading.safetensors ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:635e998063a10211633edd3e4b1676201822cd67f790ec71dba5f32d8b625c8b
3
+ size 6416109
ComfyUI-KJNodes/intrinsic_loras/intrinsic_loras.txt ADDED
@@ -0,0 +1,4 @@
 
 
 
 
 
1
+ source for the loras:
2
+ https://github.com/duxiaodan/intrinsic-lora
3
+
4
+ Renamed and conveted to .safetensors
ComfyUI-KJNodes/kjweb_async/marked.min.js ADDED
@@ -0,0 +1,6 @@
 
 
 
 
 
 
 
1
+ /**
2
+ * marked v12.0.1 - a markdown parser
3
+ * Copyright (c) 2011-2024, Christopher Jeffrey. (MIT Licensed)
4
+ * https://github.com/markedjs/marked
5
+ */
6
+ !function(e,t){"object"==typeof exports&&"undefined"!=typeof module?t(exports):"function"==typeof define&&define.amd?define(["exports"],t):t((e="undefined"!=typeof globalThis?globalThis:e||self).marked={})}(this,(function(e){"use strict";function t(){return{async:!1,breaks:!1,extensions:null,gfm:!0,hooks:null,pedantic:!1,renderer:null,silent:!1,tokenizer:null,walkTokens:null}}function n(t){e.defaults=t}e.defaults={async:!1,breaks:!1,extensions:null,gfm:!0,hooks:null,pedantic:!1,renderer:null,silent:!1,tokenizer:null,walkTokens:null};const s=/[&<>"']/,r=new RegExp(s.source,"g"),i=/[<>"']|&(?!(#\d{1,7}|#[Xx][a-fA-F0-9]{1,6}|\w+);)/,l=new RegExp(i.source,"g"),o={"&":"&amp;","<":"&lt;",">":"&gt;",'"':"&quot;","'":"&#39;"},a=e=>o[e];function c(e,t){if(t){if(s.test(e))return e.replace(r,a)}else if(i.test(e))return e.replace(l,a);return e}const h=/&(#(?:\d+)|(?:#x[0-9A-Fa-f]+)|(?:\w+));?/gi;function p(e){return e.replace(h,((e,t)=>"colon"===(t=t.toLowerCase())?":":"#"===t.charAt(0)?"x"===t.charAt(1)?String.fromCharCode(parseInt(t.substring(2),16)):String.fromCharCode(+t.substring(1)):""))}const u=/(^|[^\[])\^/g;function k(e,t){let n="string"==typeof e?e:e.source;t=t||"";const s={replace:(e,t)=>{let r="string"==typeof t?t:t.source;return r=r.replace(u,"$1"),n=n.replace(e,r),s},getRegex:()=>new RegExp(n,t)};return s}function g(e){try{e=encodeURI(e).replace(/%25/g,"%")}catch(e){return null}return e}const f={exec:()=>null};function d(e,t){const n=e.replace(/\|/g,((e,t,n)=>{let s=!1,r=t;for(;--r>=0&&"\\"===n[r];)s=!s;return s?"|":" |"})).split(/ \|/);let s=0;if(n[0].trim()||n.shift(),n.length>0&&!n[n.length-1].trim()&&n.pop(),t)if(n.length>t)n.splice(t);else for(;n.length<t;)n.push("");for(;s<n.length;s++)n[s]=n[s].trim().replace(/\\\|/g,"|");return n}function x(e,t,n){const s=e.length;if(0===s)return"";let r=0;for(;r<s;){const i=e.charAt(s-r-1);if(i!==t||n){if(i===t||!n)break;r++}else r++}return e.slice(0,s-r)}function b(e,t,n,s){const r=t.href,i=t.title?c(t.title):null,l=e[1].replace(/\\([\[\]])/g,"$1");if("!"!==e[0].charAt(0)){s.state.inLink=!0;const e={type:"link",raw:n,href:r,title:i,text:l,tokens:s.inlineTokens(l)};return s.state.inLink=!1,e}return{type:"image",raw:n,href:r,title:i,text:c(l)}}class w{options;rules;lexer;constructor(t){this.options=t||e.defaults}space(e){const t=this.rules.block.newline.exec(e);if(t&&t[0].length>0)return{type:"space",raw:t[0]}}code(e){const t=this.rules.block.code.exec(e);if(t){const e=t[0].replace(/^ {1,4}/gm,"");return{type:"code",raw:t[0],codeBlockStyle:"indented",text:this.options.pedantic?e:x(e,"\n")}}}fences(e){const t=this.rules.block.fences.exec(e);if(t){const e=t[0],n=function(e,t){const n=e.match(/^(\s+)(?:```)/);if(null===n)return t;const s=n[1];return t.split("\n").map((e=>{const t=e.match(/^\s+/);if(null===t)return e;const[n]=t;return n.length>=s.length?e.slice(s.length):e})).join("\n")}(e,t[3]||"");return{type:"code",raw:e,lang:t[2]?t[2].trim().replace(this.rules.inline.anyPunctuation,"$1"):t[2],text:n}}}heading(e){const t=this.rules.block.heading.exec(e);if(t){let e=t[2].trim();if(/#$/.test(e)){const t=x(e,"#");this.options.pedantic?e=t.trim():t&&!/ $/.test(t)||(e=t.trim())}return{type:"heading",raw:t[0],depth:t[1].length,text:e,tokens:this.lexer.inline(e)}}}hr(e){const t=this.rules.block.hr.exec(e);if(t)return{type:"hr",raw:t[0]}}blockquote(e){const t=this.rules.block.blockquote.exec(e);if(t){const e=x(t[0].replace(/^ *>[ \t]?/gm,""),"\n"),n=this.lexer.state.top;this.lexer.state.top=!0;const s=this.lexer.blockTokens(e);return this.lexer.state.top=n,{type:"blockquote",raw:t[0],tokens:s,text:e}}}list(e){let t=this.rules.block.list.exec(e);if(t){let n=t[1].trim();const s=n.length>1,r={type:"list",raw:"",ordered:s,start:s?+n.slice(0,-1):"",loose:!1,items:[]};n=s?`\\d{1,9}\\${n.slice(-1)}`:`\\${n}`,this.options.pedantic&&(n=s?n:"[*+-]");const i=new RegExp(`^( {0,3}${n})((?:[\t ][^\\n]*)?(?:\\n|$))`);let l="",o="",a=!1;for(;e;){let n=!1;if(!(t=i.exec(e)))break;if(this.rules.block.hr.test(e))break;l=t[0],e=e.substring(l.length);let s=t[2].split("\n",1)[0].replace(/^\t+/,(e=>" ".repeat(3*e.length))),c=e.split("\n",1)[0],h=0;this.options.pedantic?(h=2,o=s.trimStart()):(h=t[2].search(/[^ ]/),h=h>4?1:h,o=s.slice(h),h+=t[1].length);let p=!1;if(!s&&/^ *$/.test(c)&&(l+=c+"\n",e=e.substring(c.length+1),n=!0),!n){const t=new RegExp(`^ {0,${Math.min(3,h-1)}}(?:[*+-]|\\d{1,9}[.)])((?:[ \t][^\\n]*)?(?:\\n|$))`),n=new RegExp(`^ {0,${Math.min(3,h-1)}}((?:- *){3,}|(?:_ *){3,}|(?:\\* *){3,})(?:\\n+|$)`),r=new RegExp(`^ {0,${Math.min(3,h-1)}}(?:\`\`\`|~~~)`),i=new RegExp(`^ {0,${Math.min(3,h-1)}}#`);for(;e;){const a=e.split("\n",1)[0];if(c=a,this.options.pedantic&&(c=c.replace(/^ {1,4}(?=( {4})*[^ ])/g," ")),r.test(c))break;if(i.test(c))break;if(t.test(c))break;if(n.test(e))break;if(c.search(/[^ ]/)>=h||!c.trim())o+="\n"+c.slice(h);else{if(p)break;if(s.search(/[^ ]/)>=4)break;if(r.test(s))break;if(i.test(s))break;if(n.test(s))break;o+="\n"+c}p||c.trim()||(p=!0),l+=a+"\n",e=e.substring(a.length+1),s=c.slice(h)}}r.loose||(a?r.loose=!0:/\n *\n *$/.test(l)&&(a=!0));let u,k=null;this.options.gfm&&(k=/^\[[ xX]\] /.exec(o),k&&(u="[ ] "!==k[0],o=o.replace(/^\[[ xX]\] +/,""))),r.items.push({type:"list_item",raw:l,task:!!k,checked:u,loose:!1,text:o,tokens:[]}),r.raw+=l}r.items[r.items.length-1].raw=l.trimEnd(),r.items[r.items.length-1].text=o.trimEnd(),r.raw=r.raw.trimEnd();for(let e=0;e<r.items.length;e++)if(this.lexer.state.top=!1,r.items[e].tokens=this.lexer.blockTokens(r.items[e].text,[]),!r.loose){const t=r.items[e].tokens.filter((e=>"space"===e.type)),n=t.length>0&&t.some((e=>/\n.*\n/.test(e.raw)));r.loose=n}if(r.loose)for(let e=0;e<r.items.length;e++)r.items[e].loose=!0;return r}}html(e){const t=this.rules.block.html.exec(e);if(t){return{type:"html",block:!0,raw:t[0],pre:"pre"===t[1]||"script"===t[1]||"style"===t[1],text:t[0]}}}def(e){const t=this.rules.block.def.exec(e);if(t){const e=t[1].toLowerCase().replace(/\s+/g," "),n=t[2]?t[2].replace(/^<(.*)>$/,"$1").replace(this.rules.inline.anyPunctuation,"$1"):"",s=t[3]?t[3].substring(1,t[3].length-1).replace(this.rules.inline.anyPunctuation,"$1"):t[3];return{type:"def",tag:e,raw:t[0],href:n,title:s}}}table(e){const t=this.rules.block.table.exec(e);if(!t)return;if(!/[:|]/.test(t[2]))return;const n=d(t[1]),s=t[2].replace(/^\||\| *$/g,"").split("|"),r=t[3]&&t[3].trim()?t[3].replace(/\n[ \t]*$/,"").split("\n"):[],i={type:"table",raw:t[0],header:[],align:[],rows:[]};if(n.length===s.length){for(const e of s)/^ *-+: *$/.test(e)?i.align.push("right"):/^ *:-+: *$/.test(e)?i.align.push("center"):/^ *:-+ *$/.test(e)?i.align.push("left"):i.align.push(null);for(const e of n)i.header.push({text:e,tokens:this.lexer.inline(e)});for(const e of r)i.rows.push(d(e,i.header.length).map((e=>({text:e,tokens:this.lexer.inline(e)}))));return i}}lheading(e){const t=this.rules.block.lheading.exec(e);if(t)return{type:"heading",raw:t[0],depth:"="===t[2].charAt(0)?1:2,text:t[1],tokens:this.lexer.inline(t[1])}}paragraph(e){const t=this.rules.block.paragraph.exec(e);if(t){const e="\n"===t[1].charAt(t[1].length-1)?t[1].slice(0,-1):t[1];return{type:"paragraph",raw:t[0],text:e,tokens:this.lexer.inline(e)}}}text(e){const t=this.rules.block.text.exec(e);if(t)return{type:"text",raw:t[0],text:t[0],tokens:this.lexer.inline(t[0])}}escape(e){const t=this.rules.inline.escape.exec(e);if(t)return{type:"escape",raw:t[0],text:c(t[1])}}tag(e){const t=this.rules.inline.tag.exec(e);if(t)return!this.lexer.state.inLink&&/^<a /i.test(t[0])?this.lexer.state.inLink=!0:this.lexer.state.inLink&&/^<\/a>/i.test(t[0])&&(this.lexer.state.inLink=!1),!this.lexer.state.inRawBlock&&/^<(pre|code|kbd|script)(\s|>)/i.test(t[0])?this.lexer.state.inRawBlock=!0:this.lexer.state.inRawBlock&&/^<\/(pre|code|kbd|script)(\s|>)/i.test(t[0])&&(this.lexer.state.inRawBlock=!1),{type:"html",raw:t[0],inLink:this.lexer.state.inLink,inRawBlock:this.lexer.state.inRawBlock,block:!1,text:t[0]}}link(e){const t=this.rules.inline.link.exec(e);if(t){const e=t[2].trim();if(!this.options.pedantic&&/^</.test(e)){if(!/>$/.test(e))return;const t=x(e.slice(0,-1),"\\");if((e.length-t.length)%2==0)return}else{const e=function(e,t){if(-1===e.indexOf(t[1]))return-1;let n=0;for(let s=0;s<e.length;s++)if("\\"===e[s])s++;else if(e[s]===t[0])n++;else if(e[s]===t[1]&&(n--,n<0))return s;return-1}(t[2],"()");if(e>-1){const n=(0===t[0].indexOf("!")?5:4)+t[1].length+e;t[2]=t[2].substring(0,e),t[0]=t[0].substring(0,n).trim(),t[3]=""}}let n=t[2],s="";if(this.options.pedantic){const e=/^([^'"]*[^\s])\s+(['"])(.*)\2/.exec(n);e&&(n=e[1],s=e[3])}else s=t[3]?t[3].slice(1,-1):"";return n=n.trim(),/^</.test(n)&&(n=this.options.pedantic&&!/>$/.test(e)?n.slice(1):n.slice(1,-1)),b(t,{href:n?n.replace(this.rules.inline.anyPunctuation,"$1"):n,title:s?s.replace(this.rules.inline.anyPunctuation,"$1"):s},t[0],this.lexer)}}reflink(e,t){let n;if((n=this.rules.inline.reflink.exec(e))||(n=this.rules.inline.nolink.exec(e))){const e=t[(n[2]||n[1]).replace(/\s+/g," ").toLowerCase()];if(!e){const e=n[0].charAt(0);return{type:"text",raw:e,text:e}}return b(n,e,n[0],this.lexer)}}emStrong(e,t,n=""){let s=this.rules.inline.emStrongLDelim.exec(e);if(!s)return;if(s[3]&&n.match(/[\p{L}\p{N}]/u))return;if(!(s[1]||s[2]||"")||!n||this.rules.inline.punctuation.exec(n)){const n=[...s[0]].length-1;let r,i,l=n,o=0;const a="*"===s[0][0]?this.rules.inline.emStrongRDelimAst:this.rules.inline.emStrongRDelimUnd;for(a.lastIndex=0,t=t.slice(-1*e.length+n);null!=(s=a.exec(t));){if(r=s[1]||s[2]||s[3]||s[4]||s[5]||s[6],!r)continue;if(i=[...r].length,s[3]||s[4]){l+=i;continue}if((s[5]||s[6])&&n%3&&!((n+i)%3)){o+=i;continue}if(l-=i,l>0)continue;i=Math.min(i,i+l+o);const t=[...s[0]][0].length,a=e.slice(0,n+s.index+t+i);if(Math.min(n,i)%2){const e=a.slice(1,-1);return{type:"em",raw:a,text:e,tokens:this.lexer.inlineTokens(e)}}const c=a.slice(2,-2);return{type:"strong",raw:a,text:c,tokens:this.lexer.inlineTokens(c)}}}}codespan(e){const t=this.rules.inline.code.exec(e);if(t){let e=t[2].replace(/\n/g," ");const n=/[^ ]/.test(e),s=/^ /.test(e)&&/ $/.test(e);return n&&s&&(e=e.substring(1,e.length-1)),e=c(e,!0),{type:"codespan",raw:t[0],text:e}}}br(e){const t=this.rules.inline.br.exec(e);if(t)return{type:"br",raw:t[0]}}del(e){const t=this.rules.inline.del.exec(e);if(t)return{type:"del",raw:t[0],text:t[2],tokens:this.lexer.inlineTokens(t[2])}}autolink(e){const t=this.rules.inline.autolink.exec(e);if(t){let e,n;return"@"===t[2]?(e=c(t[1]),n="mailto:"+e):(e=c(t[1]),n=e),{type:"link",raw:t[0],text:e,href:n,tokens:[{type:"text",raw:e,text:e}]}}}url(e){let t;if(t=this.rules.inline.url.exec(e)){let e,n;if("@"===t[2])e=c(t[0]),n="mailto:"+e;else{let s;do{s=t[0],t[0]=this.rules.inline._backpedal.exec(t[0])?.[0]??""}while(s!==t[0]);e=c(t[0]),n="www."===t[1]?"http://"+t[0]:t[0]}return{type:"link",raw:t[0],text:e,href:n,tokens:[{type:"text",raw:e,text:e}]}}}inlineText(e){const t=this.rules.inline.text.exec(e);if(t){let e;return e=this.lexer.state.inRawBlock?t[0]:c(t[0]),{type:"text",raw:t[0],text:e}}}}const m=/^ {0,3}((?:-[\t ]*){3,}|(?:_[ \t]*){3,}|(?:\*[ \t]*){3,})(?:\n+|$)/,y=/(?:[*+-]|\d{1,9}[.)])/,$=k(/^(?!bull |blockCode|fences|blockquote|heading|html)((?:.|\n(?!\s*?\n|bull |blockCode|fences|blockquote|heading|html))+?)\n {0,3}(=+|-+) *(?:\n+|$)/).replace(/bull/g,y).replace(/blockCode/g,/ {4}/).replace(/fences/g,/ {0,3}(?:`{3,}|~{3,})/).replace(/blockquote/g,/ {0,3}>/).replace(/heading/g,/ {0,3}#{1,6}/).replace(/html/g,/ {0,3}<[^\n>]+>\n/).getRegex(),z=/^([^\n]+(?:\n(?!hr|heading|lheading|blockquote|fences|list|html|table| +\n)[^\n]+)*)/,T=/(?!\s*\])(?:\\.|[^\[\]\\])+/,R=k(/^ {0,3}\[(label)\]: *(?:\n *)?([^<\s][^\s]*|<.*?>)(?:(?: +(?:\n *)?| *\n *)(title))? *(?:\n+|$)/).replace("label",T).replace("title",/(?:"(?:\\"?|[^"\\])*"|'[^'\n]*(?:\n[^'\n]+)*\n?'|\([^()]*\))/).getRegex(),_=k(/^( {0,3}bull)([ \t][^\n]+?)?(?:\n|$)/).replace(/bull/g,y).getRegex(),A="address|article|aside|base|basefont|blockquote|body|caption|center|col|colgroup|dd|details|dialog|dir|div|dl|dt|fieldset|figcaption|figure|footer|form|frame|frameset|h[1-6]|head|header|hr|html|iframe|legend|li|link|main|menu|menuitem|meta|nav|noframes|ol|optgroup|option|p|param|search|section|summary|table|tbody|td|tfoot|th|thead|title|tr|track|ul",S=/<!--(?:-?>|[\s\S]*?(?:-->|$))/,I=k("^ {0,3}(?:<(script|pre|style|textarea)[\\s>][\\s\\S]*?(?:</\\1>[^\\n]*\\n+|$)|comment[^\\n]*(\\n+|$)|<\\?[\\s\\S]*?(?:\\?>\\n*|$)|<![A-Z][\\s\\S]*?(?:>\\n*|$)|<!\\[CDATA\\[[\\s\\S]*?(?:\\]\\]>\\n*|$)|</?(tag)(?: +|\\n|/?>)[\\s\\S]*?(?:(?:\\n *)+\\n|$)|<(?!script|pre|style|textarea)([a-z][\\w-]*)(?:attribute)*? */?>(?=[ \\t]*(?:\\n|$))[\\s\\S]*?(?:(?:\\n *)+\\n|$)|</(?!script|pre|style|textarea)[a-z][\\w-]*\\s*>(?=[ \\t]*(?:\\n|$))[\\s\\S]*?(?:(?:\\n *)+\\n|$))","i").replace("comment",S).replace("tag",A).replace("attribute",/ +[a-zA-Z:_][\w.:-]*(?: *= *"[^"\n]*"| *= *'[^'\n]*'| *= *[^\s"'=<>`]+)?/).getRegex(),E=k(z).replace("hr",m).replace("heading"," {0,3}#{1,6}(?:\\s|$)").replace("|lheading","").replace("|table","").replace("blockquote"," {0,3}>").replace("fences"," {0,3}(?:`{3,}(?=[^`\\n]*\\n)|~{3,})[^\\n]*\\n").replace("list"," {0,3}(?:[*+-]|1[.)]) ").replace("html","</?(?:tag)(?: +|\\n|/?>)|<(?:script|pre|style|textarea|!--)").replace("tag",A).getRegex(),q={blockquote:k(/^( {0,3}> ?(paragraph|[^\n]*)(?:\n|$))+/).replace("paragraph",E).getRegex(),code:/^( {4}[^\n]+(?:\n(?: *(?:\n|$))*)?)+/,def:R,fences:/^ {0,3}(`{3,}(?=[^`\n]*(?:\n|$))|~{3,})([^\n]*)(?:\n|$)(?:|([\s\S]*?)(?:\n|$))(?: {0,3}\1[~`]* *(?=\n|$)|$)/,heading:/^ {0,3}(#{1,6})(?=\s|$)(.*)(?:\n+|$)/,hr:m,html:I,lheading:$,list:_,newline:/^(?: *(?:\n|$))+/,paragraph:E,table:f,text:/^[^\n]+/},Z=k("^ *([^\\n ].*)\\n {0,3}((?:\\| *)?:?-+:? *(?:\\| *:?-+:? *)*(?:\\| *)?)(?:\\n((?:(?! *\\n|hr|heading|blockquote|code|fences|list|html).*(?:\\n|$))*)\\n*|$)").replace("hr",m).replace("heading"," {0,3}#{1,6}(?:\\s|$)").replace("blockquote"," {0,3}>").replace("code"," {4}[^\\n]").replace("fences"," {0,3}(?:`{3,}(?=[^`\\n]*\\n)|~{3,})[^\\n]*\\n").replace("list"," {0,3}(?:[*+-]|1[.)]) ").replace("html","</?(?:tag)(?: +|\\n|/?>)|<(?:script|pre|style|textarea|!--)").replace("tag",A).getRegex(),L={...q,table:Z,paragraph:k(z).replace("hr",m).replace("heading"," {0,3}#{1,6}(?:\\s|$)").replace("|lheading","").replace("table",Z).replace("blockquote"," {0,3}>").replace("fences"," {0,3}(?:`{3,}(?=[^`\\n]*\\n)|~{3,})[^\\n]*\\n").replace("list"," {0,3}(?:[*+-]|1[.)]) ").replace("html","</?(?:tag)(?: +|\\n|/?>)|<(?:script|pre|style|textarea|!--)").replace("tag",A).getRegex()},P={...q,html:k("^ *(?:comment *(?:\\n|\\s*$)|<(tag)[\\s\\S]+?</\\1> *(?:\\n{2,}|\\s*$)|<tag(?:\"[^\"]*\"|'[^']*'|\\s[^'\"/>\\s]*)*?/?> *(?:\\n{2,}|\\s*$))").replace("comment",S).replace(/tag/g,"(?!(?:a|em|strong|small|s|cite|q|dfn|abbr|data|time|code|var|samp|kbd|sub|sup|i|b|u|mark|ruby|rt|rp|bdi|bdo|span|br|wbr|ins|del|img)\\b)\\w+(?!:|[^\\w\\s@]*@)\\b").getRegex(),def:/^ *\[([^\]]+)\]: *<?([^\s>]+)>?(?: +(["(][^\n]+[")]))? *(?:\n+|$)/,heading:/^(#{1,6})(.*)(?:\n+|$)/,fences:f,lheading:/^(.+?)\n {0,3}(=+|-+) *(?:\n+|$)/,paragraph:k(z).replace("hr",m).replace("heading"," *#{1,6} *[^\n]").replace("lheading",$).replace("|table","").replace("blockquote"," {0,3}>").replace("|fences","").replace("|list","").replace("|html","").replace("|tag","").getRegex()},Q=/^\\([!"#$%&'()*+,\-./:;<=>?@\[\]\\^_`{|}~])/,v=/^( {2,}|\\)\n(?!\s*$)/,B="\\p{P}\\p{S}",C=k(/^((?![*_])[\spunctuation])/,"u").replace(/punctuation/g,B).getRegex(),M=k(/^(?:\*+(?:((?!\*)[punct])|[^\s*]))|^_+(?:((?!_)[punct])|([^\s_]))/,"u").replace(/punct/g,B).getRegex(),O=k("^[^_*]*?__[^_*]*?\\*[^_*]*?(?=__)|[^*]+(?=[^*])|(?!\\*)[punct](\\*+)(?=[\\s]|$)|[^punct\\s](\\*+)(?!\\*)(?=[punct\\s]|$)|(?!\\*)[punct\\s](\\*+)(?=[^punct\\s])|[\\s](\\*+)(?!\\*)(?=[punct])|(?!\\*)[punct](\\*+)(?!\\*)(?=[punct])|[^punct\\s](\\*+)(?=[^punct\\s])","gu").replace(/punct/g,B).getRegex(),D=k("^[^_*]*?\\*\\*[^_*]*?_[^_*]*?(?=\\*\\*)|[^_]+(?=[^_])|(?!_)[punct](_+)(?=[\\s]|$)|[^punct\\s](_+)(?!_)(?=[punct\\s]|$)|(?!_)[punct\\s](_+)(?=[^punct\\s])|[\\s](_+)(?!_)(?=[punct])|(?!_)[punct](_+)(?!_)(?=[punct])","gu").replace(/punct/g,B).getRegex(),j=k(/\\([punct])/,"gu").replace(/punct/g,B).getRegex(),H=k(/^<(scheme:[^\s\x00-\x1f<>]*|email)>/).replace("scheme",/[a-zA-Z][a-zA-Z0-9+.-]{1,31}/).replace("email",/[a-zA-Z0-9.!#$%&'*+/=?^_`{|}~-]+(@)[a-zA-Z0-9](?:[a-zA-Z0-9-]{0,61}[a-zA-Z0-9])?(?:\.[a-zA-Z0-9](?:[a-zA-Z0-9-]{0,61}[a-zA-Z0-9])?)+(?![-_])/).getRegex(),U=k(S).replace("(?:--\x3e|$)","--\x3e").getRegex(),X=k("^comment|^</[a-zA-Z][\\w:-]*\\s*>|^<[a-zA-Z][\\w-]*(?:attribute)*?\\s*/?>|^<\\?[\\s\\S]*?\\?>|^<![a-zA-Z]+\\s[\\s\\S]*?>|^<!\\[CDATA\\[[\\s\\S]*?\\]\\]>").replace("comment",U).replace("attribute",/\s+[a-zA-Z:_][\w.:-]*(?:\s*=\s*"[^"]*"|\s*=\s*'[^']*'|\s*=\s*[^\s"'=<>`]+)?/).getRegex(),F=/(?:\[(?:\\.|[^\[\]\\])*\]|\\.|`[^`]*`|[^\[\]\\`])*?/,N=k(/^!?\[(label)\]\(\s*(href)(?:\s+(title))?\s*\)/).replace("label",F).replace("href",/<(?:\\.|[^\n<>\\])+>|[^\s\x00-\x1f]*/).replace("title",/"(?:\\"?|[^"\\])*"|'(?:\\'?|[^'\\])*'|\((?:\\\)?|[^)\\])*\)/).getRegex(),G=k(/^!?\[(label)\]\[(ref)\]/).replace("label",F).replace("ref",T).getRegex(),J=k(/^!?\[(ref)\](?:\[\])?/).replace("ref",T).getRegex(),K={_backpedal:f,anyPunctuation:j,autolink:H,blockSkip:/\[[^[\]]*?\]\([^\(\)]*?\)|`[^`]*?`|<[^<>]*?>/g,br:v,code:/^(`+)([^`]|[^`][\s\S]*?[^`])\1(?!`)/,del:f,emStrongLDelim:M,emStrongRDelimAst:O,emStrongRDelimUnd:D,escape:Q,link:N,nolink:J,punctuation:C,reflink:G,reflinkSearch:k("reflink|nolink(?!\\()","g").replace("reflink",G).replace("nolink",J).getRegex(),tag:X,text:/^(`+|[^`])(?:(?= {2,}\n)|[\s\S]*?(?:(?=[\\<!\[`*_]|\b_|$)|[^ ](?= {2,}\n)))/,url:f},V={...K,link:k(/^!?\[(label)\]\((.*?)\)/).replace("label",F).getRegex(),reflink:k(/^!?\[(label)\]\s*\[([^\]]*)\]/).replace("label",F).getRegex()},W={...K,escape:k(Q).replace("])","~|])").getRegex(),url:k(/^((?:ftp|https?):\/\/|www\.)(?:[a-zA-Z0-9\-]+\.?)+[^\s<]*|^email/,"i").replace("email",/[A-Za-z0-9._+-]+(@)[a-zA-Z0-9-_]+(?:\.[a-zA-Z0-9-_]*[a-zA-Z0-9])+(?![-_])/).getRegex(),_backpedal:/(?:[^?!.,:;*_'"~()&]+|\([^)]*\)|&(?![a-zA-Z0-9]+;$)|[?!.,:;*_'"~)]+(?!$))+/,del:/^(~~?)(?=[^\s~])([\s\S]*?[^\s~])\1(?=[^~]|$)/,text:/^([`~]+|[^`~])(?:(?= {2,}\n)|(?=[a-zA-Z0-9.!#$%&'*+\/=?_`{\|}~-]+@)|[\s\S]*?(?:(?=[\\<!\[`*~_]|\b_|https?:\/\/|ftp:\/\/|www\.|$)|[^ ](?= {2,}\n)|[^a-zA-Z0-9.!#$%&'*+\/=?_`{\|}~-](?=[a-zA-Z0-9.!#$%&'*+\/=?_`{\|}~-]+@)))/},Y={...W,br:k(v).replace("{2,}","*").getRegex(),text:k(W.text).replace("\\b_","\\b_| {2,}\\n").replace(/\{2,\}/g,"*").getRegex()},ee={normal:q,gfm:L,pedantic:P},te={normal:K,gfm:W,breaks:Y,pedantic:V};class ne{tokens;options;state;tokenizer;inlineQueue;constructor(t){this.tokens=[],this.tokens.links=Object.create(null),this.options=t||e.defaults,this.options.tokenizer=this.options.tokenizer||new w,this.tokenizer=this.options.tokenizer,this.tokenizer.options=this.options,this.tokenizer.lexer=this,this.inlineQueue=[],this.state={inLink:!1,inRawBlock:!1,top:!0};const n={block:ee.normal,inline:te.normal};this.options.pedantic?(n.block=ee.pedantic,n.inline=te.pedantic):this.options.gfm&&(n.block=ee.gfm,this.options.breaks?n.inline=te.breaks:n.inline=te.gfm),this.tokenizer.rules=n}static get rules(){return{block:ee,inline:te}}static lex(e,t){return new ne(t).lex(e)}static lexInline(e,t){return new ne(t).inlineTokens(e)}lex(e){e=e.replace(/\r\n|\r/g,"\n"),this.blockTokens(e,this.tokens);for(let e=0;e<this.inlineQueue.length;e++){const t=this.inlineQueue[e];this.inlineTokens(t.src,t.tokens)}return this.inlineQueue=[],this.tokens}blockTokens(e,t=[]){let n,s,r,i;for(e=this.options.pedantic?e.replace(/\t/g," ").replace(/^ +$/gm,""):e.replace(/^( *)(\t+)/gm,((e,t,n)=>t+" ".repeat(n.length)));e;)if(!(this.options.extensions&&this.options.extensions.block&&this.options.extensions.block.some((s=>!!(n=s.call({lexer:this},e,t))&&(e=e.substring(n.raw.length),t.push(n),!0)))))if(n=this.tokenizer.space(e))e=e.substring(n.raw.length),1===n.raw.length&&t.length>0?t[t.length-1].raw+="\n":t.push(n);else if(n=this.tokenizer.code(e))e=e.substring(n.raw.length),s=t[t.length-1],!s||"paragraph"!==s.type&&"text"!==s.type?t.push(n):(s.raw+="\n"+n.raw,s.text+="\n"+n.text,this.inlineQueue[this.inlineQueue.length-1].src=s.text);else if(n=this.tokenizer.fences(e))e=e.substring(n.raw.length),t.push(n);else if(n=this.tokenizer.heading(e))e=e.substring(n.raw.length),t.push(n);else if(n=this.tokenizer.hr(e))e=e.substring(n.raw.length),t.push(n);else if(n=this.tokenizer.blockquote(e))e=e.substring(n.raw.length),t.push(n);else if(n=this.tokenizer.list(e))e=e.substring(n.raw.length),t.push(n);else if(n=this.tokenizer.html(e))e=e.substring(n.raw.length),t.push(n);else if(n=this.tokenizer.def(e))e=e.substring(n.raw.length),s=t[t.length-1],!s||"paragraph"!==s.type&&"text"!==s.type?this.tokens.links[n.tag]||(this.tokens.links[n.tag]={href:n.href,title:n.title}):(s.raw+="\n"+n.raw,s.text+="\n"+n.raw,this.inlineQueue[this.inlineQueue.length-1].src=s.text);else if(n=this.tokenizer.table(e))e=e.substring(n.raw.length),t.push(n);else if(n=this.tokenizer.lheading(e))e=e.substring(n.raw.length),t.push(n);else{if(r=e,this.options.extensions&&this.options.extensions.startBlock){let t=1/0;const n=e.slice(1);let s;this.options.extensions.startBlock.forEach((e=>{s=e.call({lexer:this},n),"number"==typeof s&&s>=0&&(t=Math.min(t,s))})),t<1/0&&t>=0&&(r=e.substring(0,t+1))}if(this.state.top&&(n=this.tokenizer.paragraph(r)))s=t[t.length-1],i&&"paragraph"===s.type?(s.raw+="\n"+n.raw,s.text+="\n"+n.text,this.inlineQueue.pop(),this.inlineQueue[this.inlineQueue.length-1].src=s.text):t.push(n),i=r.length!==e.length,e=e.substring(n.raw.length);else if(n=this.tokenizer.text(e))e=e.substring(n.raw.length),s=t[t.length-1],s&&"text"===s.type?(s.raw+="\n"+n.raw,s.text+="\n"+n.text,this.inlineQueue.pop(),this.inlineQueue[this.inlineQueue.length-1].src=s.text):t.push(n);else if(e){const t="Infinite loop on byte: "+e.charCodeAt(0);if(this.options.silent){console.error(t);break}throw new Error(t)}}return this.state.top=!0,t}inline(e,t=[]){return this.inlineQueue.push({src:e,tokens:t}),t}inlineTokens(e,t=[]){let n,s,r,i,l,o,a=e;if(this.tokens.links){const e=Object.keys(this.tokens.links);if(e.length>0)for(;null!=(i=this.tokenizer.rules.inline.reflinkSearch.exec(a));)e.includes(i[0].slice(i[0].lastIndexOf("[")+1,-1))&&(a=a.slice(0,i.index)+"["+"a".repeat(i[0].length-2)+"]"+a.slice(this.tokenizer.rules.inline.reflinkSearch.lastIndex))}for(;null!=(i=this.tokenizer.rules.inline.blockSkip.exec(a));)a=a.slice(0,i.index)+"["+"a".repeat(i[0].length-2)+"]"+a.slice(this.tokenizer.rules.inline.blockSkip.lastIndex);for(;null!=(i=this.tokenizer.rules.inline.anyPunctuation.exec(a));)a=a.slice(0,i.index)+"++"+a.slice(this.tokenizer.rules.inline.anyPunctuation.lastIndex);for(;e;)if(l||(o=""),l=!1,!(this.options.extensions&&this.options.extensions.inline&&this.options.extensions.inline.some((s=>!!(n=s.call({lexer:this},e,t))&&(e=e.substring(n.raw.length),t.push(n),!0)))))if(n=this.tokenizer.escape(e))e=e.substring(n.raw.length),t.push(n);else if(n=this.tokenizer.tag(e))e=e.substring(n.raw.length),s=t[t.length-1],s&&"text"===n.type&&"text"===s.type?(s.raw+=n.raw,s.text+=n.text):t.push(n);else if(n=this.tokenizer.link(e))e=e.substring(n.raw.length),t.push(n);else if(n=this.tokenizer.reflink(e,this.tokens.links))e=e.substring(n.raw.length),s=t[t.length-1],s&&"text"===n.type&&"text"===s.type?(s.raw+=n.raw,s.text+=n.text):t.push(n);else if(n=this.tokenizer.emStrong(e,a,o))e=e.substring(n.raw.length),t.push(n);else if(n=this.tokenizer.codespan(e))e=e.substring(n.raw.length),t.push(n);else if(n=this.tokenizer.br(e))e=e.substring(n.raw.length),t.push(n);else if(n=this.tokenizer.del(e))e=e.substring(n.raw.length),t.push(n);else if(n=this.tokenizer.autolink(e))e=e.substring(n.raw.length),t.push(n);else if(this.state.inLink||!(n=this.tokenizer.url(e))){if(r=e,this.options.extensions&&this.options.extensions.startInline){let t=1/0;const n=e.slice(1);let s;this.options.extensions.startInline.forEach((e=>{s=e.call({lexer:this},n),"number"==typeof s&&s>=0&&(t=Math.min(t,s))})),t<1/0&&t>=0&&(r=e.substring(0,t+1))}if(n=this.tokenizer.inlineText(r))e=e.substring(n.raw.length),"_"!==n.raw.slice(-1)&&(o=n.raw.slice(-1)),l=!0,s=t[t.length-1],s&&"text"===s.type?(s.raw+=n.raw,s.text+=n.text):t.push(n);else if(e){const t="Infinite loop on byte: "+e.charCodeAt(0);if(this.options.silent){console.error(t);break}throw new Error(t)}}else e=e.substring(n.raw.length),t.push(n);return t}}class se{options;constructor(t){this.options=t||e.defaults}code(e,t,n){const s=(t||"").match(/^\S*/)?.[0];return e=e.replace(/\n$/,"")+"\n",s?'<pre><code class="language-'+c(s)+'">'+(n?e:c(e,!0))+"</code></pre>\n":"<pre><code>"+(n?e:c(e,!0))+"</code></pre>\n"}blockquote(e){return`<blockquote>\n${e}</blockquote>\n`}html(e,t){return e}heading(e,t,n){return`<h${t}>${e}</h${t}>\n`}hr(){return"<hr>\n"}list(e,t,n){const s=t?"ol":"ul";return"<"+s+(t&&1!==n?' start="'+n+'"':"")+">\n"+e+"</"+s+">\n"}listitem(e,t,n){return`<li>${e}</li>\n`}checkbox(e){return"<input "+(e?'checked="" ':"")+'disabled="" type="checkbox">'}paragraph(e){return`<p>${e}</p>\n`}table(e,t){return t&&(t=`<tbody>${t}</tbody>`),"<table>\n<thead>\n"+e+"</thead>\n"+t+"</table>\n"}tablerow(e){return`<tr>\n${e}</tr>\n`}tablecell(e,t){const n=t.header?"th":"td";return(t.align?`<${n} align="${t.align}">`:`<${n}>`)+e+`</${n}>\n`}strong(e){return`<strong>${e}</strong>`}em(e){return`<em>${e}</em>`}codespan(e){return`<code>${e}</code>`}br(){return"<br>"}del(e){return`<del>${e}</del>`}link(e,t,n){const s=g(e);if(null===s)return n;let r='<a href="'+(e=s)+'"';return t&&(r+=' title="'+t+'"'),r+=">"+n+"</a>",r}image(e,t,n){const s=g(e);if(null===s)return n;let r=`<img src="${e=s}" alt="${n}"`;return t&&(r+=` title="${t}"`),r+=">",r}text(e){return e}}class re{strong(e){return e}em(e){return e}codespan(e){return e}del(e){return e}html(e){return e}text(e){return e}link(e,t,n){return""+n}image(e,t,n){return""+n}br(){return""}}class ie{options;renderer;textRenderer;constructor(t){this.options=t||e.defaults,this.options.renderer=this.options.renderer||new se,this.renderer=this.options.renderer,this.renderer.options=this.options,this.textRenderer=new re}static parse(e,t){return new ie(t).parse(e)}static parseInline(e,t){return new ie(t).parseInline(e)}parse(e,t=!0){let n="";for(let s=0;s<e.length;s++){const r=e[s];if(this.options.extensions&&this.options.extensions.renderers&&this.options.extensions.renderers[r.type]){const e=r,t=this.options.extensions.renderers[e.type].call({parser:this},e);if(!1!==t||!["space","hr","heading","code","table","blockquote","list","html","paragraph","text"].includes(e.type)){n+=t||"";continue}}switch(r.type){case"space":continue;case"hr":n+=this.renderer.hr();continue;case"heading":{const e=r;n+=this.renderer.heading(this.parseInline(e.tokens),e.depth,p(this.parseInline(e.tokens,this.textRenderer)));continue}case"code":{const e=r;n+=this.renderer.code(e.text,e.lang,!!e.escaped);continue}case"table":{const e=r;let t="",s="";for(let t=0;t<e.header.length;t++)s+=this.renderer.tablecell(this.parseInline(e.header[t].tokens),{header:!0,align:e.align[t]});t+=this.renderer.tablerow(s);let i="";for(let t=0;t<e.rows.length;t++){const n=e.rows[t];s="";for(let t=0;t<n.length;t++)s+=this.renderer.tablecell(this.parseInline(n[t].tokens),{header:!1,align:e.align[t]});i+=this.renderer.tablerow(s)}n+=this.renderer.table(t,i);continue}case"blockquote":{const e=r,t=this.parse(e.tokens);n+=this.renderer.blockquote(t);continue}case"list":{const e=r,t=e.ordered,s=e.start,i=e.loose;let l="";for(let t=0;t<e.items.length;t++){const n=e.items[t],s=n.checked,r=n.task;let o="";if(n.task){const e=this.renderer.checkbox(!!s);i?n.tokens.length>0&&"paragraph"===n.tokens[0].type?(n.tokens[0].text=e+" "+n.tokens[0].text,n.tokens[0].tokens&&n.tokens[0].tokens.length>0&&"text"===n.tokens[0].tokens[0].type&&(n.tokens[0].tokens[0].text=e+" "+n.tokens[0].tokens[0].text)):n.tokens.unshift({type:"text",text:e+" "}):o+=e+" "}o+=this.parse(n.tokens,i),l+=this.renderer.listitem(o,r,!!s)}n+=this.renderer.list(l,t,s);continue}case"html":{const e=r;n+=this.renderer.html(e.text,e.block);continue}case"paragraph":{const e=r;n+=this.renderer.paragraph(this.parseInline(e.tokens));continue}case"text":{let i=r,l=i.tokens?this.parseInline(i.tokens):i.text;for(;s+1<e.length&&"text"===e[s+1].type;)i=e[++s],l+="\n"+(i.tokens?this.parseInline(i.tokens):i.text);n+=t?this.renderer.paragraph(l):l;continue}default:{const e='Token with "'+r.type+'" type was not found.';if(this.options.silent)return console.error(e),"";throw new Error(e)}}}return n}parseInline(e,t){t=t||this.renderer;let n="";for(let s=0;s<e.length;s++){const r=e[s];if(this.options.extensions&&this.options.extensions.renderers&&this.options.extensions.renderers[r.type]){const e=this.options.extensions.renderers[r.type].call({parser:this},r);if(!1!==e||!["escape","html","link","image","strong","em","codespan","br","del","text"].includes(r.type)){n+=e||"";continue}}switch(r.type){case"escape":{const e=r;n+=t.text(e.text);break}case"html":{const e=r;n+=t.html(e.text);break}case"link":{const e=r;n+=t.link(e.href,e.title,this.parseInline(e.tokens,t));break}case"image":{const e=r;n+=t.image(e.href,e.title,e.text);break}case"strong":{const e=r;n+=t.strong(this.parseInline(e.tokens,t));break}case"em":{const e=r;n+=t.em(this.parseInline(e.tokens,t));break}case"codespan":{const e=r;n+=t.codespan(e.text);break}case"br":n+=t.br();break;case"del":{const e=r;n+=t.del(this.parseInline(e.tokens,t));break}case"text":{const e=r;n+=t.text(e.text);break}default:{const e='Token with "'+r.type+'" type was not found.';if(this.options.silent)return console.error(e),"";throw new Error(e)}}}return n}}class le{options;constructor(t){this.options=t||e.defaults}static passThroughHooks=new Set(["preprocess","postprocess","processAllTokens"]);preprocess(e){return e}postprocess(e){return e}processAllTokens(e){return e}}class oe{defaults={async:!1,breaks:!1,extensions:null,gfm:!0,hooks:null,pedantic:!1,renderer:null,silent:!1,tokenizer:null,walkTokens:null};options=this.setOptions;parse=this.#e(ne.lex,ie.parse);parseInline=this.#e(ne.lexInline,ie.parseInline);Parser=ie;Renderer=se;TextRenderer=re;Lexer=ne;Tokenizer=w;Hooks=le;constructor(...e){this.use(...e)}walkTokens(e,t){let n=[];for(const s of e)switch(n=n.concat(t.call(this,s)),s.type){case"table":{const e=s;for(const s of e.header)n=n.concat(this.walkTokens(s.tokens,t));for(const s of e.rows)for(const e of s)n=n.concat(this.walkTokens(e.tokens,t));break}case"list":{const e=s;n=n.concat(this.walkTokens(e.items,t));break}default:{const e=s;this.defaults.extensions?.childTokens?.[e.type]?this.defaults.extensions.childTokens[e.type].forEach((s=>{const r=e[s].flat(1/0);n=n.concat(this.walkTokens(r,t))})):e.tokens&&(n=n.concat(this.walkTokens(e.tokens,t)))}}return n}use(...e){const t=this.defaults.extensions||{renderers:{},childTokens:{}};return e.forEach((e=>{const n={...e};if(n.async=this.defaults.async||n.async||!1,e.extensions&&(e.extensions.forEach((e=>{if(!e.name)throw new Error("extension name required");if("renderer"in e){const n=t.renderers[e.name];t.renderers[e.name]=n?function(...t){let s=e.renderer.apply(this,t);return!1===s&&(s=n.apply(this,t)),s}:e.renderer}if("tokenizer"in e){if(!e.level||"block"!==e.level&&"inline"!==e.level)throw new Error("extension level must be 'block' or 'inline'");const n=t[e.level];n?n.unshift(e.tokenizer):t[e.level]=[e.tokenizer],e.start&&("block"===e.level?t.startBlock?t.startBlock.push(e.start):t.startBlock=[e.start]:"inline"===e.level&&(t.startInline?t.startInline.push(e.start):t.startInline=[e.start]))}"childTokens"in e&&e.childTokens&&(t.childTokens[e.name]=e.childTokens)})),n.extensions=t),e.renderer){const t=this.defaults.renderer||new se(this.defaults);for(const n in e.renderer){if(!(n in t))throw new Error(`renderer '${n}' does not exist`);if("options"===n)continue;const s=n,r=e.renderer[s],i=t[s];t[s]=(...e)=>{let n=r.apply(t,e);return!1===n&&(n=i.apply(t,e)),n||""}}n.renderer=t}if(e.tokenizer){const t=this.defaults.tokenizer||new w(this.defaults);for(const n in e.tokenizer){if(!(n in t))throw new Error(`tokenizer '${n}' does not exist`);if(["options","rules","lexer"].includes(n))continue;const s=n,r=e.tokenizer[s],i=t[s];t[s]=(...e)=>{let n=r.apply(t,e);return!1===n&&(n=i.apply(t,e)),n}}n.tokenizer=t}if(e.hooks){const t=this.defaults.hooks||new le;for(const n in e.hooks){if(!(n in t))throw new Error(`hook '${n}' does not exist`);if("options"===n)continue;const s=n,r=e.hooks[s],i=t[s];le.passThroughHooks.has(n)?t[s]=e=>{if(this.defaults.async)return Promise.resolve(r.call(t,e)).then((e=>i.call(t,e)));const n=r.call(t,e);return i.call(t,n)}:t[s]=(...e)=>{let n=r.apply(t,e);return!1===n&&(n=i.apply(t,e)),n}}n.hooks=t}if(e.walkTokens){const t=this.defaults.walkTokens,s=e.walkTokens;n.walkTokens=function(e){let n=[];return n.push(s.call(this,e)),t&&(n=n.concat(t.call(this,e))),n}}this.defaults={...this.defaults,...n}})),this}setOptions(e){return this.defaults={...this.defaults,...e},this}lexer(e,t){return ne.lex(e,t??this.defaults)}parser(e,t){return ie.parse(e,t??this.defaults)}#e(e,t){return(n,s)=>{const r={...s},i={...this.defaults,...r};!0===this.defaults.async&&!1===r.async&&(i.silent||console.warn("marked(): The async option was set to true by an extension. The async: false option sent to parse will be ignored."),i.async=!0);const l=this.#t(!!i.silent,!!i.async);if(null==n)return l(new Error("marked(): input parameter is undefined or null"));if("string"!=typeof n)return l(new Error("marked(): input parameter is of type "+Object.prototype.toString.call(n)+", string expected"));if(i.hooks&&(i.hooks.options=i),i.async)return Promise.resolve(i.hooks?i.hooks.preprocess(n):n).then((t=>e(t,i))).then((e=>i.hooks?i.hooks.processAllTokens(e):e)).then((e=>i.walkTokens?Promise.all(this.walkTokens(e,i.walkTokens)).then((()=>e)):e)).then((e=>t(e,i))).then((e=>i.hooks?i.hooks.postprocess(e):e)).catch(l);try{i.hooks&&(n=i.hooks.preprocess(n));let s=e(n,i);i.hooks&&(s=i.hooks.processAllTokens(s)),i.walkTokens&&this.walkTokens(s,i.walkTokens);let r=t(s,i);return i.hooks&&(r=i.hooks.postprocess(r)),r}catch(e){return l(e)}}}#t(e,t){return n=>{if(n.message+="\nPlease report this to https://github.com/markedjs/marked.",e){const e="<p>An error occurred:</p><pre>"+c(n.message+"",!0)+"</pre>";return t?Promise.resolve(e):e}if(t)return Promise.reject(n);throw n}}}const ae=new oe;function ce(e,t){return ae.parse(e,t)}ce.options=ce.setOptions=function(e){return ae.setOptions(e),ce.defaults=ae.defaults,n(ce.defaults),ce},ce.getDefaults=t,ce.defaults=e.defaults,ce.use=function(...e){return ae.use(...e),ce.defaults=ae.defaults,n(ce.defaults),ce},ce.walkTokens=function(e,t){return ae.walkTokens(e,t)},ce.parseInline=ae.parseInline,ce.Parser=ie,ce.parser=ie.parse,ce.Renderer=se,ce.TextRenderer=re,ce.Lexer=ne,ce.lexer=ne.lex,ce.Tokenizer=w,ce.Hooks=le,ce.parse=ce;const he=ce.options,pe=ce.setOptions,ue=ce.use,ke=ce.walkTokens,ge=ce.parseInline,fe=ce,de=ie.parse,xe=ne.lex;e.Hooks=le,e.Lexer=ne,e.Marked=oe,e.Parser=ie,e.Renderer=se,e.TextRenderer=re,e.Tokenizer=w,e.getDefaults=t,e.lexer=xe,e.marked=ce,e.options=he,e.parse=fe,e.parseInline=ge,e.parser=de,e.setOptions=pe,e.use=ue,e.walkTokens=ke}));