googleapis / googleapis/google-cloud-ruby

Google vision API: Slow response times

Open
#28,234 0 comments 0 reactions 0 assignees View on GitHub
Dominant language
Ruby
Stars
1.4k
Forks
578
Avg merge
1d 11h
Merged PRs (30d)
166

Description

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](https://cloud.google.com/support/) 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":

- Search the issues already opened: https://github.com/googleapis/google-cloud-ruby/issues
- Search StackOverflow: http://stackoverflow.com/questions/tagged/google-cloud-platform+ruby

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

```sh
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!

Contributor guide

Open the contributing guide

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.