Skip to content

Instantly share code, notes, and snippets.

@richardgrantserverless
Created May 26, 2022 17:06
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save richardgrantserverless/104458360b2e619281d73165fb4b26ed to your computer and use it in GitHub Desktop.
Save richardgrantserverless/104458360b2e619281d73165fb4b26ed to your computer and use it in GitHub Desktop.
def predict(event, context):
try:
body = json.loads(event['body'])
context.log(body)
preds = infer.sentence_prediction(sentence=body['log'])
context.log(preds)
logging.info(f"prediction: {preds}")
return {
"statusCode": 200,
"headers": {
'Content-Type': 'application/json',
'Access-Control-Allow-Origin': '*',
"Access-Control-Allow-Credentials": True
},
"body": json.dumps({"prediction": preds['class']})
}
except Exception as e:
logging.error(e)
return {
"statusCode": 500,
"headers": {
'Content-Type': 'application/json',
'Access-Control-Allow-Origin': '*',
"Access-Control-Allow-Credentials": True
},
"body": json.dumps({"error": repr(e)})
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment