Created
April 12, 2023 22:41
-
-
Save peterc/66dfe8900ef157530c8f9b8c2293ce19 to your computer and use it in GitHub Desktop.
Basic Ruby client to the Automatic1111 WebUI API
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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