Skip to content

Instantly share code, notes, and snippets.

@kkrishnan90
Created October 23, 2021 05:15
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save kkrishnan90/500a9a522be7e9945c98480ad45a05bf to your computer and use it in GitHub Desktop.
Save kkrishnan90/500a9a522be7e9945c98480ad45a05bf to your computer and use it in GitHub Desktop.
from flask import escape
from flask import jsonify
def hello_http(request):
request_json = request.get_json(silent=True)
request_args = request.args
if request_json and 'image' in request_json:
res = detect_handwritten_ocr_uri(request_json['image'])
else:
res = "Error in payload data. Attach image"
return jsonify({"result":res})
# [START vision_handwritten_ocr_gcs_beta]
def detect_handwritten_ocr_uri(uri):
from google.cloud import vision_v1p3beta1 as vision
client = vision.ImageAnnotatorClient()
image = vision.Image()
image.source.image_uri = uri
image_context = vision.ImageContext(
language_hints=['en-t-i0-handwrit'])
response = client.document_text_detection(image=image,
image_context=image_context)
print('Full Text: {}'.format(response.full_text_annotation.text))
return response.full_text_annotation.text
if response.error.message:
raise Exception(
'{}\nFor more info on error messages, check: '
'https://cloud.google.com/apis/design/errors'.format(
response.error.message))
# [END vision_handwritten_ocr_gcs_beta]
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment