Skip to content

Commit

Permalink
Merge pull request #4 from marlowetutor/refactor/DEVEVANG-100-python-…
Browse files Browse the repository at this point in the history
…rewrite

Refactor/devevang 100 python rewrite
  • Loading branch information
carnellj-genesys authored Oct 3, 2024
2 parents 3c4a412 + 25fd35e commit 3143da2
Show file tree
Hide file tree
Showing 31 changed files with 367 additions and 20,114 deletions.
19,789 changes: 0 additions & 19,789 deletions blueprint/aws-classifier-lambda/package-lock.json

This file was deleted.

38 changes: 0 additions & 38 deletions blueprint/aws-classifier-lambda/package.json

This file was deleted.

44 changes: 0 additions & 44 deletions blueprint/aws-classifier-lambda/serverless.ts

This file was deleted.

This file was deleted.

This file was deleted.

This file was deleted.

This file was deleted.

This file was deleted.

This file was deleted.

1 change: 0 additions & 1 deletion blueprint/aws-classifier-lambda/src/functions/index.ts

This file was deleted.

12 changes: 0 additions & 12 deletions blueprint/aws-classifier-lambda/src/libs/apiGateway.ts

This file was deleted.

3 changes: 0 additions & 3 deletions blueprint/aws-classifier-lambda/src/libs/handlerResolver.ts

This file was deleted.

6 changes: 0 additions & 6 deletions blueprint/aws-classifier-lambda/src/libs/lambda.ts

This file was deleted.

24 changes: 0 additions & 24 deletions blueprint/aws-classifier-lambda/tsconfig.json

This file was deleted.

9 changes: 0 additions & 9 deletions blueprint/aws-classifier-lambda/tsconfig.paths.json

This file was deleted.

57 changes: 0 additions & 57 deletions blueprint/aws-classifier-lambda/webpack.config.js

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
"s3:ListBucket"
],
"Resource": [
"arn:aws:s3:::nintca-test-bucket"
"arn:aws:s3:::inintca-test-bucket"
],
"Effect": "Allow"
}
Expand Down
Empty file.
56 changes: 56 additions & 0 deletions blueprint/aws-sam-email-classifier/emailclassifier/app.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
import json
import boto3
import logging
import os

logger = logging.getLogger()
logger.setLevel("INFO")

def lambda_handler(event, context):

try:
account_id = os.getenv('AWS_ACCOUNT_ID')
region = os.getenv('AWS_REGION')
confidence_threshold = os.getenv('COMPREHEND_CONFIDENCE_THRESHOLD')
if confidence_threshold == None:
raise Exception("Please set the confidence threshold in the environment variables.")

request_body_string = event.get("body")
if request_body_string == None:
raise Exception("Please use the correct format for the request body.")

comprehend_object = boto3.client("comprehend")
endpoint_arn = f'arn:aws:comprehend:{region}:{account_id}:document-classifier-endpoint/emailclassifier'
response_object = comprehend_object.classify_document(
Text=request_body_string,
EndpointArn=endpoint_arn
)

logger.info(json.dumps(response_object))
classes_list = response_object.get("Classes")

if (len(classes_list) > 0):
# get the first item with the highest confidence/score
queue_name = classes_list[0].get("Name")
confidence = classes_list[0].get("Score")

# confidence threshold reached
if (float(confidence) > float(confidence_threshold)):
response_body = {"QueueName": queue_name , "Confidence": confidence}

# confidence threshold not reached, then an empty string is returned.
if (float(confidence) < float(confidence_threshold)):
response_body = {"Message": "Classification results did not meet the confidence threshold."}

return {
"statusCode": 200,
"body": json.dumps(response_body),
}

except Exception as err:
e = f'Error: {str(err)}'
logger.error(e)
return {
"statusCode": 502,
"body": json.dumps({"Message":e}),
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
requests
boto3
Loading

0 comments on commit 3143da2

Please sign in to comment.