From 2aa55f140f6c3009b43e292ccbd8544fafef3511 Mon Sep 17 00:00:00 2001 From: MRXLT Date: Sun, 24 May 2020 12:52:54 +0000 Subject: [PATCH] fix app --- python/paddle_serving_app/__init__.py | 6 ------ python/paddle_serving_app/reader/lac_reader.py | 8 +++++++- python/paddle_serving_app/reader/senta_reader.py | 10 +++++++++- 3 files changed, 16 insertions(+), 8 deletions(-) diff --git a/python/paddle_serving_app/__init__.py b/python/paddle_serving_app/__init__.py index 2a622557..11ad09a1 100644 --- a/python/paddle_serving_app/__init__.py +++ b/python/paddle_serving_app/__init__.py @@ -11,10 +11,4 @@ # 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. -from .reader.chinese_bert_reader import ChineseBertReader -from .reader.image_reader import ImageReader, File2Image, URL2Image, Sequential, Normalize, CenterCrop, Resize, PadStride -from .reader.lac_reader import LACReader -from .reader.senta_reader import SentaReader -from .reader.imdb_reader import IMDBDataset from .models import ServingModels -from .local_predict import Debugger diff --git a/python/paddle_serving_app/reader/lac_reader.py b/python/paddle_serving_app/reader/lac_reader.py index 720bbf9c..7e804ff3 100644 --- a/python/paddle_serving_app/reader/lac_reader.py +++ b/python/paddle_serving_app/reader/lac_reader.py @@ -48,10 +48,16 @@ def load_kv_dict(dict_path, class LACReader(object): """data reader""" - def __init__(self, dict_folder): + def __init__(self, dict_folder=""): # read dict #basepath = os.path.abspath(__file__) #folder = os.path.dirname(basepath) + if dict_folder == "": + dict_folder = "lac_dict" + if not os.path.exists(dict_folder): + r = os.system( + "wget https://paddle-serving.bj.bcebos.com/reader/lac/lac_dict.tar.gz --no-check-certificate && tar -xzvf lac_dict.tar.gz" + ) word_dict_path = os.path.join(dict_folder, "word.dic") label_dict_path = os.path.join(dict_folder, "tag.dic") replace_dict_path = os.path.join(dict_folder, "q2b.dic") diff --git a/python/paddle_serving_app/reader/senta_reader.py b/python/paddle_serving_app/reader/senta_reader.py index 6e608b82..e0c93c00 100644 --- a/python/paddle_serving_app/reader/senta_reader.py +++ b/python/paddle_serving_app/reader/senta_reader.py @@ -14,10 +14,11 @@ import sys import io +import os class SentaReader(): - def __init__(self, vocab_path, max_seq_len=20): + def __init__(self, vocab_path="", max_seq_len=20): self.max_seq_len = max_seq_len self.word_dict = self.load_vocab(vocab_path) @@ -25,6 +26,13 @@ class SentaReader(): """ load the given vocabulary """ + if vocab_path == "": + vocab_path = "senta_vocab.txt" + if not os.path.exists(vocab_path): + r = os.system( + " wget https://paddle-serving.bj.bcebos.com/reader/senta/senta_vocab.txt --no-check-certificate" + ) + vocab = {} with io.open(vocab_path, 'r', encoding='utf8') as f: for line in f: -- GitLab