Class: Roseflow::StabilityAI::Operations::Upscale

Inherits:
Base
  • Object
show all
Defined in:
lib/roseflow/stabilityai/operations/upscale.rb

Instance Method Summary collapse

Methods inherited from Base

#multipart?

Instance Method Details

#bodyObject



39
40
41
42
43
44
45
46
# File 'lib/roseflow/stabilityai/operations/upscale.rb', line 39

def body
  case upscale_type.to_sym
  when :sdx4
    sdx4_body
  when :esrgan
    esrgan_body
  end
end

#esrgan_bodyObject



61
62
63
64
65
66
67
68
69
# File 'lib/roseflow/stabilityai/operations/upscale.rb', line 61

def esrgan_body
  initial = to_h.except(*excluded_keys)
  esrgan.to_h.merge(
    image: Faraday::Multipart::ParamPart.new(
      esrgan.image,
      "image/png",
    ),
  ).merge(initial)
end

#excluded_keysObject



35
36
37
# File 'lib/roseflow/stabilityai/operations/upscale.rb', line 35

def excluded_keys
  [:path, :engine_id, :text_prompts, :upscale_type, :esrgan, :sdx4]
end

#pathObject



31
32
33
# File 'lib/roseflow/stabilityai/operations/upscale.rb', line 31

def path
  "/v1/generation/#{engine_id}/image-to-image/upscale"
end

#sdx4_bodyObject



48
49
50
51
52
53
54
55
56
57
58
59
# File 'lib/roseflow/stabilityai/operations/upscale.rb', line 48

def sdx4_body
  initial = to_h.except(*excluded_keys)
  sdx4.to_h.merge(
    image: Faraday::Multipart::ParamPart.new(
      sdx4.image,
      "image/png",
    ),
    text_prompts: sdx4.text_prompts.each_with_index.map do |item, index|
      [index, item.to_h]
    end.to_h,
  ).merge(initial)
end

#typeObject



71
72
73
# File 'lib/roseflow/stabilityai/operations/upscale.rb', line 71

def type
  :upscale
end