Created
July 14, 2020 15:57
-
-
Save BetterProgramming/a62909208e9f6cbd0319765695ee065d to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import boto3 | |
# Document | |
s3BucketName = "<Your bucket name>" | |
documentName = "<Image with text>" | |
# Amazon Textract client | |
textract = boto3.client('textract') | |
# Call Amazon Textract | |
response = textract.detect_document_text( | |
Document={ | |
'S3Object': { | |
'Bucket': s3BucketName, | |
'Name': documentName | |
} | |
}) | |
#print(response) | |
# Print text | |
print("\nText\n========") | |
text = "" | |
for item in response["Blocks"]: | |
if item["BlockType"] == "LINE": | |
print ('\033[94m' + item["Text"] + '\033[0m') | |
text = text + " " + item["Text"] | |
# Amazon Comprehend client | |
comprehend = boto3.client('comprehendmedical') | |
# Detect medical entities | |
entities = comprehend.detect_entities(Text=text) | |
print("\nMidical Entities\n========") | |
for entity in entities["Entities"]: | |
print("- {}".format(entity["Text"])) | |
print (" Type: {}".format(entity["Type"])) | |
print (" Category: {}".format(entity["Category"])) | |
if(entity["Traits"]): | |
print(" Traits:") | |
for trait in entity["Traits"]: | |
print (" - {}".format(trait["Name"])) | |
print("\n") |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment