-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathjps_nodes.py
3563 lines (2822 loc) · 144 KB
/
jps_nodes.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
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
"""
@author: JPS
@title: JPS Custom Nodes for ComfyUI
@nickname: JPS Custom Nodes
@description: Various nodes to handle SDXL Resolutions, SDXL Basic Settings, IP Adapter Settings, Revision Settings, SDXL Prompt Styler, Crop Image to Square, Crop Image to Target Size, Get Date-Time String, Resolution Multiply, Largest Integer, 5-to-1 Switches for Integer, Images, Latents, Conditioning, Model, VAE, ControlNet
"""
#------------------------------------------------------------------------#
# JPS Custom Nodes https://github.com/JPS-GER/ComfyUI_JPS-Nodes #
# for ComfyUI https://github.com/comfyanonymous/ComfyUI #
#------------------------------------------------------------------------#
import torch
import json
import os
import comfy.sd
import folder_paths
from datetime import datetime
from PIL import Image, ImageOps, ImageSequence
import numpy as np
from PIL.PngImagePlugin import PngInfo
from comfy.cli_args import args
import torch.nn.functional as F
def min_(tensor_list):
# return the element-wise min of the tensor list.
x = torch.stack(tensor_list)
mn = x.min(axis=0)[0]
return torch.clamp(mn, min=0)
def max_(tensor_list):
# return the element-wise max of the tensor list.
x = torch.stack(tensor_list)
mx = x.max(axis=0)[0]
return torch.clamp(mx, max=1)
# From https://github.com/Jamy-L/Pytorch-Contrast-Adaptive-Sharpening/
def contrast_adaptive_sharpening(image, amount):
img = F.pad(image, pad=(1, 1, 1, 1)).cpu()
a = img[..., :-2, :-2]
b = img[..., :-2, 1:-1]
c = img[..., :-2, 2:]
d = img[..., 1:-1, :-2]
e = img[..., 1:-1, 1:-1]
f = img[..., 1:-1, 2:]
g = img[..., 2:, :-2]
h = img[..., 2:, 1:-1]
i = img[..., 2:, 2:]
# Computing contrast
cross = (b, d, e, f, h)
mn = min_(cross)
mx = max_(cross)
diag = (a, c, g, i)
mn2 = min_(diag)
mx2 = max_(diag)
mx = mx + mx2
mn = mn + mn2
# Computing local weight
inv_mx = torch.reciprocal(mx)
amp = inv_mx * torch.minimum(mn, (2 - mx))
# scaling
amp = torch.sqrt(amp)
w = - amp * (amount * (1/5 - 1/8) + 1/8)
div = torch.reciprocal(1 + 4*w)
output = ((b + d + f + h)*w + e) * div
output = output.clamp(0, 1)
output = torch.nan_to_num(output)
return (output)
def read_json_file(file_path):
"""
Reads a JSON file's content and returns it.
Ensures content matches the expected format.
"""
if not os.access(file_path, os.R_OK):
print(f"Warning: No read permissions for file {file_path}")
return None
try:
with open(file_path, 'r', encoding='utf-8') as file:
content = json.load(file)
# Check if the content matches the expected format.
if not all(['name' in item and 'prompt' in item and 'negative_prompt' in item for item in content]):
print(f"Warning: Invalid content in file {file_path}")
return None
return content
except Exception as e:
print(f"An error occurred while reading {file_path}: {str(e)}")
return None
def read_sdxl_styles(json_data):
"""
Returns style names from the provided JSON data.
"""
if not isinstance(json_data, list):
print("Error: input data must be a list")
return []
return [item['name'] for item in json_data if isinstance(item, dict) and 'name' in item]
def get_all_json_files(directory):
"""
Returns all JSON files from the specified directory.
"""
return [os.path.join(directory, file) for file in os.listdir(directory) if file.endswith('.json') and os.path.isfile(os.path.join(directory, file))]
def load_styles_from_directory(directory):
"""
Loads styles from all JSON files in the directory.
Renames duplicate style names by appending a suffix.
"""
json_files = get_all_json_files(directory)
combined_data = []
seen = set()
for json_file in json_files:
json_data = read_json_file(json_file)
if json_data:
for item in json_data:
original_style = item['name']
style = original_style
suffix = 1
while style in seen:
style = f"{original_style}_{suffix}"
suffix += 1
item['name'] = style
seen.add(style)
combined_data.append(item)
unique_style_names = [item['name'] for item in combined_data if isinstance(item, dict) and 'name' in item]
return combined_data, unique_style_names
def validate_json_data(json_data):
"""
Validates the structure of the JSON data.
"""
if not isinstance(json_data, list):
return False
for template in json_data:
if 'name' not in template or 'prompt' not in template:
return False
return True
def find_template_by_name(json_data, template_name):
"""
Returns a template from the JSON data by name or None if not found.
"""
for template in json_data:
if template['name'] == template_name:
return template
return None
def split_template(template: str) -> tuple:
"""
Splits a template into two parts based on a specific pattern.
"""
if "{prompt} ." in template:
template_prompt_g, template_prompt_l = template.split("{prompt} .", 1)
template_prompt_g = template_prompt_g.strip() + " {prompt}"
template_prompt_l = template_prompt_l.strip()
else:
template_prompt_g = template
template_prompt_l = ""
return template_prompt_g, template_prompt_l
def replace_prompts_in_template(template, positive_prompt_g, positive_prompt_l, negative_prompt):
"""
Replace the placeholders in a given template with the provided prompts and split them accordingly.
Args:
- template (dict): The template containing prompt placeholders.
- positive_prompt_g (str): The main positive prompt to replace '{prompt}' in the template.
- positive_prompt_l (str): The auxiliary positive prompt to be combined in a specific manner.
- negative_prompt (str): The negative prompt to be combined with any existing negative prompt in the template.
Returns:
- tuple: A tuple containing the replaced main positive, auxiliary positive, combined positive and negative prompts.
"""
template_prompt_g, template_prompt_l_template = split_template(template['prompt'])
text_g_positive = template_prompt_g.replace("{prompt}", positive_prompt_g)
text_l_positive = f"{template_prompt_l_template}, {positive_prompt_l}" if template_prompt_l_template and positive_prompt_l else template_prompt_l_template or positive_prompt_l
json_negative_prompt = template.get('negative_prompt', "")
text_negative = f"{json_negative_prompt}, {negative_prompt}" if json_negative_prompt and negative_prompt else json_negative_prompt or negative_prompt
return text_g_positive, text_l_positive, text_negative
def read_sdxl_templates_replace_and_combine(json_data, template_name, positive_prompt_g, positive_prompt_l, negative_prompt):
"""
Find a specific template by its name, then replace and combine its placeholders with the provided prompts in an advanced manner.
Args:
- json_data (list): The list of templates.
- template_name (str): The name of the desired template.
- positive_prompt_g (str): The main positive prompt.
- positive_prompt_l (str): The auxiliary positive prompt.
- negative_prompt (str): The negative prompt to be combined.
Returns:
- tuple: A tuple containing the replaced and combined main positive, auxiliary positive, combined positive and negative prompts.
"""
if not validate_json_data(json_data):
return positive_prompt_g, positive_prompt_l, negative_prompt
template = find_template_by_name(json_data, template_name)
if template:
return replace_prompts_in_template(template, positive_prompt_g, positive_prompt_l, negative_prompt)
else:
return positive_prompt_g, positive_prompt_l, negative_prompt
accepted_ratios_horizontal = {
"7:4": (1344, 768, 1.750000000),
"9:7": (1152, 896, 1.285714286),
"19:13": (1216, 832, 1.461538462),
"1:2": (704, 1408, 0.500000000),
"3:1": (1728, 576, 3.000000000),
"4:1": (2048, 512, 4.000000000),
"4:3": (1152, 864, 1.333333333),
"3:2": (1248, 832, 1.500000000),
"5:2": (1600, 640, 2.500000000),
"5:3": (1280, 768, 1.666666667),
"16:9": (1344, 768, 1.750000000),
"19:7": (1664, 576, 2.888888889),
"12:5": (1536, 640, 2.400000000),
"26:7": (1920, 512, 3.750000000),
"32:9": (1792, 512, 3.500000000),
}
accepted_ratios_vertical = {
"4:7": (768, 1344, 0.571428571),
"7:9": (896, 1152, 0.777777778),
"13:19": (832, 1216, 0.684210526),
"2:1": (1408, 704, 2.000000000),
"1:3": (576, 1728, 0.333333333),
"1:4": (512, 2048, 0.250000000),
"3:4": (864, 1152, 0.750000000),
"2:3": (832, 1248, 0.666666667),
"2:5": (640, 1600, 0.400000000),
"3:5": (768, 1280, 0.600000000),
"9:16": (768, 1344, 0.571428571),
"7:19": (576, 1664, 0.346153846),
"5:12": (640, 1536, 0.416666667),
"7:26": (512, 1920, 0.266666667),
"9:32": (576, 1792, 0.321428571),
}
# Square aspect ratio
accepted_ratios_square = {
"1:1": (1024, 1024, 1.00000000)
}
class SDXL_Resolutions:
resolution = ["square - 1024x1024 (1:1)","landscape - 1152x896 (4:3)","landscape - 1216x832 (3:2)","landscape - 1344x768 (16:9)","landscape - 1536x640 (21:9)", "portrait - 896x1152 (3:4)","portrait - 832x1216 (2:3)","portrait - 768x1344 (9:16)","portrait - 640x1536 (9:21)"]
def __init__(self):
pass
@classmethod
def INPUT_TYPES(s):
return {
"required": {
"resolution": (s.resolution,),
}
}
RETURN_TYPES = ("INT","INT",)
RETURN_NAMES = ("width", "height")
FUNCTION = "get_resolutions"
CATEGORY="JPS Nodes/Settings"
def get_resolutions(self,resolution):
width = 1024
height = 1024
width = int(width)
height = int(height)
if(resolution == "square - 1024x1024 (1:1)"):
width = 1024
height = 1024
if(resolution == "landscape - 1152x896 (4:3)"):
width = 1152
height = 896
if(resolution == "landscape - 1216x832 (3:2)"):
width = 1216
height = 832
if(resolution == "landscape - 1344x768 (16:9)"):
width = 1344
height = 768
if(resolution == "landscape - 1536x640 (21:9)"):
width = 1536
height = 640
if(resolution == "portrait - 896x1152 (3:4)"):
width = 896
height = 1152
if(resolution == "portrait - 832x1216 (2:3)"):
width = 832
height = 1216
if(resolution == "portrait - 768x1344 (9:16)"):
width = 768
height = 1344
if(resolution == "portrait - 640x1536 (9:21)"):
width = 640
height = 1536
return(int(width),int(height))
#---------------------------------------------------------------------------------------------------------------------------------------------------#
class SDXL_Basic_Settings:
resolution = ["Use Image Resolution", "square - 1024x1024 (1:1)","landscape - 1152x896 (4:3)","landscape - 1216x832 (3:2)","landscape - 1344x768 (16:9)","landscape - 1536x640 (21:9)", "portrait - 896x1152 (3:4)","portrait - 832x1216 (2:3)","portrait - 768x1344 (9:16)","portrait - 640x1536 (9:21)"]
def __init__(self):
pass
@classmethod
def INPUT_TYPES(s):
return {
"required": {
"resolution": (s.resolution,),
"sampler_name": (comfy.samplers.KSampler.SAMPLERS,),
"scheduler": (comfy.samplers.KSampler.SCHEDULERS,),
"steps_total": ("INT", {"default": 60, "min": 20, "max": 250, "step": 5}),
"base_percentage": ("INT", {"default": 80, "min": 5, "max": 100, "step": 5}),
"cfg": ("FLOAT", {"default": 6.5, "min": 1, "max": 20, "step": 0.1}),
"cfg_rescale": ("FLOAT", {"default": 0.00, "min": 0.00, "max": 1.00, "step": 0.05}),
"cfg_refiner": ("FLOAT", {"default": 6.5, "min": 0, "max": 20, "step": 0.1}),
"ascore_refiner": ("FLOAT", {"default": 6, "min": 1, "max": 10, "step": 0.5}),
"res_factor": ("INT", {"default": 4, "min": 1, "max": 8, "step": 1}),
"clip_skip": ("INT", {"default": -2, "min": -24, "max": -1}),
"filename": ("STRING", {"default": "JPS"}),
}}
RETURN_TYPES = ("BASIC_PIPE",)
RETURN_NAMES = ("sdxl_basic_settings",)
FUNCTION = "get_values"
CATEGORY="JPS Nodes/Settings"
def get_values(self,resolution,sampler_name,scheduler,steps_total,base_percentage,cfg,cfg_rescale,cfg_refiner,ascore_refiner,res_factor,clip_skip,filename):
width = 1024
height = 1024
width = int(width)
height = int(height)
steps_total = int(steps_total)
step_split = steps_total * base_percentage / 100
cfg = float(cfg)
cfg_rescale = float(cfg_rescale)
cfg_refiner = float (cfg_refiner)
ascore_refiner = float (ascore_refiner)
res_factor = int (res_factor)
base_percentage = int (base_percentage)
image_res = 1
if(resolution == "Use Image Resolution"):
image_res = 2
if(resolution == "square - 1024x1024 (1:1)"):
width = 1024
height = 1024
if(resolution == "landscape - 1152x896 (4:3)"):
width = 1152
height = 896
if(resolution == "landscape - 1216x832 (3:2)"):
width = 1216
height = 832
if(resolution == "landscape - 1344x768 (16:9)"):
width = 1344
height = 768
if(resolution == "landscape - 1536x640 (21:9)"):
width = 1536
height = 640
if(resolution == "portrait - 896x1152 (3:4)"):
width = 896
height = 1152
if(resolution == "portrait - 832x1216 (2:3)"):
width = 832
height = 1216
if(resolution == "portrait - 768x1344 (9:16)"):
width = 768
height = 1344
if(resolution == "portrait - 640x1536 (9:21)"):
width = 640
height = 1536
if(cfg_refiner == 0):
cfg_refiner = cfg
sdxl_basic_settings = width, height, sampler_name, scheduler, steps_total, step_split, cfg, cfg_rescale, cfg_refiner, ascore_refiner, res_factor, clip_skip, filename,image_res
return(sdxl_basic_settings,)
#---------------------------------------------------------------------------------------------------------------------------------------------------#
class SDXL_Basic_Settings_Pipe:
resolution = ["square - 1024x1024 (1:1)","landscape - 1152x896 (4:3)","landscape - 1216x832 (3:2)","landscape - 1344x768 (16:9)","landscape - 1536x640 (21:9)", "portrait - 896x1152 (3:4)","portrait - 832x1216 (2:3)","portrait - 768x1344 (9:16)","portrait - 640x1536 (9:21)"]
def __init__(self):
pass
@classmethod
def INPUT_TYPES(s):
return {
"required": {
"sdxl_basic_settings": ("BASIC_PIPE",)
},
}
RETURN_TYPES = ("INT","INT","INT",comfy.samplers.KSampler.SAMPLERS,comfy.samplers.KSampler.SCHEDULERS,"INT","INT","FLOAT","FLOAT","FLOAT","FLOAT","INT","INT","STRING",)
RETURN_NAMES = ("image_res","width","height","sampler_name","scheduler","steps_total","step_split","cfg","cfg_rescale","cfg_refiner","ascore_refiner","res_factor","clip_skip","filename",)
FUNCTION = "give_values"
CATEGORY="JPS Nodes/Pipes"
def give_values(self,sdxl_basic_settings):
width, height, sampler_name, scheduler, steps_total, step_split, cfg, cfg_rescale, cfg_refiner, ascore_refiner, res_factor, clip_skip, filename,image_res = sdxl_basic_settings
return(int(image_res), int(width), int(height), sampler_name, scheduler, int(steps_total), int(step_split), float(cfg), float(cfg_rescale), float(cfg_refiner), float(ascore_refiner), int (res_factor), int(clip_skip), str(filename),)
#---------------------------------------------------------------------------------------------------------------------------------------------------#
class SDXL_Settings:
resolution = ["Use Image Resolution", "square - 1024x1024 (1:1)","landscape - 1152x896 (4:3)","landscape - 1216x832 (3:2)","landscape - 1344x768 (16:9)","landscape - 1536x640 (21:9)", "portrait - 896x1152 (3:4)","portrait - 832x1216 (2:3)","portrait - 768x1344 (9:16)","portrait - 640x1536 (9:21)"]
def __init__(self):
pass
@classmethod
def INPUT_TYPES(s):
return {
"required": {
"resolution": (s.resolution,),
"res_factor": ("INT", {"default": 4, "min": 1, "max": 8, "step": 1}),
"sampler_name": (comfy.samplers.KSampler.SAMPLERS,),
"scheduler": (comfy.samplers.KSampler.SCHEDULERS,),
"steps": ("INT", {"default": 60, "min": 20, "max": 250, "step": 5}),
"cfg": ("FLOAT", {"default": 6.5, "min": 1, "max": 20, "step": 0.1}),
"cfg_rescale": ("FLOAT", {"default": 0.00, "min": 0.00, "max": 1.00, "step": 0.05}),
"clip_skip": ("INT", {"default": -2, "min": -24, "max": -1}),
"filename": ("STRING", {"default": "JPS"}),
}}
RETURN_TYPES = ("BASIC_PIPE",)
RETURN_NAMES = ("sdxl_settings",)
FUNCTION = "get_values"
CATEGORY="JPS Nodes/Settings"
def get_values(self,resolution,res_factor,sampler_name,scheduler,steps,cfg,cfg_rescale,clip_skip,filename):
image_res = 1
if(resolution == "Use Image Resolution"):
image_res = 2
width = 1024
height = 1024
if(resolution == "landscape - 1152x896 (4:3)"):
width = 1152
height = 896
if(resolution == "landscape - 1216x832 (3:2)"):
width = 1216
height = 832
if(resolution == "landscape - 1344x768 (16:9)"):
width = 1344
height = 768
if(resolution == "landscape - 1536x640 (21:9)"):
width = 1536
height = 640
if(resolution == "portrait - 896x1152 (3:4)"):
width = 896
height = 1152
if(resolution == "portrait - 832x1216 (2:3)"):
width = 832
height = 1216
if(resolution == "portrait - 768x1344 (9:16)"):
width = 768
height = 1344
if(resolution == "portrait - 640x1536 (9:21)"):
width = 640
height = 1536
sdxl_settings = width, height, res_factor, sampler_name, scheduler, steps, cfg, cfg_rescale, clip_skip, filename,image_res
return(sdxl_settings,)
#---------------------------------------------------------------------------------------------------------------------------------------------------#
class SDXL_Settings_Pipe:
def __init__(self):
pass
@classmethod
def INPUT_TYPES(s):
return {
"required": {
"sdxl_settings": ("BASIC_PIPE",)
},
}
RETURN_TYPES = ("INT","INT","INT","INT",comfy.samplers.KSampler.SAMPLERS,comfy.samplers.KSampler.SCHEDULERS,"INT","FLOAT","FLOAT","INT","STRING",)
RETURN_NAMES = ("image_res","width","height","res_factor","sampler_name","scheduler","steps","cfg","cfg_rescale","clip_skip","filename",)
FUNCTION = "give_values"
CATEGORY="JPS Nodes/Pipes"
def give_values(self,sdxl_settings):
width, height, res_factor, sampler_name, scheduler, steps, cfg, cfg_rescale, clip_skip, filename,image_res = sdxl_settings
return(int(image_res), int(width), int(height), int (res_factor), sampler_name, scheduler, int(steps), float(cfg), float(cfg_rescale), int(clip_skip), str(filename),)
#---------------------------------------------------------------------------------------------------------------------------------------------------#
class SDXL_Prompt_Handling_Plus:
handling = ["Copy to Both if Empty","Use Positive_G + Positive_L","Copy Positive_G to Both","Copy Positive_L to Both","Ignore Positive_G Input", "Ignore Positive_L Input", "Combine Positive_G + Positive_L", "Combine Positive_L + Positive_G",]
def __init__(self):
pass
@classmethod
def INPUT_TYPES(s):
return {
"required": {
"handling": (s.handling,),
"pos_g": ("STRING", {"multiline": True, "placeholder": "Prompt Text pos_g", "dynamicPrompts": True}),
"pos_l": ("STRING", {"multiline": True, "placeholder": "Prompt Text pos_l", "dynamicPrompts": True}),
},
}
RETURN_TYPES = ("STRING","STRING",)
RETURN_NAMES = ("pos_g","pos_l",)
FUNCTION = "pick_handling"
CATEGORY="JPS Nodes/Text"
def pick_handling(self,handling,pos_g,pos_l):
if(handling == "Copy Positive_G to Both"):
pos_l = pos_g
elif(handling == "Copy Positive_L to Both"):
pos_g = pos_l
elif(handling == "Ignore Positive_G Input"):
pos_g = ''
elif(handling == "Ignore Positive_L Input"):
pos_l = ''
elif(handling == "Combine Positive_G + Positive_L"):
combine = pos_g + ' . ' + pos_l
pos_g = combine
pos_l = combine
elif(handling == "Combine Positive_L + Positive_G"):
combine = pos_l + ' . ' + pos_g
pos_g = combine
pos_l = combine
elif(handling == "Copy to Both if Empty" and pos_l == ''):
pos_l = pos_g
elif(handling == "Copy to Both if Empty" and pos_g == ''):
pos_g = pos_l
return(pos_g,pos_l,)
#---------------------------------------------------------------------------------------------------------------------------------------------------#
class Text_Prompt:
def __init__(self):
pass
@classmethod
def INPUT_TYPES(s):
return {
"required": {
"text": ("STRING", {"multiline": True, "placeholder": "Prompt Text", "dynamicPrompts": True}),
},
}
RETURN_TYPES = ("STRING",)
RETURN_NAMES = ("text",)
FUNCTION = "text_prompt"
CATEGORY="JPS Nodes/Text"
def text_prompt(self,text):
return(text,)
#---------------------------------------------------------------------------------------------------------------------------------------------------#
class Text_Prompt_Combo:
def __init__(self):
pass
@classmethod
def INPUT_TYPES(s):
return {
"required": {
"pos": ("STRING", {"multiline": True, "placeholder": "Prompt Text Positive", "dynamicPrompts": True}),
"neg": ("STRING", {"multiline": True, "placeholder": "Prompt Text Negative", "dynamicPrompts": True}),
},
}
RETURN_TYPES = ("STRING","STRING",)
RETURN_NAMES = ("pos","neg",)
FUNCTION = "give_values"
CATEGORY="JPS Nodes/Text"
def give_values(self,pos,neg):
return(pos,neg,)
#---------------------------------------------------------------------------------------------------------------------------------------------------#
class SDXL_Prompt_Handling:
handling = ["Copy to Both if Empty","Use Positive_G + Positive_L","Copy Positive_G to Both","Copy Positive_L to Both","Ignore Positive_G Input", "Ignore Positive_L Input", "Combine Positive_G + Positive_L", "Combine Positive_L + Positive_G",]
def __init__(self):
pass
@classmethod
def INPUT_TYPES(s):
return {
"required": {
"handling": (s.handling,),
"pos_g": ("STRING", {"default": ""}),
"pos_l": ("STRING", {"default": ""}),
},
}
RETURN_TYPES = ("STRING","STRING",)
RETURN_NAMES = ("pos_g","pos_l",)
FUNCTION = "pick_handling"
CATEGORY="JPS Nodes/Text"
def pick_handling(self,handling,pos_g,pos_l,):
if(handling == "Copy Positive_G to Both"):
pos_l = pos_g
elif(handling == "Copy Positive_L to Both"):
pos_g = pos_l
elif(handling == "Ignore Positive_G Input"):
pos_g = ''
elif(handling == "Ignore Positive_L Input"):
pos_l = ''
elif(handling == "Combine Positive_G + Positive_L"):
combine = pos_g + ' . ' + pos_l
pos_g = combine
pos_l = combine
elif(handling == "Combine Positive_L + Positive_G"):
combine = pos_l + ' . ' + pos_g
pos_g = combine
pos_l = combine
elif(handling == "Copy to Both if Empty" and pos_l == ''):
pos_l = pos_g
elif(handling == "Copy to Both if Empty" and pos_g == ''):
pos_g = pos_l
return(pos_g,pos_l,)
#---------------------------------------------------------------------------------------------------------------------------------------------------#
class Math_Resolution_Multiply:
def __init__(self):
pass
@classmethod
def INPUT_TYPES(s):
return {
"required": {
"width": ("INT", {"default": 1024, "min": 256, "max": 8192, "step": 16}),
"height": ("INT", {"default": 1024, "min": 256, "max": 8192, "step": 16}),
"factor": ("INT", {"default": 2, "min": 1, "max": 8, "step": 1}),
}}
RETURN_TYPES = ("INT","INT")
RETURN_NAMES = ("width_resized", "height_resized")
FUNCTION = "get_newres"
CATEGORY="JPS Nodes/Math"
def get_newres(self,width,height,factor):
factor = int(factor)
width = int(width)
width_resized = int(width) * int(factor)
height = int(height)
height_resized = int (height) * int(factor)
return(int(width_resized),int(height_resized))
#---------------------------------------------------------------------------------------------------------------------------------------------------#
class Math_Largest_Integer:
def init(self):
pass
@classmethod
def INPUT_TYPES(cls):
return {
"required": {
"int_a": ("INT", {"default": 1,}),
"int_b": ("INT", {"default": 1,}),
}
}
RETURN_TYPES = ("INT","INT","INT")
RETURN_NAMES = ("larger_int","smaller_int","is_a_larger")
FUNCTION = "get_lrg"
CATEGORY="JPS Nodes/Math"
def get_lrg(self,int_a,int_b):
larger_int = int(int_b)
smaller_int = int(int_a)
is_a_larger = int(0)
if int_a > int_b:
larger_int = int(int_a)
smaller_int = int(int_b)
is_a_larger = int(1)
return(int(larger_int),int(smaller_int),int(is_a_larger))
#---------------------------------------------------------------------------------------------------------------------------------------------------#
class Math_Multiply_INT_INT:
def init(self):
pass
@classmethod
def INPUT_TYPES(cls):
return {
"required": {
"int_a": ("INT", {"default": 1,}),
"int_b": ("INT", {"default": 1,}),
}
}
RETURN_TYPES = ("INT","FLOAT")
RETURN_NAMES = ("int_multiply","float_multiply")
FUNCTION = "get_multiply_int_int"
CATEGORY="JPS Nodes/Math"
def get_multiply_int_int(self,int_a,int_b):
int_multiply = int(int_a) * int(int_b)
float_multiply = int(int_a) * int(int_b)
return(int(int_multiply),float(float_multiply))
#---------------------------------------------------------------------------------------------------------------------------------------------------#
class Math_Multiply_INT_FLOAT:
def init(self):
pass
@classmethod
def INPUT_TYPES(cls):
return {
"required": {
"int_a": ("INT", {"default": 1,}),
"float_b": ("FLOAT", {"default": 1,}),
}
}
RETURN_TYPES = ("INT","FLOAT")
RETURN_NAMES = ("int_multiply","float_multiply")
FUNCTION = "get_multiply_int_float"
CATEGORY="JPS Nodes/Math"
def get_multiply_int_float(self,int_a,float_b):
int_multiply = int(int_a) * float(float_b)
float_multiply = int(int_a) * float(float_b)
return(int(int_multiply),float(float_multiply))
#---------------------------------------------------------------------------------------------------------------------------------------------------#
class Math_Multiply_FLOAT_FLOAT:
def init(self):
pass
@classmethod
def INPUT_TYPES(cls):
return {
"required": {
"float_a": ("FLOAT", {"default": 1,}),
"float_b": ("FLOAT", {"default": 1,}),
}
}
RETURN_TYPES = ("INT","FLOAT")
RETURN_NAMES = ("int_multiply","float_multiply")
FUNCTION = "get_multiply_float_float"
CATEGORY="JPS Nodes/Math"
def get_multiply_float_float(self,float_a,float_b):
int_multiply = float(float_a) * float(float_b)
float_multiply = float(float_a) * float(float_b)
return(int(int_multiply),float(float_multiply))
#---------------------------------------------------------------------------------------------------------------------------------------------------#
class Math_Substract_INT_INT:
def init(self):
pass
@classmethod
def INPUT_TYPES(cls):
return {
"required": {
"int_a": ("INT", {"default": 1,}),
"int_b": ("INT", {"default": 1,}),
}
}
RETURN_TYPES = ("INT","FLOAT")
RETURN_NAMES = ("int_substract","float_substract")
FUNCTION = "get_substract_int_int"
CATEGORY="JPS Nodes/Math"
def get_substract_int_int(self,int_a,int_b):
int_substract = int(int_a) - int(int_b)
float_substract = int(int_a) - int(int_b)
return(int(int_substract),float(float_substract))
#---------------------------------------------------------------------------------------------------------------------------------------------------#
class Text_Concatenate:
@classmethod
def INPUT_TYPES(s):
return {
"required": {
"delimiter": (["none", "space", "comma"],),
},
"optional": {
"text1": ("STRING", {"forceInput": True}),
"text2": ("STRING", {"forceInput": True}),
"text3": ("STRING", {"forceInput": True}),
"text4": ("STRING", {"forceInput": True}),
"text5": ("STRING", {"forceInput": True}),
}
}
RETURN_TYPES = ("STRING",)
RETURN_NAMES = ("text",)
FUNCTION = "get_contxt"
CATEGORY = "JPS Nodes/Text"
def get_contxt(self, delimiter, text1=None, text2=None, text3=None, text4=None, text5=None):
needdelim = False
delim = ""
if delimiter == "space":
delim = " "
if delimiter == "comma":
delim = ", "
concatenated = ""
if text1:
concatenated = text1
needdelim = True
if text2:
if needdelim:
concatenated += delim
concatenated += text2
needdelim = True
if text3:
if needdelim:
concatenated += delim
concatenated += text3
needdelim = True
if text4:
if needdelim:
concatenated += delim
concatenated += text4
needdelim = True
if text5:
if needdelim:
concatenated += delim
concatenated += text5
needdelim = True
return (concatenated,)
#---------------------------------------------------------------------------------------------------------------------------------------------------#
class Get_Date_Time_String:
time_format = ["%Y%m%d%H%M%S","%Y%m%d%H%M","%Y%m%d","%Y-%m-%d-%H_%M_%S","%Y-%m-%d-%H_%M","%Y-%m-%d","%Y-%m-%d %H_%M_%S","%Y-%m-%d %H_%M","%Y-%m-%d","%H%M","%H%M%S","%H_%M","%H_%M_%S"]
def __init__(self):
pass
@classmethod
def INPUT_TYPES(s):
return {
"required": {
"style": (s.time_format,),
}
}
RETURN_TYPES = ("STRING",)
RETURN_NAMES = ("time_format",)
FUNCTION = "get_time"
CATEGORY = "JPS Nodes/Text"
def get_time(self, style):
now = datetime.now()
timestamp = now.strftime(style)
return (timestamp,)
@classmethod
def IS_CHANGED(s, style):
now = datetime.now()
timestamp = now.strftime(style)
return (timestamp,)
#---------------------------------------------------------------------------------------------------------------------------------------------------#
class Time_Seed:
# time_format = ["%Y%m%d%H%M%S","%Y%m%d%H%M","%Y%m%d","%Y-%m-%d-%H_%M_%S","%Y-%m-%d-%H_%M","%Y-%m-%d","%Y-%m-%d %H_%M_%S","%Y-%m-%d %H_%M","%Y-%m-%d","%H%M","%H%M%S","%H_%M","%H_%M_%S"]
def __init__(self):
pass
@classmethod
def INPUT_TYPES(s):
return {
"required": {
"fixed_seed": ("INT", {"default": 0, "min": 0, "max": 99999999999, "step": 1}),
}
}
RETURN_TYPES = ("INT",)
RETURN_NAMES = ("seed",)
FUNCTION = "get_seed"
CATEGORY = "JPS Nodes/Text"
def get_seed(self, fixed_seed):
now = datetime.now()
time = now.strftime("%Y%m%d%H%M%S")
seed_out = int(time) + np.random.randint(999999)
if fixed_seed != 0:
seed_out=fixed_seed
return (int(seed_out),)
@classmethod
def IS_CHANGED(s, seed_out):
now = datetime.now()
forceupdate = now.strftime("%Y%m%d%H%M%S")
forceupdate = forceupdate + np.random.randint(99999999) + seed_out
return (forceupdate,)
#---------------------------------------------------------------------------------------------------------------------------------------------------#
class SDXL_Recommended_Resolution_Calc:
def __init__(self):
pass
@classmethod
def INPUT_TYPES(s):
return {
"required": {
"target_width": ("INT", {
"default": 1024,
"min": 0,
"max": 8192,
"step": 2
}),
"target_height": ("INT", {
"default": 1024,
"min": 0,
"max": 8192,
"step": 2
}),
},
}