File size: 1,103 Bytes
9ecca49
 
 
 
b51f064
9ecca49
b51f064
 
 
 
9ecca49
70c8769
b51f064
9ecca49
 
 
 
 
 
 
 
 
 
b51f064
70c8769
9ecca49
70c8769
 
b51f064
70c8769
b51f064
9ecca49
 
 
 
 
b51f064
 
9ecca49
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
32
33
34
35
36
37
38
39
40
"""
AWS Lambda function
"""

import json
from classification.classifier import Classifier


cls = Classifier()


# Lambda handler (proxy integration option unchecked on AWS API Gateway)
def lambda_handler(event, context):
    """
    Lambda handler (proxy integration option unchecked on AWS API Gateway)

    Args:
        event (dict): The event that triggered the Lambda function.
        context (LambdaContext): Information about the execution environment.

    Returns:
        dict: The response to be returned from the Lambda function.
    """

    try:
        features = event.get("features", {})
        if not features:
            raise ValueError("'features' key missing")

        response = cls.load_and_test(features)
        return {
            "statusCode": 200,
            "headers": {"Content-Type": "application/json"},
            "body": json.dumps(
                {"predictions": response["predictions"], "probabilities": response["probabilities"]}
            ),
        }
    except Exception as e:
        return {"statusCode": 500, "body": json.dumps({"error": str(e)})}