提交 bbb40430 编写于 作者: B barrierye

unify predict return

上级 ccd17fd5
...@@ -62,22 +62,14 @@ class WebService(object): ...@@ -62,22 +62,14 @@ class WebService(object):
abort(400) abort(400)
try: try:
feed, fetch = self.preprocess(request.json, request.json["fetch"]) feed, fetch = self.preprocess(request.json, request.json["fetch"])
if isinstance(feed, list): if isinstance(feed, dict) and "fetch" in feed:
fetch_map_batch = self.client_service.predict(
feed_batch=feed, fetch=fetch)
fetch_map_batch = self.postprocess(
feed=request.json, fetch=fetch, fetch_map=fetch_map_batch)
for key in fetch_map_batch:
fetch_map_batch[key] = fetch_map_batch[key].tolist()
result = {"result": fetch_map_batch}
elif isinstance(feed, dict):
if "fetch" in feed:
del feed["fetch"] del feed["fetch"]
fetch_map = self.client_service.predict(feed=feed, fetch=fetch) fetch_map = self.client_service.predict(feed=feed, fetch=fetch)
for key in fetch_map: for key in fetch_map:
fetch_map[key] = fetch_map[key][0].tolist() fetch_map[key] = fetch_map[key][0].tolist()
result = self.postprocess( result = self.postprocess(
feed=request.json, fetch=fetch, fetch_map=fetch_map) feed=request.json, fetch=fetch, fetch_map=fetch_map)
result = {"result": result}
except ValueError: except ValueError:
result = {"result": "Request Value Error"} result = {"result": "Request Value Error"}
return result return result
......
...@@ -106,22 +106,14 @@ class WebService(object): ...@@ -106,22 +106,14 @@ class WebService(object):
abort(400) abort(400)
try: try:
feed, fetch = self.preprocess(request.json, request.json["fetch"]) feed, fetch = self.preprocess(request.json, request.json["fetch"])
if isinstance(feed, list): if isinstance(feed, dict) and "fetch" in feed:
fetch_map_batch = self.client.predict(
feed_batch=feed, fetch=fetch)
fetch_map_batch = self.postprocess(
feed=request.json, fetch=fetch, fetch_map=fetch_map_batch)
for key in fetch_map_batch:
fetch_map_batch[key] = fetch_map_batch[key].tolist()
result = {"result": fetch_map_batch}
elif isinstance(feed, dict):
if "fetch" in feed:
del feed["fetch"] del feed["fetch"]
fetch_map = self.client.predict(feed=feed, fetch=fetch) fetch_map = self.client.predict(feed=feed, fetch=fetch)
for key in fetch_map: for key in fetch_map:
fetch_map[key] = fetch_map[key][0].tolist() fetch_map[key] = fetch_map[key][0].tolist()
result = self.postprocess( result = self.postprocess(
feed=request.json, fetch=fetch, fetch_map=fetch_map) feed=request.json, fetch=fetch, fetch_map=fetch_map)
result = {"result": result}
except ValueError: except ValueError:
result = {"result": "Request Value Error"} result = {"result": "Request Value Error"}
return result return result
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册