-
Notifications
You must be signed in to change notification settings - Fork 5
/
Copy pathhandler.py
45 lines (31 loc) · 1.1 KB
/
handler.py
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
41
42
43
44
45
import json
import pickle
import numpy as np
model_name = 'flower-v1.pkl'
model_pk = pickle.load(open(model_name, 'rb'))
def predict(event= None, context= None):
body = {
"message": "OK",
}
if 'queryStringParameters' in event.keys():
params = event['queryStringParameters']
sepal_length = float(params['sepal_length'])
sepal_width = float(params["sepal_width"])
petal_length = float(params["petal_length"])
petal_width = float(params["petal_width"])
data = np.array([[sepal_length, sepal_width, petal_length, petal_width]])
prediction = model_pk.predict(data)
body['prediction'] = prediction
else:
body['message'] = 'queryStringParameters not in event.'
response = {
"statusCode": 200,
"body": prediction[0],
"headers": {
"Content-Type": 'application/json',
"Access-Control-Allow-Origin": "*"
}
}
return response
data = {"queryStringParameters": {"sepal_length": 200000, "sepal_width": 10, "petal_length": 4, "petal_width": 1}}
print(predict(data))