_id: replicate author: Anton Breslavskii | https://github.com/breslavsky description: Provides features to use AI models from Replicate AI readme: "" title: Replicate AI url: https://huggingface.co/PiperMy/Node-Packages/resolve/main/replicate.yaml version: 6 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