Class: Lara::Images
- Inherits:
-
Object
- Object
- Lara::Images
- Defined in:
- lib/lara/images.rb
Instance Method Summary collapse
-
#initialize(client) ⇒ Images
constructor
A new instance of Images.
-
#translate(file_path:, target:, source: nil, adapt_to: nil, glossaries: nil, style: nil, text_removal: nil, no_trace: false) ⇒ String
Translates an image and returns the translated image as binary data.
-
#translate_text(file_path:, target:, source: nil, adapt_to: nil, glossaries: nil, style: nil, verbose: false, no_trace: false) ⇒ Lara::Models::ImageTextResult
Extracts and translates text from an image.
Constructor Details
#initialize(client) ⇒ Images
Returns a new instance of Images.
5 6 7 |
# File 'lib/lara/images.rb', line 5 def initialize(client) @client = client end |
Instance Method Details
#translate(file_path:, target:, source: nil, adapt_to: nil, glossaries: nil, style: nil, text_removal: nil, no_trace: false) ⇒ String
Translates an image and returns the translated image as binary data.
19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 |
# File 'lib/lara/images.rb', line 19 def translate(file_path:, target:, source: nil, adapt_to: nil, glossaries: nil, style: nil, text_removal: nil, no_trace: false) image_upload = Faraday::Multipart::FilePart.new(file_path, mime_type_for(file_path)) body = { source: source, target: target, adapt_to: adapt_to&.to_json, glossaries: glossaries&.to_json, style: style, text_removal: text_removal }.compact headers = {} headers["X-No-Trace"] = "true" if no_trace @client.post("/v2/images/translate", body: body, files: { image: image_upload }, headers: headers, raw_response: true) end |
#translate_text(file_path:, target:, source: nil, adapt_to: nil, glossaries: nil, style: nil, verbose: false, no_trace: false) ⇒ Lara::Models::ImageTextResult
Extracts and translates text from an image.
49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 |
# File 'lib/lara/images.rb', line 49 def translate_text(file_path:, target:, source: nil, adapt_to: nil, glossaries: nil, style: nil, verbose: false, no_trace: false) image_upload = Faraday::Multipart::FilePart.new(file_path, mime_type_for(file_path)) body = { source: source, target: target, adapt_to: adapt_to&.to_json, glossaries: glossaries&.to_json, style: style, verbose: verbose.to_s }.compact headers = {} headers["X-No-Trace"] = "true" if no_trace result = @client.post("/v2/images/translate-text", body: body, files: { image: image_upload }, headers: headers) Lara::Models::ImageTextResult.from_hash(result) end |