Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Google vision API: Slow response times #28234

Open
alejandrouda opened this issue Jan 13, 2025 · 0 comments
Open

Google vision API: Slow response times #28234

alejandrouda opened this issue Jan 13, 2025 · 0 comments
Assignees

Comments

@alejandrouda
Copy link

Thanks for stopping by to let us know something could be better!

PLEASE READ: If you have a support contract with Google, please create an issue in the support console instead of filing on GitHub. This will ensure a timely response.

Please run down the following list and make sure you've tried the usual "quick fixes":

If you are still having issues, please be sure to include as much information as possible:

Environment details

  • OS: MacOS
  • Ruby version: 3.3.6
  • Gem name and version: google-cloud-vision (1.5.1)

Steps to reproduce

  1. Call the API and pass an image
  2. The API call works and I get the response, but the response time is huge (approx 77 seconds). If I use the Rest API, I get very quick response for the same image.

Code example

require "google/cloud/vision"
    require "time"
    require "base64"

    # Initialize the Vision API client
    vision = Google::Cloud::Vision.image_annotator

    image_path = Rails.root.join("app", "assets", "images", "cookie.png")
    image = File.open(image_path, "rb")


    # Cloudinary URL of the image
    # image_url = "https://res.cloudinary.com/dqstmox0s/image/upload/v1736173018/cookie_zqljqk.png"

    # Start measuring time
    start_time = Time.now

    # Perform text detection (OCR) on the image from the Cloudinary URL
    begin
      puts "Calling Vision API..."
      # Sending image URL for OCR
      response = vision.text_detection image: image

      # End measuring time
      end_time = Time.now
      duration = end_time - start_time

      # Print the time it took
      puts "OCR request took #{duration} seconds."

      # The response contains multiple results in 'text_annotations'
      if response.responses.any?
        # Get the text annotations from the first response
        annotations = response.responses.first.text_annotations

        # Print the detected text
        raw_text = annotations.first.description
        split_text = raw_text.split("\n")
        text_to_match = split_text[0]
        puts "Detected text:"
        p text_to_match
      else
        puts "No text annotations found."
      end
    rescue StandardError => e
      puts "An error occurred: #{e.message}"
    end

Full backtrace

Calling Vision API...
OCR request took 76.694712 seconds.
Detected text:
"Image text"

Could there be some kind of configuration issue? I was thinking which endpoint it's calling (Europe or US), but this seems to work properly with the generic endpoint when using the REST API.

Thanks for your help!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants