package.py 2.8 KB
Newer Older
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17
#   Copyright (c) 2020 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.
"""
Usage:
    Download a package for serving directly
    Example:
D
dongdaxiang 已提交
18
        python -m paddle_serving_app.models --get_model senta_bilstm
19 20 21 22
        python -m paddle_serving_app.models --list_model
"""

import argparse
D
dongdaxiang 已提交
23
import sys
24 25 26 27 28 29
from .models import ServingModels


def parse_args():  # pylint: disable=doc-string-missing
    parser = argparse.ArgumentParser("serve")
    parser.add_argument(
D
dongdaxiang 已提交
30
        "--get_model", type=str, default="", help="Download a specific model")
31
    parser.add_argument(
D
dongdaxiang 已提交
32
        '--list_model', nargs='*', default=None, help="List Models")
D
dongdaxiang 已提交
33 34
    parser.add_argument(
        '--tutorial', type=str, default="", help="Get running command")
35 36 37 38 39
    return parser.parse_args()


if __name__ == "__main__":
    args = parse_args()
D
dongdaxiang 已提交
40
    if args.list_model != None:
41
        model_handle = ServingModels()
D
dongdaxiang 已提交
42 43 44 45 46 47 48 49
        model_dict = model_handle.get_model_list()
        # Task level model list
        # Text Classification, Semantic Representation
        # Image Classification, Object Detection, Image Segmentation
        for key in model_dict:
            print("-----------------------------------------------")
            print("{}: {}".format(key, " | ".join(model_dict[key])))

D
dongdaxiang 已提交
50
    elif args.get_model != "":
51
        model_handle = ServingModels()
D
dongdaxiang 已提交
52 53
        model_dict = model_handle.url_dict
        if args.get_model not in model_dict:
54 55 56 57
            print(
                "Your model name does not exist in current model list, stay tuned"
            )
            sys.exit(0)
D
dongdaxiang 已提交
58
        model_handle.download(args.get_model)
D
dongdaxiang 已提交
59 60 61 62 63 64 65 66 67 68
    elif args.tutorial != "":
        model_handle = ServingModels()
        model_dict = model_handle.url_dict
        if args.get_model not in model_dict:
            print(
                "Your model name does not exist in current model list, stay tuned"
            )
            sys.exit(0)
        tutorial_str = model_handle.get_tutorial()
        print(tutorial_str)
69 70 71 72 73 74 75 76 77 78
    else:
        print("Wrong argument")
        print("""
              Usage:
              Download a package for serving directly
              Example:
                   python -m paddle_serving_app.models --get senta_bilstm
                   python -m paddle_serving_app.models --list_model
              """)
        pass