iris_classification_lambda / lambda_function.py
Clement Vachet
Use features instead of body as input
70c8769
raw
history blame
822 Bytes
from classification.classifier import Classifier
import json
cls = Classifier()
# Lambda handler (proxy integration option unchecked on AWS API Gateway)
def lambda_handler(event, context):
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)})
}