Skip to content

Instantly share code, notes, and snippets.

View brinnaebent's full-sized avatar

RunsData brinnaebent

View GitHub Profile
{
"Version": "2012-10-17",
"Statement": [
{
"Sid": "S3Access",
"Effect": "Allow",
"Action": "s3:GetObject",
"Resource": "arn:aws:s3:::your-bucket-name/*"
}
]
{
"Version": "2012-10-17",
"Statement": [
{
"Sid": "S3Access",
"Effect": "Allow",
"Action": "s3:PutObject",
"Resource": "arn:aws:s3:::your-bucket-name/*"
}
]
{
"Version": "2012-10-17",
"Statement": [
{
"Action": "textract:DetectDocumentText",
"Resource": "*",
"Effect": "Allow",
"Sid": "DetectDocumentText"
}
]
s3 = boto3.client('s3')
s3.put_object(Bucket=your_output_bucket_name, Key=file_name, Body=text_to_upload.encode())
import os
os.environ[‘your-api-key-name’]
mkdir package_layer
cd package_layer
mkdir python
pip install package -t python/
zip -r9 ~/path_to_zip/package_layer.zip python/
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
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": {
def lambda_handler(event, context):
if event: # event is not None when S3 receives a document
print(event["Records"][0]) # print current event
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,