Skip to content

Instantly share code, notes, and snippets.

@shabazpatel
Created June 14, 2018 01:38
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 shabazpatel/4a7b91cef2bfd2f90c9e536e7500b2c0 to your computer and use it in GitHub Desktop.
Save shabazpatel/4a7b91cef2bfd2f90c9e536e7500b2c0 to your computer and use it in GitHub Desktop.
Code for serverless deployments
[...]
def handler(event, context):
# take input pd data frame and return dictionary with classificaiton
input = json.loads(event['body'])['input']
output_response = {"statusCode": 200, "headers": {"Content-Type": "application/json"}}
try:
# Inference
y_pred = iris_model.predict(input)
y_pred = [round(value) for value in y_pred]
prediction_result = {'Species': Species_class_map[y_pred[0]]}
output_response['body'] = json.dumps(prediction_result)
except Exception as e:
output_response["statusCode"] = 500
return output_response
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment