Spaces:
Sleeping
Sleeping
Clement Vachet
commited on
Commit
·
70c8769
1
Parent(s):
f4e0e4a
Use features instead of body as input
Browse files- lambda_function.py +9 -4
- tests/test_lambda.py +3 -1
lambda_function.py
CHANGED
|
@@ -4,15 +4,20 @@ import json
|
|
| 4 |
|
| 5 |
cls = Classifier()
|
| 6 |
|
|
|
|
| 7 |
def lambda_handler(event, context):
|
| 8 |
-
try:
|
| 9 |
-
# Parse the input data
|
| 10 |
-
data = json.loads(event.get('body', '{}'))
|
| 11 |
|
| 12 |
-
|
|
|
|
|
|
|
|
|
|
| 13 |
|
|
|
|
| 14 |
return {
|
| 15 |
'statusCode': 200,
|
|
|
|
|
|
|
|
|
|
| 16 |
'body': json.dumps({
|
| 17 |
'predictions': response["predictions"],
|
| 18 |
'probabilities': response["probabilities"]
|
|
|
|
| 4 |
|
| 5 |
cls = Classifier()
|
| 6 |
|
| 7 |
+
# Lambda handler (proxy integration option unchecked on AWS API Gateway)
|
| 8 |
def lambda_handler(event, context):
|
|
|
|
|
|
|
|
|
|
| 9 |
|
| 10 |
+
try:
|
| 11 |
+
features = event.get('features', {})
|
| 12 |
+
if not features:
|
| 13 |
+
raise ValueError("'features' key missing")
|
| 14 |
|
| 15 |
+
response = cls.load_and_test(features)
|
| 16 |
return {
|
| 17 |
'statusCode': 200,
|
| 18 |
+
'headers': {
|
| 19 |
+
'Content-Type': 'application/json'
|
| 20 |
+
},
|
| 21 |
'body': json.dumps({
|
| 22 |
'predictions': response["predictions"],
|
| 23 |
'probabilities': response["probabilities"]
|
tests/test_lambda.py
CHANGED
|
@@ -11,7 +11,9 @@ from lambda_function import lambda_handler
|
|
| 11 |
|
| 12 |
@pytest.fixture
|
| 13 |
def event():
|
| 14 |
-
json_event = {
|
|
|
|
|
|
|
| 15 |
return json_event
|
| 16 |
|
| 17 |
@pytest.fixture
|
|
|
|
| 11 |
|
| 12 |
@pytest.fixture
|
| 13 |
def event():
|
| 14 |
+
json_event = {
|
| 15 |
+
"features": [[6.5, 3.0, 5.8, 2.2], [6.1, 2.8, 4.7, 1.2]]
|
| 16 |
+
}
|
| 17 |
return json_event
|
| 18 |
|
| 19 |
@pytest.fixture
|