From 456abaa3dbb0ca36b80e9fefffe5c3f2e2c4b663 Mon Sep 17 00:00:00 2001 From: shenyuhan Date: Thu, 21 Nov 2019 11:38:20 +0800 Subject: [PATCH] modify chinese tips --- paddlehub/serving/app_single.py | 10 +++--- .../serving/model_service/model_manage.py | 34 +++++++++++++++++++ 2 files changed, 38 insertions(+), 6 deletions(-) create mode 100644 paddlehub/serving/model_service/model_manage.py diff --git a/paddlehub/serving/app_single.py b/paddlehub/serving/app_single.py index 7eec330a..2285fb89 100644 --- a/paddlehub/serving/app_single.py +++ b/paddlehub/serving/app_single.py @@ -12,11 +12,8 @@ # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. # See the License for the specific language governing permissions and from flask import Flask, request, render_template -from paddlehub.serving.model_service.text_model_service import TextModelService -from paddlehub.serving.model_service.image_model_service import ImageModelService +from paddlehub.serving.model_service.model_manage import default_module_manager from paddlehub.common import utils -# from model_service.text_model_service import TextModelService -# from model_service.image_model_service import ImageModelService import time import os import base64 @@ -269,7 +266,7 @@ def create_app(): file_name = req_id + "_" + item.filename item.save(file_name) file_name_list.append(file_name) - module = ImageModelService.get_module(module_name) + module = default_module_manager.get_module(module_name) predict_func_name = cv_module_method.get(module_name, "") if predict_func_name != "": predict_func = eval(predict_func_name) @@ -297,7 +294,7 @@ def create_app(): file_name = req_id + "_" + file.filename files[file_key].append(file_name) file.save(file_name) - module = TextModelService.get_module(module_name) + module = default_module_manager.get_module(module_name) results = predict_nlp( module=module, input_text=inputs, @@ -321,6 +318,7 @@ def config_with_file(configs): elif item["category"] == "NLP": nlp_module.append(item["module"]) batch_size_dict.update({item["module"]: item["batch_size"]}) + default_module_manager.load_module([item["module"]]) def run(is_use_gpu=False, configs=None, port=8866, timeout=60): diff --git a/paddlehub/serving/model_service/model_manage.py b/paddlehub/serving/model_service/model_manage.py new file mode 100644 index 00000000..b18c43a4 --- /dev/null +++ b/paddlehub/serving/model_service/model_manage.py @@ -0,0 +1,34 @@ +# coding: utf-8 +# Copyright (c) 2019 PaddlePaddle Authors. All Rights Reserved. +# +# Licensed under the Apache License, Version 2.0 (the "License" +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. +import paddlehub as hub + + +class ModuleManager(object): + def __init__(self): + self.modules = {} + + def load_module(self, modules=[]): + for name in modules: + self.modules.update({name: hub.Module(name)}) + print("Loading %s successful." % name) + + def get_module(self, name): + if name in self.modules.keys(): + return self.modules[name] + else: + return hub.Module(name) + + +default_module_manager = ModuleManager() -- GitLab