Skip to content
Permalink
Branch: master
Find file Copy path
Find file Copy path
Fetching contributors…
Cannot retrieve contributors at this time
34 lines (26 sloc) 909 Bytes
import numpy
import requests
from sagemaker_containers.beta.framework import (content_types, encoders)
class SagemakerServerError(Exception):
def __init__(self, message):
self.message = message
'''
A basic Sagemaker serving proxy
'''
class SagemakerProxy(object):
def __init__(self,endpoint=None):
print("endpoint:",endpoint)
self.endpoint=endpoint
def predict(self,X,features_names):
print("predict")
r = requests.post(
self.endpoint+"/invocations",
json = X.tolist())
if r.status_code == 200:
result = encoders.decode(r.content,r.headers.get('content-type'))
if len(result.shape) == 1:
result = numpy.expand_dims(result, axis=0)
return result
else:
print("Error from server:",r)
raise SagemakerServerError(r.json())
You can’t perform that action at this time.