Spaces:
Sleeping
Sleeping
Clement Vachet
commited on
Commit
·
b51f064
1
Parent(s):
0626826
Add lambda function
Browse files
lambda.py
ADDED
@@ -0,0 +1,26 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
from classification.classifier import Classifier
|
2 |
+
import json
|
3 |
+
|
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 |
+
response = cls.load_and_test(data)
|
13 |
+
print("Lambda response: ", response)
|
14 |
+
|
15 |
+
return {
|
16 |
+
'statusCode': 200,
|
17 |
+
'body': json.dumps({
|
18 |
+
'predictions': response["predictions"],
|
19 |
+
'probabilities': response["probabilities"]
|
20 |
+
})
|
21 |
+
}
|
22 |
+
except Exception as e:
|
23 |
+
return {
|
24 |
+
'statusCode': 500,
|
25 |
+
'body': json.dumps({'error': str(e)})
|
26 |
+
}
|