const ws = require('ws'); async function changestyle(buffer, style = 'anime') { const _style = { anime: [], ghibli: ['ghibli_style_offset:0.8'] }; if (!buffer || !Buffer.isBuffer(buffer)) throw new Error('Image buffer is required'); if (!Object.keys(_style).includes(style)) throw new Error(`Available styles: ${Object.keys(_style).join(', ')}`); const session_hash = Math.random().toString(36).substring(2); const socket = new ws('wss://colorifyai.art/demo-auto-coloring/queue/join'); return new Promise(async (resolve, reject) => { socket.on('message', (data) => { const d = JSON.parse(data.toString('utf8')); if (d.msg === 'send_hash') { socket.send(JSON.stringify({ session_hash })); } else if (d.msg === 'send_data') { socket.send(JSON.stringify({ data: { lora: _style[style], source_image: `data:image/jpeg;base64,${buffer.toString('base64')}`, prompt: '(masterpiece), best quality', // Can be adjust request_from: 10 } })); } else if (d.msg === 'process_completed') { socket.close(); resolve(`https://temp.colorifyai.art/${d.output.result[0]}`); } }); }); } // Usage: const fs = require('fs'); const resp = await changestyle(fs.readFileSync('./image2.jpg'), 'ghibli'); console.log(resp);