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
{ | |
"Version": "2012-10-17", | |
"Statement": [ | |
{ | |
"Sid": "S3Access", | |
"Effect": "Allow", | |
"Action": "s3:GetObject", | |
"Resource": "arn:aws:s3:::your-bucket-name/*" | |
} | |
] |
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
{ | |
"Version": "2012-10-17", | |
"Statement": [ | |
{ | |
"Sid": "S3Access", | |
"Effect": "Allow", | |
"Action": "s3:PutObject", | |
"Resource": "arn:aws:s3:::your-bucket-name/*" | |
} | |
] |
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
{ | |
"Version": "2012-10-17", | |
"Statement": [ | |
{ | |
"Action": "textract:DetectDocumentText", | |
"Resource": "*", | |
"Effect": "Allow", | |
"Sid": "DetectDocumentText" | |
} | |
] |
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
s3 = boto3.client('s3') | |
s3.put_object(Bucket=your_output_bucket_name, Key=file_name, Body=text_to_upload.encode()) |
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 os | |
os.environ[‘your-api-key-name’] |
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
mkdir package_layer | |
cd package_layer | |
mkdir python | |
pip install package -t python/ | |
zip -r9 ~/path_to_zip/package_layer.zip python/ |
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
def format_ocr_response(response): | |
output_string = str() | |
for item in response["Blocks"]: | |
if item["BlockType"] == "LINE": | |
output_string = output_string + item["Text"] | |
output_string = output_string + '\n' | |
return output_string |
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 | |
file_obj = event["Records"][0] # get the current event | |
bucketname = str(file_obj["s3"]["bucket"]["name"]) #get bucket name from event | |
filename = str(file_obj["s3"]["object"]["key"]) #get file name from event | |
textract = boto3.client("textract") | |
response = textract.detect_document_text( | |
Document={ | |
"S3Object": { |
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
def lambda_handler(event, context): | |
if event: # event is not None when S3 receives a document | |
print(event["Records"][0]) # print current event |
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 os | |
import openai | |
openai.api_key = 'OPEN_AI_API_KEY' | |
response = openai.Edit.create( | |
model="text-davinci-edit-001", | |
input="Meeting Notes\n1/30/23\nIn attendance: Bob, Chip\nBob's 3 point plan - 1. Build cool stuff 2, work with Awesome people 3, eat lots of pizza Tasks for Bob - • Write blog\nEdit blog\n• Order a Pizza\nbob favorite pizza toppings: • pineapple\n8 ham\n•mushroms\n", | |
instruction="Fix the grammar and format as Markdown.", | |
temperature=0.5, |
NewerOlder