Class: GenAI::Image::StabilityAI
- Defined in:
- lib/gen_ai/image/stability_ai.rb
Constant Summary collapse
- DEFAULT_SIZE =
'256x256'
- API_BASE_URL =
'https://api.stability.ai'
- DEFAULT_MODEL =
'stable-diffusion-xl-beta-v2-2-2'
- UPSCALE_MODEL =
'stable-diffusion-x4-latent-upscaler'
Instance Method Summary collapse
- #edit(image, prompt, options = {}) ⇒ Object
- #generate(prompt, options = {}) ⇒ Object
-
#initialize(token:, options: {}) ⇒ StabilityAI
constructor
A new instance of StabilityAI.
- #upscale(image, options = {}) ⇒ Object
Methods inherited from Base
Methods included from Dependency
Constructor Details
#initialize(token:, options: {}) ⇒ StabilityAI
Returns a new instance of StabilityAI.
13 14 15 |
# File 'lib/gen_ai/image/stability_ai.rb', line 13 def initialize(token:, options: {}) build_client(token) end |
Instance Method Details
#edit(image, prompt, options = {}) ⇒ Object
30 31 32 33 34 35 36 37 38 39 40 41 |
# File 'lib/gen_ai/image/stability_ai.rb', line 30 def edit(image, prompt, = {}) model = [:model] || DEFAULT_MODEL url = "/v1/generation/#{model}/image-to-image" response = client.post url, build_edit_body(image, prompt, ), multipart: true build_result( raw: response, model: model, parsed: parse_response_data(response['artifacts']) ) end |
#generate(prompt, options = {}) ⇒ Object
17 18 19 20 21 22 23 24 25 26 27 28 |
# File 'lib/gen_ai/image/stability_ai.rb', line 17 def generate(prompt, = {}) model = [:model] || DEFAULT_MODEL url = "/v1/generation/#{model}/text-to-image" response = client.post url, build_generation_body(prompt, ) build_result( raw: response, model: model, parsed: parse_response_data(response['artifacts']) ) end |
#upscale(image, options = {}) ⇒ Object
43 44 45 46 47 48 49 50 51 52 53 54 |
# File 'lib/gen_ai/image/stability_ai.rb', line 43 def upscale(image, = {}) model = [:model] || UPSCALE_MODEL url = "/v1/generation/#{model}/image-to-image/upscale" response = client.post url, build_upscale_body(image, ), multipart: true build_result( raw: response, model: model, parsed: parse_response_data(response['artifacts']) ) end |