Class: StableDiffusionRuby::Client

Inherits:
Object
  • Object
show all
Defined in:
lib/stable_diffusion_ruby/client.rb

Instance Method Summary collapse

Instance Method Details

#generate(prompt: nil, style: "photorealistic", model: nil, backend: nil) ⇒ Result

Generate an image from a text prompt.

Parameters:

  • prompt (String, nil) (defaults to: nil)

    Text prompt for generation

  • style (String) (defaults to: "photorealistic")

    Style preset (“photorealistic”, “anime”)

  • model (String, nil) (defaults to: nil)

    Model override (“sdxl” or “sd35”)

  • backend (Symbol, nil) (defaults to: nil)

    Force a backend (:modal, :python) or nil for auto-detect

Returns:



28
29
30
31
32
33
34
# File 'lib/stable_diffusion_ruby/client.rb', line 28

def generate(prompt: nil, style: "photorealistic", model: nil, backend: nil)
  params = { style: style }
  params[:user_prompt] = prompt if prompt
  params[:model] = model if model

  execute("generate_image", params, backend: backend)
end

#inpaint(image_path:, mask_path:, prompt: nil, model: nil, backend: nil) ⇒ Result

Repaint a masked region of an image using AI inpainting.

Parameters:

  • image_path (String)

    Path to the image

  • mask_path (String)

    Path to the mask PNG (white=repaint, black=keep)

  • prompt (String, nil) (defaults to: nil)

    Override prompt

  • model (String, nil) (defaults to: nil)

    Model override (“sdxl” or “sd35”)

  • backend (Symbol, nil) (defaults to: nil)

    Force a backend (:modal, :python) or nil for auto-detect

Returns:



44
45
46
47
48
49
50
# File 'lib/stable_diffusion_ruby/client.rb', line 44

def inpaint(image_path:, mask_path:, prompt: nil, model: nil, backend: nil)
  params = { image_path: image_path, mask_path: mask_path }
  params[:prompt] = prompt if prompt
  params[:model] = model if model

  execute("inpaint_region", params, backend: backend)
end

#outpaint(source_path:, prompt: nil, model: nil, seed_offset: 0, backend: nil) ⇒ Result

Extend a square image to 16:9 using AI outpainting.

Parameters:

  • source_path (String)

    Path to the source square image

  • prompt (String, nil) (defaults to: nil)

    Override prompt (auto-generates from image analysis if nil)

  • model (String, nil) (defaults to: nil)

    Model override (“sdxl” or “sd35”)

  • seed_offset (Integer) (defaults to: 0)

    Seed offset for reproducibility

  • backend (Symbol, nil) (defaults to: nil)

    Force a backend (:modal, :python) or nil for auto-detect

Returns:



13
14
15
16
17
18
19
# File 'lib/stable_diffusion_ruby/client.rb', line 13

def outpaint(source_path:, prompt: nil, model: nil, seed_offset: 0, backend: nil)
  params = { source_path: source_path, seed_offset: seed_offset }
  params[:prompt] = prompt if prompt
  params[:model] = model if model

  execute("outpaint_image", params, backend: backend)
end