Skip to content

Instantly share code, notes, and snippets.

@peterc
Created April 12, 2023 22:41
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save peterc/66dfe8900ef157530c8f9b8c2293ce19 to your computer and use it in GitHub Desktop.
Save peterc/66dfe8900ef157530c8f9b8c2293ce19 to your computer and use it in GitHub Desktop.
Basic Ruby client to the Automatic1111 WebUI API
require 'json'
require 'rest-client'
require 'base64'
url = "http://localhost:7860"
payload = {
"prompt": "liminal space, unusual lighting, sinister presence",
"negative_prompt": "",
"steps": 30,
"sampler_name": "Euler a",
"cfg_scale": 5.5,
"restore_faces": true,
"seed": 123456,
"batch_size": 4
}
response = RestClient.post "#{url}/sdapi/v1/txt2img", payload.to_json, {content_type: :json, accept: :json}
r = JSON.parse(response.body)
r["images"].each.with_index do |image, i|
image_data = Base64.decode64(image)
File.open("output#{i}.png", 'wb') { |f| f.write(image_data) }
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment