forked from aws-samples/aws-nlp-workshop
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathlambda_sagemaker_invoke.py
34 lines (27 loc) · 1002 Bytes
/
lambda_sagemaker_invoke.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
from __future__ import print_function
import json
import urllib
import boto3
print('Loading function')
sm = boto3.client('sagemaker-runtime')
def lambda_handler(event, context):
#print("Received event: " + json.dumps(event, indent=2))
# Get the object from the event and show its content type
try:
response = sm.invoke_endpoint(
EndpointName='tensorboard-names-2018-03-20-22-40-47-154',
Body='{"name":"Pratap"}',
ContentType='application/json',
Accept='*/*')
body = response['Body']
json_str = body.read()
json_data = json.loads(json_str)
outputs = json_data['outputs']
gender = outputs['Gender']
#prediction = float(str(gender['floatVal']))
print("Prediction: (Male if Less that .5 and Female if > 0.5 ) with confidence" + str(gender['floatVal']))
return response['ContentType']
except Exception as e:
print(e)
print('Error')
raise e