From 548a0fc57258e871f3162848a5a73e372d4dd05f Mon Sep 17 00:00:00 2001 From: dongdaxiang Date: Fri, 17 Apr 2020 22:25:33 +0800 Subject: [PATCH] change web service --- python/paddle_serving_server/web_service.py | 61 ++++++++----------- .../paddle_serving_server_gpu/web_service.py | 39 +++++------- 2 files changed, 41 insertions(+), 59 deletions(-) diff --git a/python/paddle_serving_server/web_service.py b/python/paddle_serving_server/web_service.py index d91f82d4..8963aec1 100755 --- a/python/paddle_serving_server/web_service.py +++ b/python/paddle_serving_server/web_service.py @@ -55,41 +55,32 @@ class WebService(object): "{}/serving_server_conf.prototxt".format(self.model_config)) self.client_service.connect(["0.0.0.0:{}".format(self.port + 1)]) - @app_instance.route(service_name, methods=['POST']) - def get_prediction(): - if not request.json: - abort(400) - if "fetch" not in request.json: - abort(400) - try: - feed, fetch = self.preprocess(request.json, - request.json["fetch"]) - if isinstance(feed, list): - fetch_map_batch = 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"] - fetch_map = client_service.predict(feed=feed, fetch=fetch) - for key in fetch_map: - fetch_map[key] = fetch_map[key][0].tolist() - result = self.postprocess( - feed=request.json, fetch=fetch, fetch_map=fetch_map) - except ValueError: - result = {"result": "Request Value Error"} - return result - - app_instance.run(host="0.0.0.0", - port=self.port, - threaded=False, - processes=1) + def get_prediction(): + if not request.json: + abort(400) + if "fetch" not in request.json: + abort(400) + try: + feed, fetch = self.preprocess(request.json, request.json["fetch"]) + if isinstance(feed, list): + fetch_map_batch = 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"] + fetch_map = client_service.predict(feed=feed, fetch=fetch) + for key in fetch_map: + fetch_map[key] = fetch_map[key][0].tolist() + result = self.postprocess( + feed=request.json, fetch=fetch, fetch_map=fetch_map) + except ValueError: + result = {"result": "Request Value Error"} + return result def run_server(self): import socket diff --git a/python/paddle_serving_server_gpu/web_service.py b/python/paddle_serving_server_gpu/web_service.py index 4960fde1..757f3eb1 100755 --- a/python/paddle_serving_server_gpu/web_service.py +++ b/python/paddle_serving_server_gpu/web_service.py @@ -147,30 +147,21 @@ class WebService(object): self.idx = 0 - @app_instance.route(service_name, methods=['POST']) - def get_prediction(): - if not request.json: - abort(400) - if "fetch" not in request.json: - abort(400) - - self.input_queues[self.idx].put(request.json) - - self.idx += 1 - if self.idx >= len(self.gpus): - self.idx = 0 - result = self.output_queue.get() - if not isinstance(result, dict) and result == -1: - result = {"result": "Request Value Error"} - return result - - app_instance.run(host="0.0.0.0", - port=self.port, - threaded=False, - processes=1) - - for p in producer_list: - p.join() + def get_prediction(): + if not request.json: + abort(400) + if "fetch" not in request.json: + abort(400) + + self.input_queues[self.idx].put(request.json) + + self.idx += 1 + if self.idx >= len(self.gpus): + self.idx = 0 + result = self.output_queue.get() + if not isinstance(result, dict) and result == -1: + result = {"result": "Request Value Error"} + return result def run_server(self): import socket -- GitLab