Class: RubyLLM::Agents::ImageUpscaler

Inherits:
Object
  • Object
show all
Extended by:
DSL
Includes:
Execution
Defined in:
lib/ruby_llm/agents/image/upscaler.rb,
lib/ruby_llm/agents/image/upscaler/dsl.rb,
lib/ruby_llm/agents/image/upscaler/execution.rb

Overview

Image upscaler for resolution enhancement

Increases the resolution of images using AI upscaling models. Supports 2x, 4x, and 8x upscaling with optional face enhancement.

Examples:

Basic usage

result = RubyLLM::Agents::ImageUpscaler.call(image: "path/to/low_res.jpg")
result.url # => "https://..." (high resolution version)

Custom upscaler class

class PhotoUpscaler < RubyLLM::Agents::ImageUpscaler
  model "real-esrgan"
  scale 4
  face_enhance true

  description "Upscales photos with face enhancement"
end

result = PhotoUpscaler.call(image: portrait_photo)
result.size # => "4096x4096" (if input was 1024x1024)

Defined Under Namespace

Modules: DSL, Execution

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Methods included from Execution

#execute

Constructor Details

#initialize(image:, **options) ⇒ ImageUpscaler

Initialize a new image upscaler instance

Parameters:

  • image (String, IO)

    Source image (path, URL, or IO object)

  • options (Hash)

    Additional options

Options Hash (**options):

  • :model (String)

    Model to use

  • :scale (Integer)

    Upscale factor (2, 4, or 8)

  • :face_enhance (Boolean)

    Enable face enhancement

  • :denoise_strength (Float)

    Denoising strength (0.0-1.0)

  • :tenant (Object)

    Tenant for multi-tenancy



67
68
69
70
71
# File 'lib/ruby_llm/agents/image/upscaler.rb', line 67

def initialize(image:, **options)
  @image = image
  @options = options
  @tenant_id = nil
end

Instance Attribute Details

#imageObject (readonly)

Returns the value of attribute image.



56
57
58
# File 'lib/ruby_llm/agents/image/upscaler.rb', line 56

def image
  @image
end

#optionsObject (readonly)

Returns the value of attribute options.



56
57
58
# File 'lib/ruby_llm/agents/image/upscaler.rb', line 56

def options
  @options
end

#tenant_idObject (readonly)

Returns the value of attribute tenant_id.



56
57
58
# File 'lib/ruby_llm/agents/image/upscaler.rb', line 56

def tenant_id
  @tenant_id
end

Class Method Details

.call(image:, **options) ⇒ ImageUpscaleResult

Execute image upscaling

Parameters:

  • image (String, IO)

    Path, URL, or IO object of the source image

  • options (Hash)

    Additional options (model, scale, etc.)

Returns:



39
40
41
# File 'lib/ruby_llm/agents/image/upscaler.rb', line 39

def call(image:, **options)
  new(image: image, **options).call
end

.inherited(subclass) ⇒ Object

Ensure subclasses inherit DSL settings



44
45
46
47
48
49
50
51
52
53
# File 'lib/ruby_llm/agents/image/upscaler.rb', line 44

def inherited(subclass)
  super
  subclass.instance_variable_set(:@model, @model)
  subclass.instance_variable_set(:@scale, @scale)
  subclass.instance_variable_set(:@face_enhance, @face_enhance)
  subclass.instance_variable_set(:@denoise_strength, @denoise_strength)
  subclass.instance_variable_set(:@version, @version)
  subclass.instance_variable_set(:@description, @description)
  subclass.instance_variable_set(:@cache_ttl, @cache_ttl)
end

Instance Method Details

#callImageUpscaleResult

Execute the image upscaling

Returns:



76
77
78
# File 'lib/ruby_llm/agents/image/upscaler.rb', line 76

def call
  execute
end