-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathlambda_handler.py
More file actions
34 lines (28 loc) · 963 Bytes
/
Copy pathlambda_handler.py
File metadata and controls
34 lines (28 loc) · 963 Bytes
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
import json
from src.factory.onnx import ColaONNXPredictor
from src.pathconfig import PathConfig
PATHFINDER = PathConfig()
MODEL = PATHFINDER.models.joinpath("model.onnx")
predictor = ColaONNXPredictor(str(MODEL))
def handler(event, context):
"""
Lambda function handler for predicting linguistic acceptability of the given sentence
:param event: post/get request context
:param context: Context of Meta data
"""
if "resource" in event.keys():
body = event["body"]
body = json.loads(body)
# print(f"Got the input: {body['sentence']}")
response = predictor.predict(body["sentence"])
return {
"statusCode": 200,
"headers": {},
"body": json.dumps(response)
}
else:
return predictor.predict(event["sentence"])
if __name__ == "__main__":
test = {"sentence": "this is a sample sentence"}
result = handler(test, None)
print(result)