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
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
1001
1002
1003
1004
1005
1006
1007
1008
1009
1010
1011
1012
1013
1014
1015
1016
1017
1018
1019
1020
1021
1022
1023
1024
1025
1026
1027
1028
1029
1030
1031
1032
1033
1034
1035
1036
1037
1038
1039
1040
1041
1042
1043
1044
1045
1046
1047
1048
1049
1050
1051
1052
1053
1054
1055
1056
1057
1058
1059
1060
1061
1062
1063
1064
1065
1066
1067
1068
1069
1070
1071
1072
1073
1074
1075
1076
1077
1078
1079
1080
1081
1082
1083
1084
1085
1086
1087
1088
1089
1090
1091
1092
1093
1094
1095
1096
1097
1098
1099
1100
1101
1102
1103
1104
1105
1106
1107
1108
1109
1110
1111
1112
1113
1114
1115
1116
1117
1118
1119
1120
1121
1122
1123
1124
1125
1126
1127
1128
1129
1130
1131
1132
1133
1134
1135
1136
1137
1138
1139
1140
1141
1142
1143
1144
1145
1146
1147
1148
1149
1150
1151
1152
1153
1154
1155
1156
1157
1158
1159
1160
1161
1162
1163
1164
1165
1166
1167
_id: replicate
author: Anton Breslavskii | https://github.com/breslavsky
description: Provides features to use AI models from Replicate AI
title: Replicate AI
url: https://huggingface.co/PiperMy/Node-Packages/resolve/main/replicate.yaml
version: 7
nodes:
  generate_on_flux_replicate:
    _id: generate_on_flux_replicate
    arrange:
      x: 300
      y: 120
    category:
      _id: generate_images
      title: en=Generate images;ru=Генерация изображений
    environment:
      REPLICATE_TOKEN:
        title: Replicate token
        description: Go to [Replicate](https://replicate.com/account/api-tokens) to take a keys
        type: string
        scope: global
    inputs:
      prompt:
        order: 1
        title: en=Prompt;ru=Подсказка
        type: string
        required: true
        multiline: true
        default: walking cat at the moon
      imagesCount:
        order: 2
        title: en=Images count;ru=Кол-во
        type: integer
        required: true
        min: 1
        max: 4
        step: 1
        default: 1
      aspectRatio:
        order: 3
        title: en=Aspect ratio;ru=Размер
        type: string
        default: 1:1
        enum:
          - 1:1
          - 21:9
          - 16:9
          - 3:2
          - 2:3
          - 4:5
          - 5:4
          - 3:4
          - 4:3
          - 9:21
          - 9:16
    outputs:
      images:
        title: Images
        type: image[]
      image1:
        title: Image 1
        type: image
      image2:
        title: Image 2
        type: image
      image3:
        title: Image 3
        type: image
      image4:
        title: Image 4
        type: image
    package: replicate
    script: |
      export async function run({ inputs, state }) {

          const { RepeatNode, NextNode, FatalError } = DEFINITIONS;

          const REPLICATE_TOKEN = env?.variables?.get('REPLICATE_TOKEN');
          if (!REPLICATE_TOKEN) {
              throw new FatalError('Please, set your API token for Replicate AI');
          }

          const { prompt, imagesCount, aspectRatio } = inputs;

          if (!state) {
              const { data: { id: task } } = await httpClient({
                  method: 'post',
                  url: 'https://api.replicate.com/v1/models/black-forest-labs/flux-schnell/predictions',
                  data: {
                      input: {
                          prompt,
                          num_outputs: imagesCount,
                          aspect_ratio: aspectRatio
                      }
                  },
                  headers: {
                      'Authorization': `Bearer ${REPLICATE_TOKEN}`,
                      'Content-Type': 'application/json',
                      'Prefer': 'wait',
                  }
              });
              return RepeatNode.from({ state: { task }, delay: 2000 });
          } else {
              const { task } = state;

              const { data } = await httpClient({
                  method: 'get',
                  url: `https://api.replicate.com/v1/predictions/${task}`,
                  headers: {
                      'Authorization': `Bearer ${REPLICATE_TOKEN}`,
                      'Content-Type': 'application/json'
                  }
              });

              const { status, error } = data;
              switch (status) {
                  case 'processing':
                      return RepeatNode.from({ state: { task }, delay: 3000 });
                  case 'failed':
                      error.fatal(error);
                  case 'succeeded':
                      const { output: images } = data;
                      const [image1, image2, image3, image4] = images;
                      return NextNode.from({ outputs: { images, image1, image2, image3, image4 } });
              }
          }
      }
    source: catalog
    title: en=Generate on Flux;ru=Генерация Flux
    version: 5
    execution: regular
  kling_1_6_replicate:
    _id: kling_1_6_replicate
    arrange:
      x: 460
      y: 330
    category:
      _id: generate_videos
      title: en=Generate video;ru=Генерация видео
    environment:
      REPLICATE_TOKEN:
        title: Replicate token
        description: Go to [Replicate](https://replicate.com/account/api-tokens) to get API key
        type: string
        scope: global
    execution: regular
    inputs:
      image:
        order: 1
        title: en=Image;ru=Изображение
        type: image
        required: true
      prompt:
        order: 2
        title: en=Prompt;ru=Подсказка
        type: string
        required: true
        multiline: true
      negativePrompt:
        order: 3
        title: en=Negative prompt;ru=Негативная подсказка
        type: string
        multiline: true
      aspectRatio:
        order: 4
        title: en=Aspect ratio;ru=Соотношение сторон
        type: string
        default: 16:9
        enum:
          - 1:1
          - 16:9
          - 9:16
      cfgScale:
        order: 5
        title: en=Creativity (CFG scale);ru=Креативность (CFG)
        type: float
        min: 0
        max: 1
        step: 0.1
        default: 0.5
      duration:
        order: 6
        title: en=Duration;ru=Длина
        type: integer
        min: 5
        max: 10
        step: 5
        default: 5
    outputs:
      video:
        title: en=Video;ru=Видео
        type: video
    package: replicate
    script: |
      export async function costs({ inputs }) {
          const duration = Number(inputs?.duration || 5);
          return Number((duration * 0.05).toFixed(3));
      }

      const MAX_RETRIES = 100;
      export async function run({ inputs, state }) {

          const { RepeatNode, NextNode, FatalError } = DEFINITIONS;

          const REPLICATE_TOKEN = env?.variables?.get('REPLICATE_TOKEN');
          if (!REPLICATE_TOKEN) {
              throw new FatalError('Please, set your API token for Replicate AI');
          }

          const { image, prompt, negativePrompt, aspectRatio, cfgScale, duration } = inputs;

          if (!state) {
              const { data: { id: task } } = await httpClient({
                  method: 'post',
                  url: 'https://api.replicate.com/v1/models/kwaivgi/kling-v1.6-standard/predictions',
                  data: {
                      input: {
                          start_image: image,
                          prompt,
                          negative_prompt: negativePrompt,
                          aspect_ratio: aspectRatio,
                          cfg_scale: cfgScale,
                          duration
                      }
                  },
                  headers: {
                      'Authorization': `Bearer ${REPLICATE_TOKEN}`,
                      'Content-Type': 'application/json'
                  }
              });
              return RepeatNode.from({
                  state: {
                      task,
                      retries: 0
                  },
                  delay: 10000
              });
          } else {
              const { task, retries } = state;

              const { data } = await httpClient({
                  method: 'get',
                  url: `https://api.replicate.com/v1/predictions/${task}`,
                  headers: {
                      'Authorization': `Bearer ${REPLICATE_TOKEN}`,
                      'Content-Type': 'application/json'
                  }
              });

              const { status, error } = data;
              switch (status) {
                  case 'starting':
                  case 'processing':
                      if (state.retries > MAX_RETRIES) {
                          throw new FatalError('Generation timeout exceeded');
                      }
                      return RepeatNode.from({
                          state: {
                              ...state,
                              retries: retries + 1
                          },
                          progress: {
                              total: MAX_RETRIES,
                              processed: retries
                          },
                          delay: 5000
                      });
                  case 'failed':
                      throw new FatalError(error || 'Generation failed');
                  case 'succeeded':
                      const { output: video } = data;
                      return NextNode.from({ outputs: { video }, costs: await costs({ inputs }) });
                  default:
                      throw new FatalError(`Unknown status: ${status}`);
              }
          }
      }
    source: catalog
    title: en=Generate video Kling 1.6;ru=Генерация видео Kling 1.6
    version: 1
  florence_vision_replicate:
    _id: florence_vision_replicate
    arrange:
      x: 140
      y: 80
    category:
      _id: computer_vision
      title: Computer vision
    environment:
      REPLICATE_TOKEN:
        title: Replicate token
        description: Get your token from https://replicate.com/account/api-tokens
        type: string
        scope: global
    execution: regular
    inputs:
      image:
        order: 1
        title: Image
        type: image
        required: true
      mode:
        order: 2
        title: Mode
        type: string
        required: true
        default: detailed_caption
        enum:
          - caption|Caption
          - detailed_caption|Detailed caption
    outputs:
      caption:
        title: Caption
        type: string
    package: replicate
    script: |
      export async function run({ inputs, state }) {
          const { RepeatNode, NextNode, FatalError } = DEFINITIONS;

          const REPLICATE_TOKEN = env?.variables?.get('REPLICATE_TOKEN');
          if (!REPLICATE_TOKEN) {
              throw new FatalError('Please, set REPLICATE_TOKEN environment variable');
          }

          const { image, mode } = inputs;

          if (!state) {
              const { data: { id: task } } = await httpClient({
                  method: 'post',
                  url: 'https://api.replicate.com/v1/predictions',
                  data: {
                      version: 'da53547e17d45b9cfb48174b2f18af8b83ca020fa76db62136bf9c6616762595',
                      input: {
                          image: image,
                          task_input: mode === 'caption' ? 'Caption' : 'Detailed Caption'
                      }
                  },
                  headers: {
                      'Authorization': `Token ${REPLICATE_TOKEN}`,
                      'Content-Type': 'application/json'
                  },
                  timeout: 10000
              });

              return RepeatNode.from({
                  state: {
                      task,
                      retries: 0
                  },
                  delay: 2000
              });
          } else {
              const { data } = await httpClient({
                  method: 'get',
                  url: `https://api.replicate.com/v1/predictions/${state.task}`,
                  headers: {
                      'Authorization': `Token ${REPLICATE_TOKEN}`,
                      'Content-Type': 'application/json'
                  },
                  timeout: 5000
              });

              const { status, error } = data;
              switch (status) {
                  case 'processing':
                  case 'starting':
                      if (state.retries > 30) {
                          throw new FatalError('Task timeout exceeded');
                      }
                      return RepeatNode.from({
                          state: {
                              ...state,
                              retries: state.retries + 1
                          },
                          delay: 3000
                      });
                  case 'failed':
                      throw new FatalError(error || 'Task failed');
                  case 'succeeded':
                      let caption = data.output?.text ||
                          data.output?.['<CAPTION>'] ||
                          data.output?.['<DETAILED_CAPTION>'] ||
                          'No caption generated';

                      // Удаляем метки CAPTION/DETAILED_CAPTION если они есть в тексте
                      caption = String(caption)
                          .replace(/^[\s{:]*['']?<CAPTION>['']?|[''}]\s*$/gi, '')
                          .replace(/^[\s{:]*['']?<DETAILED_CAPTION>['']?|[''}]\s*$/gi, '')
                          .replace(/^[\s:]*['']+|['']+\s*$/g, '')
                          .trim();

                      return NextNode.from({
                          outputs: {
                              caption
                          }
                      });
                  default:
                      throw new FatalError(`Unknown status: ${status}`);
              }
          }
      }
    source: catalog
    title: Florence-2 Vision
    version: 5
  generate_on_flux_fill_pro_replicate:
    _id: generate_on_flux_fill_pro_replicate
    arrange:
      x: 1730
      y: 90
    category:
      _id: generate_images
      title: en=Generate images;ru=Генерация изображений
    environment:
      REPLICATE_TOKEN:
        title: Replicate token
        description: Go to [Replicate](https://replicate.com/account/api-tokens) to take a keys
        type: string
        scope: global
    execution: regular
    inputs:
      prompt:
        order: 2
        title: en=Prompt;ru=Подсказка
        description: |-
          Text prompt for image generation
          --- ru ---
          Текстовая подсказка для генерации изображения
        type: string
        required: true
        multiline: true
      seed:
        order: 5
        title: en=Seed;ru=Начальный шум
        description: |-
          Seed "-1" is a random value, otherwise a fixed value
          --- ru ---
          Значение "-1" - случайное число, иначе фиксированное
        type: integer
        default: -1
      guidance:
        order: 8
        title: en=Guidance;ru=Креативность
        description: |-
          Controls the balance between adherence to the text prompt and image quality/diversity. Higher values make the output more closely match the prompt but may reduce overall image quality. Lower values allow for more creative freedom but might produce results less relevant to the prompt
          --- ru ---
          Контролирует баланс между соответствием текстовой подсказке и качеством/разнообразием изображения. Более высокие значения делают вывод более соответствующим подсказке, но могут снизить общее качество изображения. Более низкие значения позволяют большую творческую свободу, но могут давать результаты, менее соответствующие подсказке
        type: integer
        min: 2
        max: 100
        step: 1
        default: 60
      output_format:
        order: 10
        title: en=Output Format;ru=Формат вывода
        description: |-
          Format of the output images
          --- ru ---
          Формат выходных изображений
        type: string
        default: jpg
        enum:
          - jpg
          - png
      image:
        order: 1
        title: en=Image;ru=Изображение
        description: |-
          The image to inpaint. Can contain an alpha mask. Must be jpeg, png, gif, or webp
          --- ru ---
          Изображение для дорисовки. Может содержать альфа-маску. Должно быть в формате jpeg, png, gif или webp
        type: image
        required: true
        extensions:
          - id: draw-mask
            params:
              mask: mask
      mask:
        order: 3
        title: en=Mask;ru=Маска
        description: |-
          A black-and-white image that describes the part of the image to inpaint. Black areas will be preserved while white areas will be inpainted. Must have the same size as image. Optional if you provide an alpha mask in the original image
          --- ru ---
          Черно-белое изображение, описывающее часть изображения для дорисовки. Черные области будут сохранены, а белые области будут дорисованы. Должно иметь тот же размер, что и изображение. Необязательно, если вы предоставляете альфа-маску в исходном изображении
        type: image
      outpaint:
        order: 4
        title: en=Outpaint;ru=Расширение
        description: |-
          Outpainting an input image. Mask will be ignored
          --- ru ---
          Outpaint - расширения входного изображения. Маска будет проигнорирована
        type: string
        default: None
        enum:
          - None|en=None;ru=Ничего
          - Zoom out 1.5x|en=Zoom out 1.5x;ru=Отдалить в 1,5 раза
          - Zoom out 2x|en=Zoom out 2x;ru=Отдалить в 2 раза
          - Make square|en=Make square;ru=Сделать квадратным
          - Left outpaint|en=Left outpaint;ru=Расширить слева
          - Right outpaint|en=Right outpaint;ru=Расширить справа
          - Top outpaint|en=Top outpaint;ru=Расширить сверху
          - Bottom outpaint|en=Bottom outpaint;ru=Расширить снизу
      steps:
        order: 6
        title: en=Steps;ru=Шаги
        description: |-
          Range 15-50 (more=slower)
          --- ru ---
          Диапазон 15-50 (больше=медленнее)
        type: integer
        min: 15
        max: 50
        step: 1
        default: 50
      prompt_upsampling:
        order: 7
        title: en=Prompt Upsampling;ru=Улучшение подсказки
        description: |-
          Automatically modify the prompt for more creative generation
          --- ru ---
          Автоматически изменять подсказку для более креативной генерации
        type: boolean
        default: false
      safety_tolerance:
        order: 9
        title: en=Safety Tolerance;ru=Цензура
        description: |-
          Safety tolerance, 1 is most strict and 6 is most permissive
          --- ru ---
          Цензура от 1 (строгая) до 6 (свободная)
        type: integer
        min: 1
        max: 6
        step: 1
        default: 2
    outputs:
      image:
        title: en=Image;ru=Изображение
        type: image
    package: replicate
    script: |
      export async function run({ inputs, state }) {
          const { RepeatNode, NextNode, FatalError } = DEFINITIONS;

          const REPLICATE_TOKEN = env?.variables?.get('REPLICATE_TOKEN');
          if (!REPLICATE_TOKEN) {
              throw new FatalError('Please, set your API token for Replicate AI');
          }

          const {
              prompt,
              image,
              mask,
              outpaint = 'None',
              seed = -1,
              steps = 50,
              prompt_upsampling = false,
              guidance = 60,
              safety_tolerance = 2,
              output_format = 'jpg'
          } = inputs;

          if (!state) {
              const { data: { id: task } } = await httpClient({
                  method: 'post',
                  url: 'https://api.replicate.com/v1/models/black-forest-labs/flux-fill-pro/predictions',
                  data: {
                      input: {
                          prompt,
                          image,
                          mask,
                          outpaint,
                          seed,
                          steps,
                          prompt_upsampling,
                          guidance,
                          safety_tolerance,
                          output_format
                      }
                  },
                  headers: {
                      'Authorization': `Bearer ${REPLICATE_TOKEN}`,
                      'Content-Type': 'application/json'
                  },
                  timeout: 10000  // Увеличенный таймаут для старта
              });
              return RepeatNode.from({
                  state: {
                      task,
                      retries: 0
                  },
                  delay: 2000
              });
          } else {

              const { data } = await httpClient({
                  method: 'get',
                  url: `https://api.replicate.com/v1/predictions/${state.task}`,
                  headers: {
                      'Authorization': `Bearer ${REPLICATE_TOKEN}`,
                      'Content-Type': 'application/json'
                  },
                  timeout: 5000  // Таймаут для проверки статуса
              });

              const { status, error } = data;
              switch (status) {
                  case 'starting':
                  case 'processing':
                      if (state.retries > 30) {  // Увеличенный лимит попыток
                          throw new FatalError('Generation timeout exceeded');
                      }
                      return RepeatNode.from({
                          state: {
                              ...state,
                              retries: state.retries + 1
                          },
                          delay: 3000
                      });

                  case 'failed':
                      throw new FatalError(error || 'Generation failed');
                  case 'succeeded':
                      const imageOutput = data.output;
                      return NextNode.from({
                          outputs: {
                              image: imageOutput
                          }
                      });
                  default:
                      throw new FatalError(`Unknown status: ${status}`);
              }
          }
      }
    source: catalog
    title: en=Generate Flux Fill;ru=Генерация Flux Fill
    version: 1
  generate_on_flux_redux_replicate:
    _id: generate_on_flux_redux_replicate
    arrange:
      x: 1430
      y: 90
    category:
      _id: generate_images
      title: en=Generate images;ru=Генерация изображений
    environment:
      REPLICATE_TOKEN:
        title: Replicate token
        description: Go to [Replicate](https://replicate.com/account/api-tokens) to take a keys
        type: string
        scope: global
    execution: regular
    inputs:
      seed:
        order: 6
        title: en=Seed;ru=Начальный шум
        description: |-
          Seed "-1" is a random value, otherwise a fixed value
          --- ru ---
          Значение "-1" - случайное число, иначе фиксированное
        type: integer
        default: -1
      num_outputs:
        order: 3
        title: en=Images count;ru=Кол-во изображений
        description: |-
          Number of outputs to generate
          --- ru ---
          Количество изображений для генерации
        type: integer
        min: 1
        max: 4
        step: 1
        default: 1
      guidance:
        order: 5
        title: en=Guidance;ru=Креативность
        description: |-
          The larger the value, the greater the strength of the prompt (1-10)
          --- ru ---
          Чем больше значение, тем сильнее влияет подсказка (1-10)
        type: integer
        min: 1
        max: 10
        step: 0.5
        default: 3.5
      num_inference_steps:
        order: 4
        title: en=Generation steps;ru=Шагов генерации
        description: |-
          Range 15-50 (more=slower)
          --- ru ---
          Диапазон 15-50 (больше=медленнее)
        type: integer
        min: 15
        max: 50
        step: 1
        default: 28
      megapixels:
        order: 9
        title: en=Megapixels;ru=Мегапиксели
        description: |-
          Approximate number of megapixels for generated image
          --- ru ---
          Приблизительное количество мегапикселей для сгенерированного изображения
        type: string
        default: "1"
        enum:
          - "1"
          - "0.25"
      output_format:
        order: 7
        title: en=Output Format;ru=Формат вывода
        description: |-
          Format of the output images
          --- ru ---
          Формат выходного изображения
        type: string
        default: png
        enum:
          - webp
          - jpg
          - png
      output_quality:
        order: 8
        title: en=Quality;ru=Качество
        description: |-
          Quality when saving the output images, from 0 to 100. 100 is best quality, 0 is lowest quality. Not relevant for .png outputs
          --- ru ---
          Качество при сохранении изображений, от 0 до 100. 100 - наилучшее качество, 0 - наименьшее. Не актуально для выходных изображений в формате .png
        type: integer
        min: 0
        max: 100
        step: 1
        default: 80
      disable_safety_checker:
        order: 10
        title: en=Disable Safety Checker;ru=Отключить проверку
        description: |-
          Disable safety checker for generated images
          --- ru ---
          Отключить проверку безопасности для сгенерированных изображений
        type: boolean
        default: false
      redux_image:
        order: 1
        title: en=Image;ru=Изображение
        type: image
        required: true
      aspect_ratio:
        order: 2
        title: en=Aspect Ratio;ru=Соотношение сторон
        description: |-
          Aspect ratio for the generated image
          --- ru ---
          Соотношение сторон для сгенерированного изображения
        type: string
        default: 1:1
        enum:
          - 1:1
          - 16:9
          - 21:9
          - 3:2
          - 2:3
          - 4:5
          - 5:4
          - 3:4
          - 4:3
          - 9:16
          - 9:21
    outputs:
      images:
        title: Images
        type: image[]
      image1:
        title: Image 1
        type: image
      image2:
        title: Image 2
        type: image
      image3:
        title: Image 3
        type: image
      image4:
        title: Image 4
        type: image
    package: replicate
    script: |
      export async function run({ inputs, state }) {
          const { RepeatNode, NextNode, FatalError } = DEFINITIONS;

          const REPLICATE_TOKEN = env?.variables?.get('REPLICATE_TOKEN');
          if (!REPLICATE_TOKEN) {
              throw new FatalError('Please, set your API token for Replicate AI');
          }

          const {
              redux_image,
              aspect_ratio = '1:1',
              num_outputs = 1,
              num_inference_steps = 28,
              guidance = 3,
              seed = -1,
              output_format = 'webp',
              output_quality = 80,
              megapixels = '1',
              disable_safety_checker = false
          } = inputs;

          if (!state) {
              const { data: { id: task } } = await httpClient({
                  method: 'post',
                  url: 'https://api.replicate.com/v1/models/black-forest-labs/flux-redux-dev/predictions',
                  data: {
                      input: {
                          redux_image,
                          aspect_ratio,
                          num_outputs,
                          num_inference_steps,
                          guidance,
                          seed,
                          output_format,
                          output_quality,
                          megapixels,
                          disable_safety_checker
                      }
                  },
                  headers: {
                      'Authorization': `Bearer ${REPLICATE_TOKEN}`,
                      'Content-Type': 'application/json'
                  },
                  timeout: 10000
              });
              return RepeatNode.from({
                  state: {
                      task,
                      retries: 0
                  },
                  delay: 2000
              });
          } else {
              const { data } = await httpClient({
                  method: 'get',
                  url: `https://api.replicate.com/v1/predictions/${state.task}`,
                  headers: {
                      'Authorization': `Bearer ${REPLICATE_TOKEN}`,
                      'Content-Type': 'application/json'
                  },
                  timeout: 5000
              });

              const { status, error } = data;
              switch (status) {
                  case 'starting':
                  case 'processing':
                      if (state.retries > 20) {
                          throw new FatalError('Generation timeout exceeded');
                      }
                      return RepeatNode.from({
                          state: {
                              ...state,
                              retries: state.retries + 1
                          },
                          delay: 3000
                      });

                  case 'failed':
                      throw new FatalError(error || 'Generation failed');
                  case 'succeeded':
                      const { output: images } = data;
                      const [image1, image2, image3, image4] = images;
                      return NextNode.from({
                          outputs: {
                              images,
                              image1,
                              image2,
                              image3,
                              image4
                          }
                      });
                  default:
                      throw new FatalError(`Unknown status: ${status}`);
              }
          }
      }
    source: catalog
    title: en=Generate Flux Redux;ru=Генерация Flux Redux
    version: 1
  llava_1_5_13b_replicate:
    _id: llava_1_5_13b_replicate
    arrange:
      x: 130
      y: 420
    category:
      _id: computer_vision
      title: Computer vision
    environment:
      REPLICATE_TOKEN:
        title: Replicate token
        description: Get your token from https://replicate.com/account/api-tokens
        type: string
        scope: global
    execution: regular
    inputs:
      image:
        order: 1
        title: Image
        type: image
        required: true
      prompt:
        order: 2
        title: Prompt
        type: string
        required: true
        multiline: true
        default: describe this image
      maxTokens:
        order: 4
        title: Max tokens
        type: integer
        required: true
        default: 1024
      temperature:
        order: 3
        title: Temperature
        type: float
        required: true
        min: 0
        max: 1
        step: 0.1
        default: 0.2
      topP:
        order: 3
        title: Nucleus sampling
        type: float
        required: true
        min: 0
        max: 1
        step: 0.1
        default: 1
    outputs:
      description:
        title: Description
        type: string
    package: replicate
    script: |
      export async function run({ inputs, state }) {
          const { RepeatNode, NextNode, FatalError } = DEFINITIONS;

          const REPLICATE_TOKEN = env?.variables?.get('REPLICATE_TOKEN');
          if (!REPLICATE_TOKEN) {
              throw new FatalError('Please, set REPLICATE_TOKEN environment variable');
          }

          const { image, prompt = 'describe this image', topP, temperature, maxTokens } = inputs;

          if (!state) {
              const { data: { id: task } } = await httpClient({
                  method: 'post',
                  url: 'https://api.replicate.com/v1/predictions',
                  data: {
                      version: '80537f9eead1a5bfa72d5ac6ea6414379be41d4d4f6679fd776e9535d1eb58bb',
                      "stream": false,
                      input: {
                          image,
                          prompt,
                          top_p: topP,
                          temperature,
                          max_tokens: maxTokens
                      }
                  },
                  headers: {
                      'Authorization': `Token ${REPLICATE_TOKEN}`,
                      'Content-Type': 'application/json'
                  },
                  timeout: 10000
              });

              return RepeatNode.from({
                  state: {
                      task,
                      retries: 0
                  },
                  delay: 2000
              });
          } else {
              const { data } = await httpClient({
                  method: 'get',
                  url: `https://api.replicate.com/v1/predictions/${state.task}`,
                  headers: {
                      'Authorization': `Token ${REPLICATE_TOKEN}`,
                      'Content-Type': 'application/json'
                  },
                  timeout: 5000
              });

              const { status, error } = data;
              switch (status) {
                  case 'processing':
                  case 'starting':
                      if (state.retries > 30) {
                          throw new FatalError('Task timeout exceeded');
                      }
                      return RepeatNode.from({
                          state: {
                              ...state,
                              retries: state.retries + 1
                          },
                          delay: 3000
                      });
                  case 'failed':
                      throw new FatalError(error || 'Task failed');
                  case 'succeeded':
                      let description = data.output.join('');
                      return NextNode.from({
                          outputs: {
                              description
                          }
                      });
                  default:
                      throw new FatalError(`Unknown status: ${status}`);
              }
          }
      }
    source: catalog
    title: LLaVA-1.5-13B
    version: 1
  kling_2_1_replicate:
    _id: kling_2_1_replicate
    arrange:
      x: 460
      y: 610
    category:
      _id: generate_videos
      title: en=Generate video;ru=Генерация видео
    environment:
      REPLICATE_TOKEN:
        title: Replicate token
        description: Go to [Replicate](https://replicate.com/account/api-tokens) to get API key
        type: string
        scope: global
    execution: regular
    inputs:
      image:
        order: 1
        title: en=Image;ru=Изображение
        type: image
        required: true
      prompt:
        order: 2
        title: en=Prompt;ru=Подсказка
        type: string
        required: true
        multiline: true
      negativePrompt:
        order: 3
        title: en=Negative prompt;ru=Негативная подсказка
        type: string
        multiline: true
      duration:
        order: 5
        title: en=Duration;ru=Длина
        type: integer
        min: 5
        max: 10
        step: 5
        default: 5
      mode:
        order: 4
        title: en=Mode;ru=Режим
        type: string
        default: standard
        enum:
          - standard
          - pro
    outputs:
      video:
        title: en=Video;ru=Видео
        type: video
    package: replicate
    script: |
      export async function costs({ inputs }) {
          const duration = Number(inputs?.duration || 5);
          return Number((duration * 0.1).toFixed(3));
      }

      const MAX_RETRIES = 100;
      export async function run({ inputs, state }) {

          const { RepeatNode, NextNode, FatalError } = DEFINITIONS;

          const REPLICATE_TOKEN = env?.variables?.get('REPLICATE_TOKEN');
          if (!REPLICATE_TOKEN) {
              throw new FatalError('Please, set your API token for Replicate AI');
          }

          const { image, prompt, negativePrompt, mode, duration } = inputs;

          if (!state) {
              const { data: { id: task } } = await httpClient({
                  method: 'post',
                  url: 'https://api.replicate.com/v1/models/kwaivgi/kling-v2.1/predictions',
                  data: {
                      input: {
                          start_image: image,
                          prompt,
                          negative_prompt: negativePrompt,
                          mode,
                          duration
                      }
                  },
                  headers: {
                      'Authorization': `Bearer ${REPLICATE_TOKEN}`,
                      'Content-Type': 'application/json'
                  }
              });
              return RepeatNode.from({
                  state: {
                      task,
                      retries: 0
                  },
                  delay: 10000
              });
          } else {
              const { task, retries } = state;

              const { data } = await httpClient({
                  method: 'get',
                  url: `https://api.replicate.com/v1/predictions/${task}`,
                  headers: {
                      'Authorization': `Bearer ${REPLICATE_TOKEN}`,
                      'Content-Type': 'application/json'
                  }
              });

              const { status, error } = data;
              switch (status) {
                  case 'starting':
                  case 'processing':
                      if (state.retries > MAX_RETRIES) {
                          throw new FatalError('Generation timeout exceeded');
                      }
                      return RepeatNode.from({
                          state: {
                              ...state,
                              retries: retries + 1
                          },
                          progress: {
                              total: MAX_RETRIES,
                              processed: retries
                          },
                          delay: 5000
                      });
                  case 'failed':
                      throw new FatalError(error || 'Generation failed');
                  case 'succeeded':
                      const { output: video } = data;
                      return NextNode.from({ outputs: { video }, costs: await costs({ inputs }) });
                  default:
                      throw new FatalError(`Unknown status: ${status}`);
              }
          }
      }
    source: catalog
    title: en=Generate video Kling 2.1;ru=Генерация видео Kling 2.1
    version: 1