Skip to content

Instantly share code, notes, and snippets.

@unitycoder
Forked from ausbitbank/invokeAi-api-gist
Created February 25, 2024 10:54
Show Gist options
  • Save unitycoder/f24872f57f868eb37af99713d88f4abb to your computer and use it in GitHub Desktop.
Save unitycoder/f24872f57f868eb37af99713d88f4abb to your computer and use it in GitHub Desktop.
This is a simplified version of whats needed to connect to InvokeAI websocket api, submit requests, upload init_images and recieve results
const io = require("socket.io-client")
const socket = io("http://127.0.0.1:9090",{reconnect: true})
const log = console.log.bind(console)
socket.on("connect", (socket) => {
log(socket) // Connected to api
})
socket.on("progressUpdate", (data) => {
log(data) // Returns current steps, status etc
}
socket.on("generationResult", (data) => {
log(data) // data contains all the image data needed (params, filename etc)
})
var imageOptions={
prompt: 'anon goes to space',
iterations: 1,
steps: 50,
cfg_scale: 7.5,
threshold: 0,
perlin: 0,
sampler_name: 'k_lms',
width: 512,
height: 512,
seed: 2977597109,
progress_images: false,
variation_amount: 0,
strength: 0.75,
fit: true
}
var upscale=false // or an object like {level:2,strength:0.5}
var facefix=false // or an object like {type:'codeformer',strength:1,codeformer_fidelity:1}}
socket.emit('generateImage',imageOptions,upscale,facefix) // Send request, result comes via a "generationResult" reply
// if you need to send an init image
// "initimg" should contain a buffered file // Buffer.from(res.data)
// socket.emit('uploadInitialImage', initimg, 'filename.png') // I pass an id via the filename to associate the returned result later
socket.on("initialImageUploaded", (data) => {
log(data) // Contains uploaded images new filename
})
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment