-
-
Save richardgrantserverless/104458360b2e619281d73165fb4b26ed to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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