mypiper commited on
Commit
a91de1e
·
verified ·
1 Parent(s): 1050f6e

Create replicate.yaml

Browse files
Files changed (1) hide show
  1. replicate.yaml +135 -0
replicate.yaml ADDED
@@ -0,0 +1,135 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ _id: replicate
2
+ author: Anton Breslavskii | https://github.com/breslavsky
3
+ description: Provides features to use AI models from Replicate AI
4
+ readme: ""
5
+ title: Replicate AI
6
+ url: https://huggingface.co/PiperMy/Node-Packages/resolve/main/replicate.yaml
7
+ version: 5
8
+ nodes:
9
+ generate_on_flux_replicate:
10
+ _id: generate_on_flux_replicate
11
+ arrange:
12
+ x: 300
13
+ y: 120
14
+ category:
15
+ id: generate_images
16
+ title: en=Generate images;ru=Генерация изображений
17
+ costs: |-
18
+ const COST_PER_IMAGE = 0.01;
19
+ (() => {
20
+ const { imagesCount } = inputs;
21
+ return imagesCount * COST_PER_IMAGE;
22
+ })()
23
+ environment:
24
+ REPLICATE_TOKEN:
25
+ title: Replicate token
26
+ description: Go to [Replicate](https://replicate.com/account/api-tokens) to take a keys
27
+ type: string
28
+ scope: global
29
+ inputs:
30
+ prompt:
31
+ order: 1
32
+ title: en=Prompt;ru=Подсказка
33
+ type: string
34
+ required: true
35
+ multiline: true
36
+ default: walking cat at the moon
37
+ imagesCount:
38
+ order: 2
39
+ title: en=Images count;ru=Кол-во
40
+ type: integer
41
+ required: true
42
+ min: 1
43
+ max: 4
44
+ step: 1
45
+ default: 1
46
+ aspectRatio:
47
+ order: 3
48
+ title: en=Aspect ratio;ru=Размер
49
+ type: string
50
+ default: 1:1
51
+ enum:
52
+ - 1:1
53
+ - 21:9
54
+ - 16:9
55
+ - 3:2
56
+ - 2:3
57
+ - 4:5
58
+ - 5:4
59
+ - 3:4
60
+ - 4:3
61
+ - 9:21
62
+ - 9:16
63
+ outputs:
64
+ images:
65
+ title: Images
66
+ type: image[]
67
+ image1:
68
+ title: Image 1
69
+ type: image
70
+ image2:
71
+ title: Image 2
72
+ type: image
73
+ image3:
74
+ title: Image 3
75
+ type: image
76
+ image4:
77
+ title: Image 4
78
+ type: image
79
+ package: replicate
80
+ script: |
81
+ (async () => {
82
+
83
+ const REPLICATE_TOKEN = env?.variables?.get('REPLICATE_TOKEN');
84
+ if(!REPLICATE_TOKEN) {
85
+ error.fatal('Please, set your API token for Replicate AI');
86
+ }
87
+
88
+ const { prompt, imagesCount, aspectRatio } = inputs;
89
+
90
+ if(!state) {
91
+ const {data: {id: task}} = await httpClient({
92
+ method: 'post',
93
+ url: 'https://api.replicate.com/v1/models/black-forest-labs/flux-schnell/predictions',
94
+ data: {
95
+ input: {
96
+ prompt,
97
+ num_outputs: imagesCount,
98
+ aspect_ratio: aspectRatio
99
+ }
100
+ },
101
+ headers: {
102
+ 'Authorization': `Bearer ${REPLICATE_TOKEN}`,
103
+ 'Content-Type': 'application/json',
104
+ 'Prefer': 'wait',
105
+ }
106
+ });
107
+ return repeat({state: {task}, delay: 2000});
108
+ } else {
109
+ const { task } = state;
110
+
111
+ const { data } = await httpClient({
112
+ method: 'get',
113
+ url: `https://api.replicate.com/v1/predictions/${task}`,
114
+ headers: {
115
+ 'Authorization': `Bearer ${REPLICATE_TOKEN}`,
116
+ 'Content-Type': 'application/json'
117
+ }
118
+ });
119
+
120
+ const { status, error } = data;
121
+ switch(status) {
122
+ case 'processing':
123
+ return repeat({state: {task}, delay: 3000});
124
+ case 'failed':
125
+ error.fatal(error);
126
+ case 'succeeded':
127
+ const { output: images } = data;
128
+ const [image1, image2, image3, image4] = images;
129
+ return next({outputs: {images, image1, image2, image3, image4}});
130
+ }
131
+ }
132
+ })();
133
+ source: catalog
134
+ title: en=Generate on Flux;ru=Генерация Flux
135
+ version: 5