-
Notifications
You must be signed in to change notification settings - Fork 10
/
__init__.py
784 lines (624 loc) · 26.1 KB
/
__init__.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
import json
import os
import sys
from .mz_prompt_utils import Utils
from nodes import MAX_RESOLUTION
import comfy.utils
import shutil
import comfy.samplers
import folder_paths
WEB_DIRECTORY = "./web"
AUTHOR_NAME = u"MinusZone"
CATEGORY_NAME = f"{AUTHOR_NAME} - Prompt"
# sys.path.append(os.path.join(os.path.dirname(__file__)))
import importlib
from . import mz_prompt_webserver
# mz_prompt_webserver.start_server()
NODE_CLASS_MAPPINGS = {
}
NODE_DISPLAY_NAME_MAPPINGS = {
}
from . import mz_llama_cpp
def getCommonCLIPTextEncodeInput():
from . import mz_llama_core_nodes
style_presets = mz_llama_core_nodes.get_style_presets()
CommonCLIPTextEncodeInput = {
"required": {
"style_presets": (
style_presets, {"default": style_presets[1]}
),
"text": ("STRING", {"multiline": True, }),
"keep_device": ([False, True], {"default": False}),
"seed": ("INT", {"default": 0, "min": 0, "max": 0xffffffffffffffff}),
},
"optional": {
"clip": ("CLIP", ),
"llama_cpp_options": ("LLamaCPPOptions", ),
"customize_instruct": ("CustomizeInstruct", ),
}
}
return CommonCLIPTextEncodeInput
class MZ_OllamaModelConfig_ManualSelect:
@classmethod
def INPUT_TYPES(s):
search_dirs = [
os.path.join(os.path.expanduser('~'), ".ollama", "models"),
os.path.join(os.environ.get("APPDATA", ""), ".ollama", "models"),
]
ollama_models_dir = None
for dir in search_dirs:
if os.path.exists(dir):
ollama_models_dir = dir
break
ollamas = []
if ollama_models_dir is not None:
manifests_dir = os.path.join(ollama_models_dir, "manifests")
for root, dirs, files in os.walk(manifests_dir):
for file in files:
ollamas.append(os.path.join(root, file))
chat_format = mz_llama_cpp.get_llama_cpp_chat_handlers()
return {
"required": {
"ollama": (ollamas,),
"chat_format": (["auto"] + chat_format, {"default": "auto"}),
},
"optional": {
},
}
RETURN_TYPES = ("LLamaCPPModelConfig",)
RETURN_NAMES = ("llama_cpp_model_config",)
FUNCTION = "create"
CATEGORY = f"{CATEGORY_NAME}/others"
def create(self, **kwargs):
kwargs = kwargs.copy()
ollama = kwargs.get("ollama", "")
ollama_cpp_model = None
if os.path.exists(ollama):
# {"schemaVersion":2,"mediaType":"application/vnd.docker.distribution.manifest.v2+json","config":{"mediaType":"application/vnd.docker.container.image.v1+json","digest":"sha256:887433b89a901c156f7e6944442f3c9e57f3c55d6ed52042cbb7303aea994290","size":483},"layers":[{"mediaType":"application/vnd.ollama.image.model","digest":"sha256:c1864a5eb19305c40519da12cc543519e48a0697ecd30e15d5ac228644957d12","size":1678447520},{"mediaType":"application/vnd.ollama.image.license","digest":"sha256:097a36493f718248845233af1d3fefe7a303f864fae13bc31a3a9704229378ca","size":8433},{"mediaType":"application/vnd.ollama.image.template","digest":"sha256:109037bec39c0becc8221222ae23557559bc594290945a2c4221ab4f303b8871","size":136},{"mediaType":"application/vnd.ollama.image.params","digest":"sha256:22a838ceb7fb22755a3b0ae9b4eadde629d19be1f651f73efb8c6b4e2cd0eea0","size":84}]}
with open(ollama, "r", encoding="utf-8") as f:
data = json.load(f)
if "layers" in data:
for layer in data["layers"]:
if "mediaType" in layer and layer["mediaType"] == "application/vnd.ollama.image.model":
ollama_cpp_model = layer["digest"]
break
if ollama_cpp_model is None:
raise ValueError("Invalid ollama file")
if ollama_cpp_model.startswith("sha256:"):
ollama_cpp_model = ollama_cpp_model[7:]
# ollama = C:\Users\admin\.ollama\models\manifests\registry.ollama.ai\library\gemma\2b
models_dir = ollama[:ollama.rfind("manifests")]
ollama_cpp_model = os.path.join(
models_dir, "blobs", f"sha256-{ollama_cpp_model}")
if not os.path.exists(ollama_cpp_model):
raise ValueError(f"Model not found at: {ollama_cpp_model}")
llama_cpp_model = ollama_cpp_model
chat_format = kwargs.get("chat_format", "auto")
if chat_format == "auto":
chat_format = None
return ({
"type": "ManualSelect",
"model_path": llama_cpp_model,
"chat_format": chat_format,
},)
NODE_CLASS_MAPPINGS["MZ_OllamaModelConfig_ManualSelect"] = MZ_OllamaModelConfig_ManualSelect
NODE_DISPLAY_NAME_MAPPINGS[
"MZ_OllamaModelConfig_ManualSelect"] = f"{AUTHOR_NAME} - ModelConfigManualSelect(OllamaFile)"
class MZ_LLamaCPPModelConfig_ManualSelect:
@ classmethod
def INPUT_TYPES(s):
gguf_files = Utils.get_gguf_files()
chat_format = mz_llama_cpp.get_llama_cpp_chat_handlers()
return {
"required": {
"llama_cpp_model": (gguf_files,),
"chat_format": (["auto"] + chat_format, {"default": "auto"}),
},
"optional": {
},
}
RETURN_TYPES = ("LLamaCPPModelConfig",)
RETURN_NAMES = ("llama_cpp_model_config",)
FUNCTION = "create"
CATEGORY = f"{CATEGORY_NAME}/others"
def create(self, **kwargs):
kwargs = kwargs.copy()
llama_cpp_model = kwargs.get("llama_cpp_model", "")
if llama_cpp_model != "":
llama_cpp_model = os.path.join(
Utils.get_gguf_models_path(), llama_cpp_model)
chat_format = kwargs.get("chat_format", "auto")
if chat_format == "auto":
chat_format = None
return ({
"type": "ManualSelect",
"model_path": llama_cpp_model,
"chat_format": chat_format,
},)
NODE_CLASS_MAPPINGS["MZ_LLamaCPPModelConfig_ManualSelect"] = MZ_LLamaCPPModelConfig_ManualSelect
NODE_DISPLAY_NAME_MAPPINGS[
"MZ_LLamaCPPModelConfig_ManualSelect"] = f"{AUTHOR_NAME} - ModelConfigManualSelect(LLamaCPP)"
class MZ_LLamaCPPModelConfig_DownloaderSelect:
@classmethod
def INPUT_TYPES(s):
optional_models = Utils.get_model_zoo(tags_filter="llama")
model_names = [
model["model"] for model in optional_models
]
chat_format = mz_llama_cpp.get_llama_cpp_chat_handlers()
return {
"required": {
"model_name": (model_names,),
"chat_format": (["auto"] + chat_format, {"default": "auto"}),
},
"optional": {
},
}
RETURN_TYPES = ("LLamaCPPModelConfig",)
RETURN_NAMES = ("llama_cpp_model_config",)
FUNCTION = "create"
CATEGORY = f"{CATEGORY_NAME}/others"
def create(self, **kwargs):
kwargs = kwargs.copy()
model_name = kwargs.get("model_name", "")
chat_format = kwargs.get("chat_format", "auto")
if chat_format == "auto":
chat_format = None
return ({
"type": "DownloaderSelect",
"model_name": model_name,
"chat_format": chat_format,
},)
NODE_CLASS_MAPPINGS["MZ_LLamaCPPModelConfig_DownloaderSelect"] = MZ_LLamaCPPModelConfig_DownloaderSelect
NODE_DISPLAY_NAME_MAPPINGS[
"MZ_LLamaCPPModelConfig_DownloaderSelect"] = f"{AUTHOR_NAME} - ModelConfigDownloaderSelect(LLamaCPP)"
class MZ_LLamaCPPCLIPTextEncode:
@classmethod
def INPUT_TYPES(s):
importlib.reload(mz_llama_cpp)
result = {
"required": {
},
"optional": {
"llama_cpp_model": ("LLamaCPPModelConfig",),
},
}
common_input = getCommonCLIPTextEncodeInput()
for key in common_input["required"]:
result["required"][key] = common_input["required"][key]
for key in common_input["optional"]:
result["optional"][key] = common_input["optional"][key]
return result
RETURN_TYPES = ("STRING", "CONDITIONING",)
RETURN_NAMES = ("text", "conditioning",)
OUTPUT_NODE = True
FUNCTION = "encode"
CATEGORY = CATEGORY_NAME
DESCRIPTION = """
llama_cpp_model不设置时,将使用默认模型: Meta-Llama-3-8B-Instruct.Q4_K_M.gguf
"""
def encode(self, **kwargs):
kwargs = kwargs.copy()
from . import mz_llama_core_nodes
importlib.reload(mz_llama_core_nodes)
return mz_llama_core_nodes.llama_cpp_node_encode(kwargs)
NODE_CLASS_MAPPINGS["MZ_LLamaCPPCLIPTextEncode"] = MZ_LLamaCPPCLIPTextEncode
NODE_DISPLAY_NAME_MAPPINGS[
"MZ_LLamaCPPCLIPTextEncode"] = f"{AUTHOR_NAME} - CLIPTextEncode(LLamaCPP Universal)"
class MZ_LLamaCPPOptions:
@classmethod
def INPUT_TYPES(s):
value = mz_llama_cpp.LlamaCppOptions()
result = {}
for key in value:
if type(value[key]) == bool:
result[key] = ([True, False], {"default": value[key]})
elif type(value[key]) == int:
result[key] = ("INT", {
"default": value[key], "min": -0xffffffffffffffff, "max": 0xffffffffffffffff})
elif type(value[key]) == float:
result[key] = ("FLOAT", {
"default": value[key], "min": -0xffffffffffffffff, "max": 0xffffffffffffffff})
elif type(value[key]) == str:
result[key] = ("STRING", {"default": value[key]})
elif type(value[key]) == list:
result[key] = (value[key], {"default": value[key][0]})
else:
raise Exception(f"Unknown type: {type(value[key])}")
return {
"required": result,
}
RETURN_TYPES = ("LLamaCPPOptions",)
RETURN_NAMES = ("llama_cpp_options",)
FUNCTION = "create"
CATEGORY = f"{CATEGORY_NAME}/others"
def create(self, **kwargs):
kwargs = kwargs.copy()
importlib.reload(mz_llama_cpp)
opt = {}
for key in kwargs:
opt[key] = kwargs[key]
# if opt.get("chat_format", None) == "auto":
# opt["chat_format"] = None
return (opt,)
NODE_CLASS_MAPPINGS["MZ_LLamaCPPOptions"] = MZ_LLamaCPPOptions
NODE_DISPLAY_NAME_MAPPINGS["MZ_LLamaCPPOptions"] = f"{AUTHOR_NAME} - LLamaCPPOptions"
class MZ_CustomizeInstruct:
@classmethod
def INPUT_TYPES(s):
from . import mz_prompts
return {
"required": {
"system": ("STRING", {"multiline": True, "default": mz_prompts.Long_prompt}),
"instruct": ("STRING", {"multiline": True, "default": ""}),
},
}
RETURN_TYPES = ("CustomizeInstruct",)
RETURN_NAMES = ("customize_instruct",)
FUNCTION = "create"
CATEGORY = f"{CATEGORY_NAME}/others"
def create(self, **kwargs):
kwargs = kwargs.copy()
return (kwargs,)
NODE_CLASS_MAPPINGS["MZ_CustomizeInstruct"] = MZ_CustomizeInstruct
NODE_DISPLAY_NAME_MAPPINGS["MZ_CustomizeInstruct"] = f"{AUTHOR_NAME} - CustomizeInstruct"
class MZ_ImageCaptionerConfig:
@classmethod
def INPUT_TYPES(s):
return {
"required": {
"directory": ("STRING", {"default": "", "placeholder": "directory"}),
"caption_suffix": ("STRING", {"default": ".caption"}),
"force_update": ([False, True], {"default": False}),
"retry_keyword": ("STRING", {"default": "not,\",error"}),
"prompt_fixed_beginning": ("STRING", {"default": "", }),
},
"optional": {
},
}
RETURN_TYPES = ("ImageCaptionerConfig",)
RETURN_NAMES = ("captioner_config", )
FUNCTION = "interrogate_batch"
CATEGORY = f"{CATEGORY_NAME}/others"
def interrogate_batch(self, **kwargs):
kwargs = kwargs.copy()
return (kwargs, )
NODE_CLASS_MAPPINGS["MZ_ImageCaptionerConfig"] = MZ_ImageCaptionerConfig
NODE_DISPLAY_NAME_MAPPINGS["MZ_ImageCaptionerConfig"] = f"{AUTHOR_NAME} - ImageCaptionerConfig"
class MZ_OpenAIApiCLIPTextEncode:
@classmethod
def INPUT_TYPES(s):
importlib.reload(mz_llama_cpp)
s.openai_config_path = os.path.join(
Utils.get_models_path(),
"openai_config.json",
)
default_config = {
"base_url": "",
"api_key": "",
"model_name": "gpt-3.5-turbo-1106",
}
if os.path.exists(s.openai_config_path):
try:
with open(s.openai_config_path, "r", encoding="utf-8") as f:
default_config = json.load(f)
except Exception as e:
print(f"Failed to load openai_config.json: {e}")
default_api_key = default_config.get("api_key", "")
if default_api_key != "":
default_api_key = default_api_key[:4] + "******"
result = {
"required": {
"base_url": ("STRING", {"default": default_config.get("base_url", ""), "placeholder": ""}),
"api_key": ("STRING", {"default": default_api_key, "placeholder": ""}),
"model_name": ("STRING", {"default": default_config.get("model_name", ""), }),
},
"optional": {
},
}
common_input = getCommonCLIPTextEncodeInput()
for key in common_input["required"]:
if key not in ["seed", "keep_device"]:
result["required"][key] = common_input["required"][key]
for key in common_input["optional"]:
if key != "llama_cpp_options":
result["optional"][key] = common_input["optional"][key]
return result
RETURN_TYPES = ("STRING", "CONDITIONING",)
RETURN_NAMES = ("text", "conditioning",)
OUTPUT_NODE = True
FUNCTION = "encode"
CATEGORY = CATEGORY_NAME
def encode(self, **kwargs):
kwargs = kwargs.copy()
from . import mz_openaiapi
importlib.reload(mz_openaiapi)
if kwargs.get("api_key", "").endswith("******"):
kwargs["api_key"] = ""
try:
with open(self.openai_config_path, "r", encoding="utf-8") as f:
config = json.load(f)
kwargs["api_key"] = config.get("api_key", "")
except Exception as e:
print(f"Failed to load openai_config.json: {e}")
if kwargs.get("api_key", "") != "":
with open(self.openai_config_path, "w", encoding="utf-8") as f:
json.dump({
"base_url": kwargs.get("base_url", ""),
"api_key": kwargs.get("api_key", ""),
"model_name": kwargs.get("model_name", ""),
}, f, indent=4)
else:
raise ValueError("api_key is required")
text = mz_openaiapi.query_beautify_prompt_text(kwargs)
conditionings = None
clip = kwargs.get("clip", None)
if clip is not None:
conditionings = Utils.a1111_clip_text_encode(clip, text, )
return {"ui": {"string": [Utils.to_debug_prompt(text),]}, "result": (text, conditionings)}
NODE_CLASS_MAPPINGS["MZ_OpenAIApiCLIPTextEncode"] = MZ_OpenAIApiCLIPTextEncode
NODE_DISPLAY_NAME_MAPPINGS[
"MZ_OpenAIApiCLIPTextEncode"] = f"{AUTHOR_NAME} - CLIPTextEncode(OpenAIApi)"
class MZ_ImageInterrogatorCLIPTextEncode:
@classmethod
def INPUT_TYPES(s):
return {
"required": {
"resolution": ("INT", {"default": 512, "min": 128, "max": 0xffffffffffffffff}),
"post_processing": ([False, True], {"default": True}),
"keep_device": ([False, True], {"default": False}),
"seed": ("INT", {"default": 0, "min": 0, "max": 0xffffffffffffffff}),
},
"optional": {
"image_interrogator_model": ("ImageInterrogatorModelConfig", ),
"image": ("IMAGE",),
"clip": ("CLIP", ),
"llama_cpp_options": ("LLamaCPPOptions", ),
"customize_instruct": ("CustomizeInstruct", ),
"captioner_config": ("ImageCaptionerConfig", ),
},
}
RETURN_TYPES = ("STRING", "CONDITIONING",)
RETURN_NAMES = ("text", "conditioning",)
OUTPUT_NODE = True
FUNCTION = "encode"
CATEGORY = CATEGORY_NAME
def encode(self, **kwargs):
kwargs = kwargs.copy()
from . import mz_llama_core_nodes
importlib.reload(mz_llama_core_nodes)
return mz_llama_core_nodes.image_interrogator_node_encode(kwargs)
NODE_CLASS_MAPPINGS["MZ_ImageInterrogatorCLIPTextEncode"] = MZ_ImageInterrogatorCLIPTextEncode
NODE_DISPLAY_NAME_MAPPINGS[
"MZ_ImageInterrogatorCLIPTextEncode"] = f"{AUTHOR_NAME} - CLIPTextEncode(ImageInterrogator)"
class MZ_ImageInterrogatorModelConfig_ManualSelect:
@classmethod
def INPUT_TYPES(s):
gguf_files = Utils.get_gguf_files()
chat_format = mz_llama_cpp.get_llama_cpp_chat_handlers()
return {
"required": {
"llama_cpp_model": (gguf_files,),
"mmproj_model": (["auto"] + gguf_files,),
"chat_format": (["auto"] + chat_format, {"default": "auto"}),
},
"optional": {
},
}
RETURN_TYPES = ("ImageInterrogatorModelConfig",)
RETURN_NAMES = ("image_interrogator_model",)
FUNCTION = "create"
CATEGORY = f"{CATEGORY_NAME}/others"
def create(self, **kwargs):
kwargs = kwargs.copy()
llama_cpp_model = kwargs.get("llama_cpp_model", "")
if llama_cpp_model != "":
llama_cpp_model = os.path.join(
Utils.get_gguf_models_path(), llama_cpp_model)
mmproj_model = kwargs.get("mmproj_model", "")
if mmproj_model != "":
mmproj_model = os.path.join(
Utils.get_gguf_models_path(), mmproj_model)
chat_format = kwargs.get("chat_format", "auto")
if chat_format == "auto":
chat_format = None
return ({
"type": "ManualSelect",
"model_path": llama_cpp_model,
"mmproj_model": mmproj_model,
"chat_format": chat_format,
},)
NODE_CLASS_MAPPINGS["MZ_ImageInterrogatorModelConfig_ManualSelect"] = MZ_ImageInterrogatorModelConfig_ManualSelect
NODE_DISPLAY_NAME_MAPPINGS[
"MZ_ImageInterrogatorModelConfig_ManualSelect"] = f"{AUTHOR_NAME} - ModelConfigManualSelect(ImageInterrogator)"
class MZ_ImageInterrogatorModelConfig_DownloaderSelect:
@classmethod
def INPUT_TYPES(s):
optional_models = Utils.get_model_zoo(tags_filter="llava")
model_names = [
model["model"] for model in optional_models
]
optional_models = Utils.get_model_zoo(tags_filter="mmproj")
mmproj_model_names = [
model["model"] for model in optional_models
]
chat_format = mz_llama_cpp.get_llama_cpp_chat_handlers()
return {
"required": {
"model_name": (model_names,),
"mmproj_model_name": (["auto"] + mmproj_model_names,),
"chat_format": (["auto"] + chat_format, {"default": "auto"}),
},
"optional": {
},
}
RETURN_TYPES = ("ImageInterrogatorModelConfig",)
RETURN_NAMES = ("image_interrogator_model",)
FUNCTION = "create"
CATEGORY = f"{CATEGORY_NAME}/others"
def create(self, **kwargs):
kwargs = kwargs.copy()
model_name = kwargs.get("model_name")
mmproj_model_name = kwargs.get("mmproj_model_name", "auto")
chat_format = kwargs.get("chat_format", "auto")
if chat_format == "auto":
chat_format = None
return ({
"type": "DownloaderSelect",
"model_name": model_name,
"mmproj_model_name": mmproj_model_name,
"chat_format": chat_format,
},)
NODE_CLASS_MAPPINGS["MZ_ImageInterrogatorModelConfig_DownloaderSelect"] = MZ_ImageInterrogatorModelConfig_DownloaderSelect
NODE_DISPLAY_NAME_MAPPINGS[
"MZ_ImageInterrogatorModelConfig_DownloaderSelect"] = f"{AUTHOR_NAME} - ModelConfigDownloaderSelect(ImageInterrogator)"
class MZ_Florence2CLIPTextEncode:
@classmethod
def INPUT_TYPES(s):
return {
"required": {
"model_name": ([
"Florence-2-large-ft",
"Florence-2-large",
],),
"resolution": ("INT", {"default": 512, "min": 128, "max": 0xffffffffffffffff}),
"keep_device": ([False, True], {"default": False}),
# "seed": ("INT", {"default": 0, "min": 0, "max": 0xffffffffffffffff}),
},
"optional": {
"image": ("IMAGE",),
"clip": ("CLIP", ),
},
}
RETURN_TYPES = ("STRING", "CONDITIONING",)
RETURN_NAMES = ("text", "conditioning",)
OUTPUT_NODE = True
FUNCTION = "encode"
CATEGORY = CATEGORY_NAME
def encode(self, **kwargs):
kwargs = kwargs.copy()
from . import mz_transformers
importlib.reload(mz_transformers)
return mz_transformers.florence2_node_encode(kwargs)
NODE_CLASS_MAPPINGS["MZ_Florence2CLIPTextEncode"] = MZ_Florence2CLIPTextEncode
NODE_DISPLAY_NAME_MAPPINGS[
"MZ_Florence2CLIPTextEncode"] = f"{AUTHOR_NAME} - CLIPTextEncode(Florence-2)"
class MZ_Florence2Captioner:
@classmethod
def INPUT_TYPES(s):
return {
"required": {
"model_name": ([
"Florence-2-large-ft",
"Florence-2-large",
],),
"directory": ("STRING", {"default": "", "placeholder": "directory"}),
"resolution": ("INT", {"default": 512, "min": 128, "max": 0xffffffffffffffff}),
"batch_size": ("INT", {"default": 1, "min": 1, "max": 0xffffffffffffffff}),
"caption_suffix": ("STRING", {"default": ".caption"}),
"force_update": ([False, True], {"default": False}),
"prompt_fixed_beginning": ("STRING", {"default": "", }),
},
"optional": {
},
}
RETURN_TYPES = ("STRING",)
RETURN_NAMES = ("debug",)
OUTPUT_NODE = True
FUNCTION = "encode"
CATEGORY = CATEGORY_NAME
def encode(self, **kwargs):
kwargs = kwargs.copy()
from . import mz_transformers
importlib.reload(mz_transformers)
kwargs["captioner_config"] = {
"directory": kwargs["directory"],
"resolution": kwargs["resolution"],
"batch_size": kwargs["batch_size"],
"caption_suffix": kwargs["caption_suffix"],
"force_update": kwargs["force_update"],
"prompt_fixed_beginning": kwargs["prompt_fixed_beginning"],
}
return mz_transformers.florence2_node_encode(kwargs)
NODE_CLASS_MAPPINGS["MZ_Florence2Captioner"] = MZ_Florence2Captioner
NODE_DISPLAY_NAME_MAPPINGS[
"MZ_Florence2Captioner"] = f"{AUTHOR_NAME} - Captioner(Florence-2)"
class MZ_PaliGemmaCLIPTextEncode:
@classmethod
def INPUT_TYPES(s):
return {
"required": {
"model_name": ([
"paligemma-sd3-long-captioner-v2",
"paligemma-sd3-long-captioner",
],),
"resolution": ("INT", {"default": 512, "min": 128, "max": 0xffffffffffffffff}),
"keep_device": ([False, True], {"default": False}),
# "seed": ("INT", {"default": 0, "min": 0, "max": 0xffffffffffffffff}),
},
"optional": {
"image": ("IMAGE",),
"clip": ("CLIP", ),
},
}
RETURN_TYPES = ("STRING", "CONDITIONING",)
RETURN_NAMES = ("text", "conditioning",)
OUTPUT_NODE = True
FUNCTION = "encode"
CATEGORY = CATEGORY_NAME
def encode(self, **kwargs):
kwargs = kwargs.copy()
from . import mz_transformers
importlib.reload(mz_transformers)
return mz_transformers.paligemma_node_encode(kwargs)
NODE_CLASS_MAPPINGS["MZ_PaliGemmaCLIPTextEncode"] = MZ_PaliGemmaCLIPTextEncode
NODE_DISPLAY_NAME_MAPPINGS[
"MZ_PaliGemmaCLIPTextEncode"] = f"{AUTHOR_NAME} - CLIPTextEncode(PaliGemma)"
class MZ_PaliGemmaCaptioner:
@classmethod
def INPUT_TYPES(s):
return {
"required": {
"model_name": ([
"paligemma-sd3-long-captioner-v2",
"paligemma-sd3-long-captioner",
],),
"directory": ("STRING", {"default": "", "placeholder": "directory"}),
"resolution": ("INT", {"default": 512, "min": 128, "max": 0xffffffffffffffff}),
"caption_suffix": ("STRING", {"default": ".caption"}),
"force_update": ([False, True], {"default": False}),
"prompt_fixed_beginning": ("STRING", {"default": "", }),
},
"optional": {
},
}
RETURN_TYPES = ("STRING",)
RETURN_NAMES = ("debug",)
OUTPUT_NODE = True
FUNCTION = "encode"
CATEGORY = CATEGORY_NAME
def encode(self, **kwargs):
kwargs = kwargs.copy()
from . import mz_transformers
importlib.reload(mz_transformers)
kwargs["captioner_config"] = {
"directory": kwargs["directory"],
"resolution": kwargs["resolution"],
"caption_suffix": kwargs["caption_suffix"],
"force_update": kwargs["force_update"],
"prompt_fixed_beginning": kwargs["prompt_fixed_beginning"],
}
return mz_transformers.paligemma_node_encode(kwargs)
NODE_CLASS_MAPPINGS["MZ_PaliGemmaCaptioner"] = MZ_PaliGemmaCaptioner
NODE_DISPLAY_NAME_MAPPINGS[
"MZ_PaliGemmaCaptioner"] = f"{AUTHOR_NAME} - Captioner(PaliGemma)"
try:
from . import mz_gen_translate
mz_gen_translate.gen_translate(
NODE_DISPLAY_NAME_MAPPINGS, NODE_CLASS_MAPPINGS)
except Exception as e:
print(f"Failed to generate translation: {e}")
from .v1.init import NODE_CLASS_MAPPINGS as DEPRECATED_NODE_CLASS_MAPPINGS
from .v1.init import NODE_DISPLAY_NAME_MAPPINGS as DEPRECATED_NODE_DISPLAY_NAME_MAPPINGS
NODE_CLASS_MAPPINGS.update(DEPRECATED_NODE_CLASS_MAPPINGS)
NODE_DISPLAY_NAME_MAPPINGS.update(DEPRECATED_NODE_DISPLAY_NAME_MAPPINGS)