[302778]: / request_handling.py

Download this file

32 lines (26 with data), 997 Bytes

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
import argparse
from google.cloud import vision
from google.cloud.vision import types
import io
from gcloud import storage
def create_uri(bucket_name, blob_name):
return "gs://" + bucket_name + "/" + blob_name
def get_text(image_uri):
client = vision.ImageAnnotatorClient()
image = vision.types.Image()
image.source.image_uri = image_uri
response = client.document_text_detection(image=image)
document = response
return response
def get_all_text(bucket_name, directory):
client = storage.Client(project='medical-extraction')
bucket = client.get_bucket(bucket_name)
full_text = []
for blob in bucket.list_blobs(prefix=directory):
print("----------------------" + blob.name + "---------------------------")
next_doc = get_text(create_uri(bucket_name,blob.name)).full_text_annotation.text.splitlines()
full_text += next_doc
# print(full_text)
for line in next_doc:
print (line)
return full_text