GithubHelp home page GithubHelp logo

Comments (13)

alixhami avatar alixhami commented on June 16, 2024

Hi Pierre, thanks for submitting an issue. Could you paste your whole error? This will help me see which line causes the error. Also what is the command you are running in the last step?

from ruby-docs-samples.

elcortez avatar elcortez commented on June 16, 2024

Thank you so much for your answer :)
Here is a screen capture of the error stack
capture d ecran 2018-07-24 a 19 38 23

Just to check, i removed the argument in line 43
operation = vision.async_batch_annotate_files [async_request]
So i changed this line to
operation = vision.async_batch_annotate_files

Which gave me the second error
ArgumentError (wrong number of arguments (given 0, expected 1..2))

from ruby-docs-samples.

alixhami avatar alixhami commented on June 16, 2024

Thanks! I've been away from my laptop for most of today, so I'll have to recreate your error later, but before I do that is there a reason you need to run this from rails? The sample file is set up to run similar to these samples.

from ruby-docs-samples.

elcortez avatar elcortez commented on June 16, 2024

I'm running it from rails because I'm trying to set up an application that dynamically runs OCR on invoices for my customers.
I will check your samples later, maybe I can make it work a different way. I'll keep you posted.
Thanks for your time

from ruby-docs-samples.

alixhami avatar alixhami commented on June 16, 2024

Makes sense. I'm looking into this again and I don't believe I have enough information to recreate. Could you paste your file into a gist or put the project on github? I'll need to look into how many arguments you're giving each method. It looks like you're no longer giving the arguments to the detect_pdf_gcs method, since you're calling it from the rails console without arguments.

from ruby-docs-samples.

elcortez avatar elcortez commented on June 16, 2024

Here is a sample of my code until the error message appears

require "google/cloud/vision"
require "google/cloud/storage"

class GoogleLib
  def self.launch_ocr(object)
    credentials = self.generate_credentials 
    # a method returning a hash with the informations from the gcs.json provided by google
    filename = object.storage_filename 
    # the name of the file inside the google storage bucket

    vision = Google::Cloud::Vision.new(
      project: credentials['project_id'],
      credentials: credentials
    )

    gcs_source_uri = "#{credentials['bucket_uri']}/#{filename}"
    gcs_destination_uri = credentials['bucket_uri']
    project_id = credentials['project_id']

    # Supported mime_types are: 'application/pdf' and 'image/tiff'
    input_config = {
      gcs_source: { uri: gcs_source_uri },
      mime_type:  "application/pdf"
    }

    output_config = {
      gcs_destination: { uri: gcs_destination_uri },
      batch_size:      2  # number of pages to group per json output file
    }

    async_request = {
      input_config:  input_config,
      features:      [{ type: "DOCUMENT_TEXT_DETECTION" }],
      output_config: output_config
    }

    operation = vision.async_batch_annotate_files([async_request])

The last line is the line where the error ArgumentError (wrong number of arguments (given 6, expected 0)) occurs

from ruby-docs-samples.

alixhami avatar alixhami commented on June 16, 2024

I'm not sure what the issue is because I'm not able to recreate. It might be however you are handling the credentials because that's the only thing I don't have that is in your code.

@frankyn do you know why this would happen? The error says there were 6 arguments given, but there weren't 6 arguments given on the line that raises the error. The stack trace is not detailed enough to tell.

from ruby-docs-samples.

elcortez avatar elcortez commented on June 16, 2024

A few more informations about this issue.
This is what the credentials look like after I generate them.

{
   "type"   =>"service_account",
   "client_id"   =>"...",
   "project_id"   =>"...",
   "private_key_id"   =>"...",
   "private_key"   =>"...",
   "client_email"   =>"...",
   "auth_uri"   =>"https://accounts.google.com/o/oauth2/auth",
   "token_uri"   =>"https://accounts.google.com/o/oauth2/token",
   "auth_provider_x509_cert_url"   =>"https://www.googleapis.com/oauth2/v1/certs",
   "client_x509_cert_url"   =>"....",
   "bucket_uri"   =>"...."
}

Also I integrated the gem directly in my local folder to go a little bit deeper.

Inside the file image_annotator_client.rb, there is the function async_batch_annotate_files

In here, the req variable looks like this

{
:requests=>   [
      {
:input_config=>         {
:gcs_source=>            {
:               uri=>"...."
            },
:mime_type=>"application/pdf"
         },
:features=>         [
            {
:type=>"DOCUMENT_TEXT_DETECTION"
            }
         ],
:output_config=>         {
:gcs_destination=>            {
:               uri=>"..."
            },
:batch_size=>2
         }
      }
   ]
}

The error seems to appear at this line
req = Google::Gax::to_proto(req, Google::Cloud::Vision::V1::AsyncBatchAnnotateFilesRequest)
This is where I have the ArgumentError: wrong number of arguments (given 6, expected 0) error.

Hope this helps. I'll keep looking...

from ruby-docs-samples.

elcortez avatar elcortez commented on June 16, 2024

So, I tried it again in pure ruby
I cloned this folder : https://github.com/GoogleCloudPlatform/ruby-docs-samples/tree/master/vision

then called ruby detect_pdf.rb "gs://<BUCKET_NAME>/<FILENAME>" "gs://<BUCKET_NAME>"

It returned the same error but with more stack trace
Traceback (most recent call last):

	25: from detect_pdf.rb:89:in `<main>'
	24: from detect_pdf.rb:47:in `detect_pdf_gcs'
	23: from /Users/pierrehersant/.rbenv/versions/2.5.0/lib/ruby/gems/2.5.0/gems/google-cloud-vision-0.30.0/lib/google/cloud/vision/project.rb:345:in `async_batch_annotate_files'
	22: from /Users/pierrehersant/.rbenv/versions/2.5.0/lib/ruby/gems/2.5.0/gems/google-cloud-vision-0.30.0/lib/google/cloud/vision/v1/image_annotator_client.rb:284:in `async_batch_annotate_files'
	21: from /Users/pierrehersant/.rbenv/versions/2.5.0/lib/ruby/gems/2.5.0/gems/google-gax-1.3.0/lib/google/gax/util.rb:63:in `to_proto'
	20: from /Users/pierrehersant/.rbenv/versions/2.5.0/lib/ruby/gems/2.5.0/gems/google-gax-1.3.0/lib/google/gax/util.rb:81:in `coerce_submessages'
	19: from /Users/pierrehersant/.rbenv/versions/2.5.0/lib/ruby/gems/2.5.0/gems/google-gax-1.3.0/lib/google/gax/util.rb:81:in `each'
	18: from /Users/pierrehersant/.rbenv/versions/2.5.0/lib/ruby/gems/2.5.0/gems/google-gax-1.3.0/lib/google/gax/util.rb:84:in `block in coerce_submessages'
	17: from /Users/pierrehersant/.rbenv/versions/2.5.0/lib/ruby/gems/2.5.0/gems/google-gax-1.3.0/lib/google/gax/util.rb:109:in `coerce_submessage'
	16: from /Users/pierrehersant/.rbenv/versions/2.5.0/lib/ruby/gems/2.5.0/gems/google-gax-1.3.0/lib/google/gax/util.rb:132:in `coerce_array'
	15: from /Users/pierrehersant/.rbenv/versions/2.5.0/lib/ruby/gems/2.5.0/gems/google-gax-1.3.0/lib/google/gax/util.rb:132:in `map'
	14: from /Users/pierrehersant/.rbenv/versions/2.5.0/lib/ruby/gems/2.5.0/gems/google-gax-1.3.0/lib/google/gax/util.rb:133:in `block in coerce_array'
	13: from /Users/pierrehersant/.rbenv/versions/2.5.0/lib/ruby/gems/2.5.0/gems/google-gax-1.3.0/lib/google/gax/util.rb:159:in `coerce'
	12: from /Users/pierrehersant/.rbenv/versions/2.5.0/lib/ruby/gems/2.5.0/gems/google-gax-1.3.0/lib/google/gax/util.rb:63:in `to_proto'
	11: from /Users/pierrehersant/.rbenv/versions/2.5.0/lib/ruby/gems/2.5.0/gems/google-gax-1.3.0/lib/google/gax/util.rb:81:in `coerce_submessages'
	10: from /Users/pierrehersant/.rbenv/versions/2.5.0/lib/ruby/gems/2.5.0/gems/google-gax-1.3.0/lib/google/gax/util.rb:81:in `each'
	 9: from /Users/pierrehersant/.rbenv/versions/2.5.0/lib/ruby/gems/2.5.0/gems/google-gax-1.3.0/lib/google/gax/util.rb:84:in `block in coerce_submessages'
	 8: from /Users/pierrehersant/.rbenv/versions/2.5.0/lib/ruby/gems/2.5.0/gems/google-gax-1.3.0/lib/google/gax/util.rb:109:in `coerce_submessage'
	 7: from /Users/pierrehersant/.rbenv/versions/2.5.0/lib/ruby/gems/2.5.0/gems/google-gax-1.3.0/lib/google/gax/util.rb:132:in `coerce_array'
	 6: from /Users/pierrehersant/.rbenv/versions/2.5.0/lib/ruby/gems/2.5.0/gems/google-gax-1.3.0/lib/google/gax/util.rb:132:in `map'
	 5: from /Users/pierrehersant/.rbenv/versions/2.5.0/lib/ruby/gems/2.5.0/gems/google-gax-1.3.0/lib/google/gax/util.rb:133:in `block in coerce_array'
	 4: from /Users/pierrehersant/.rbenv/versions/2.5.0/lib/ruby/gems/2.5.0/gems/google-gax-1.3.0/lib/google/gax/util.rb:159:in `coerce'
	 3: from /Users/pierrehersant/.rbenv/versions/2.5.0/lib/ruby/gems/2.5.0/gems/google-gax-1.3.0/lib/google/gax/util.rb:64:in `to_proto'
	 2: from /Users/pierrehersant/.rbenv/versions/2.5.0/lib/ruby/gems/2.5.0/gems/google-gax-1.3.0/lib/google/gax/util.rb:64:in `new'
	 1: from /Users/pierrehersant/.rbenv/versions/2.5.0/lib/ruby/gems/2.5.0/gems/google-gax-1.3.0/lib/google/gax/util.rb:64:in `initialize'
/Users/pierrehersant/.rbenv/versions/2.5.0/lib/ruby/gems/2.5.0/gems/google-gax-1.3.0/lib/google/gax/util.rb:64:in `to_sym': wrong number of arguments (given 6, expected 0) (ArgumentError)

from ruby-docs-samples.

frankyn avatar frankyn commented on June 16, 2024

Hi @elcortez, I also tried to reproduce the issue and wasn't successful. Out of curiosity could you add your Gemfile.lock? It might be a version issue. Potentially bundle update may help but it's just a guess right now.

from ruby-docs-samples.

elcortez avatar elcortez commented on June 16, 2024

In the end, it was because of the ruby version.

The detection worked when I switched back to 2.4.0;
But the error keeps coming if I use the 2.5.0.

Hopes this helps, and hopefully these samples will work later for the 2.5.0 version

Thanks for your time !!!

from ruby-docs-samples.

frankyn avatar frankyn commented on June 16, 2024

I'm glad you were able to patch the issue by moving down a version. Could you share the Gemfile.lock that didn't work for you? I'm using 2.5.1 right now and still successful.

Thank you!

from ruby-docs-samples.

elcortez avatar elcortez commented on June 16, 2024

Sure, here it is.

GEM
  remote: https://rubygems.org/
  specs:
    addressable (2.5.2)
      public_suffix (>= 2.0.2, < 4.0)
    declarative (0.0.10)
    declarative-option (0.1.0)
    diff-lcs (1.3)
    digest-crc (0.4.1)
    faraday (0.15.2)
      multipart-post (>= 1.2, < 3)
    google-api-client (0.19.8)
      addressable (~> 2.5, >= 2.5.1)
      googleauth (>= 0.5, < 0.7.0)
      httpclient (>= 2.8.1, < 3.0)
      mime-types (~> 3.0)
      representable (~> 3.0)
      retriable (>= 2.0, < 4.0)
    google-cloud-core (1.2.2)
      google-cloud-env (~> 1.0)
    google-cloud-env (1.0.2)
      faraday (~> 0.11)
    google-cloud-storage (1.10.0)
      digest-crc (~> 0.4)
      google-api-client (~> 0.19.0)
      google-cloud-core (~> 1.2)
      googleauth (~> 0.6.2)
    google-cloud-vision (0.30.0)
      google-cloud-core (~> 1.2)
      google-gax (~> 1.3)
    google-gax (1.3.0)
      google-protobuf (~> 3.2)
      googleapis-common-protos (>= 1.3.5, < 2.0)
      googleauth (~> 0.6.2)
      grpc (>= 1.7.2, < 2.0)
      rly (~> 0.2.3)
    google-protobuf (3.6.0)
    googleapis-common-protos (1.3.7)
      google-protobuf (~> 3.0)
      googleapis-common-protos-types (~> 1.0)
      grpc (~> 1.0)
    googleapis-common-protos-types (1.0.1)
      google-protobuf (~> 3.0)
    googleauth (0.6.2)
      faraday (~> 0.12)
      jwt (>= 1.4, < 3.0)
      logging (~> 2.0)
      memoist (~> 0.12)
      multi_json (~> 1.11)
      os (~> 0.9)
      signet (~> 0.7)
    grpc (1.13.0)
      google-protobuf (~> 3.1)
      googleapis-common-protos-types (~> 1.0.0)
    httpclient (2.8.3)
    jwt (2.1.0)
    little-plugger (1.1.4)
    logging (2.2.2)
      little-plugger (~> 1.1)
      multi_json (~> 1.10)
    memoist (0.16.0)
    mime-types (3.1)
      mime-types-data (~> 3.2015)
    mime-types-data (3.2016.0521)
    multi_json (1.13.1)
    multipart-post (2.0.0)
    os (0.9.6)
    public_suffix (3.0.2)
    rack (2.0.4)
    rack-test (0.8.3)
      rack (>= 1.0, < 3)
    representable (3.0.4)
      declarative (< 0.1.0)
      declarative-option (< 0.2.0)
      uber (< 0.2.0)
    retriable (3.1.1)
    rly (0.2.3)
    rmagick (2.16.0)
    rspec (3.7.0)
      rspec-core (~> 3.7.0)
      rspec-expectations (~> 3.7.0)
      rspec-mocks (~> 3.7.0)
    rspec-core (3.7.1)
      rspec-support (~> 3.7.0)
    rspec-expectations (3.7.0)
      diff-lcs (>= 1.2.0, < 2.0)
      rspec-support (~> 3.7.0)
    rspec-mocks (3.7.0)
      diff-lcs (>= 1.2.0, < 2.0)
      rspec-support (~> 3.7.0)
    rspec-support (3.7.1)
    signet (0.8.1)
      addressable (~> 2.3)
      faraday (~> 0.9)
      jwt (>= 1.5, < 3.0)
      multi_json (~> 1.10)
    uber (0.1.0)

PLATFORMS
  ruby

DEPENDENCIES
  google-cloud-storage
  google-cloud-vision
  rack-test
  rmagick
  rspec

BUNDLED WITH
   1.16.1

from ruby-docs-samples.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.