Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Decode binData before sending it to Predict function #993

Merged
merged 5 commits into from
Oct 25, 2019
Merged
Show file tree
Hide file tree
Changes from 4 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions python/seldon_core/flask_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,9 @@ def get_request() -> Dict:
raise SeldonMicroserviceException("Can't find JSON in data")
if message is None:
raise SeldonMicroserviceException("Invalid Data Format - empty JSON")
if 'binData' in message and message['binData'] is not None:
binData = message['binData']
message['binData'] = base64.b64decode(binData).decode("utf-8")
axsaucedo marked this conversation as resolved.
Show resolved Hide resolved
lennon310 marked this conversation as resolved.
Show resolved Hide resolved
return message


Expand Down
7 changes: 3 additions & 4 deletions python/tests/test_model_microservice.py
Original file line number Diff line number Diff line change
Expand Up @@ -418,9 +418,8 @@ def test_model_bin_data():
bdata_base64 = base64.b64encode(bdata).decode("utf-8")
rv = client.get('/predict?json={"binData":"' + bdata_base64 + '"}')
j = json.loads(rv.data)
return_data = base64.b64encode(base64.b64encode(bdata)).decode("utf-8")
assert rv.status_code == 200
assert j["binData"] == return_data
assert j["binData"] == bdata_base64
assert j["meta"]["tags"] == {"mytag": 1}
assert j["meta"]["metrics"][0]["key"] == user_object.metrics()[0]["key"]
assert j["meta"]["metrics"][0]["value"] == user_object.metrics()[0]["value"]
Expand All @@ -430,8 +429,8 @@ def test_model_bin_data_nparray():
user_object = UserObject(ret_nparray=True)
app = get_rest_microservice(user_object)
client = app.test_client()
encoded = base64.b64encode(b"1234")
rv = client.get('/predict?json={"binData":"' + str(encoded) + '"}')
encoded = base64.b64encode(b"1234").decode("utf-8")
rv = client.get('/predict?json={"binData":"' + encoded + '"}')
j = json.loads(rv.data)
print(j)
assert rv.status_code == 200
Expand Down