diff --git a/README.md b/README.md index d37e0b507c2ef2f55e86358c862dbccbcef26f8a..33ec40fed596601683f11da1924ebde6e6dc702c 100644 --- a/README.md +++ b/README.md @@ -152,8 +152,8 @@ print(res) ### PaddleHub v1.1.0 -* PaddleHub 新增 ERNIE 2.0 - +* PaddleHub 新增 ERNIE 2.0 + ### PaddleHub v1.0.1 * 安装模型时自动选择与paddlepaddle版本适配的模型 @@ -163,7 +163,7 @@ print(res) * 全新发布[PaddleHub官网](https://www.paddlepaddle.org.cn/hub),易用性全面提升 * 新增29个预训练模型,覆盖文本、图像、视频三大领域;目前官方提供40个预训练模型 * Fine-tune API升级,灵活性与性能全面提升 - + ### PaddleHub v0.5.0 正式发布PaddleHub预训练模型管理工具,旨在帮助用户更高效的管理模型并开展迁移学习的工作。 @@ -174,4 +174,3 @@ print(res) 目前版本支持以下模型:词法分析LAC;情感分析Senta;目标检测SSD;图像分类ResNet, MobileNet, NASNet等。 * 迁移学习: 提供了基于预训练模型的Finetune API,用户通过少量代码即可完成迁移学习,包括BERT/ERNIE文本分类、序列标注、图像分类迁移等。 - diff --git a/paddlehub/commands/config.py b/paddlehub/commands/config.py new file mode 100644 index 0000000000000000000000000000000000000000..22422d8a864c37f0337de2635e1ec92345781b91 --- /dev/null +++ b/paddlehub/commands/config.py @@ -0,0 +1,136 @@ +#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. + +from __future__ import absolute_import +from __future__ import division +from __future__ import print_function + +import argparse +import json +import os +import re + +from paddlehub.commands.base_command import BaseCommand, ENTRY +from paddlehub.common.dir import CONF_HOME +from paddlehub.common.server_config import default_server_config + + +class ConfigCommand(BaseCommand): + name = "config" + + def __init__(self, name): + super(ConfigCommand, self).__init__(name) + self.show_in_help = True + self.description = "Configure PaddleHub." + self.parser = argparse.ArgumentParser( + description=self.__class__.__doc__, + prog='%s %s [COMMAND]' % (ENTRY, name), + usage='%(prog)s', + add_help=True) + self.parser.add_argument("command") + self.parser.add_argument("option", nargs="?") + self.parser.add_argument("value", nargs="?") + + @staticmethod + def show_config(): + print("The current configuration is shown below.") + with open(os.path.join(CONF_HOME, "config.json"), "r") as fp: + print(json.dumps(json.load(fp), indent=4)) + + @staticmethod + def set_server_url(server_url): + with open(os.path.join(CONF_HOME, "config.json"), "r") as fp: + config = json.load(fp) + re_str = "^(?:http(s)?:\/\/)?[\w.-]+(?:\.[\w\.-]+)+[\w\-\._~:/?#[\]@!\$&'\*\+,;=.]+$" + if re.match(re_str, server_url) is not None: + config["server_url"] = list([server_url]) + ConfigCommand.set_config(config) + else: + print("The format of the input url is invalid.") + + @staticmethod + def set_config(config): + with open(os.path.join(CONF_HOME, "config.json"), "w") as fp: + fp.write(json.dumps(config)) + print("Set success! The current configuration is shown below.") + print(json.dumps(config, indent=4)) + + @staticmethod + def show_server_url(): + with open(os.path.join(CONF_HOME, "config.json"), "r") as fp: + config = json.load(fp) + print(config["server_url"]) + + @staticmethod + def show_log_level(): + with open(os.path.join(CONF_HOME, "config.json"), "r") as fp: + print(json.load(fp)["log_level"]) + + @staticmethod + def set_log_level(level): + if level not in [ + "CRITICAL", "FATAL", "ERROR", "WARN", "WARNING", "INFO", + "DEBUG", "NOTSET" + ]: + print("Allowed values include: " + "CRITICAL, FATAL, ERROR, WARN, WARNING, INFO, DEBUG, NOTSET") + return + with open(os.path.join(CONF_HOME, "config.json"), "r") as fp: + current_config = json.load(fp) + with open(os.path.join(CONF_HOME, "config.json"), "w") as fp: + current_config["log_level"] = level + fp.write(json.dumps(current_config)) + print("Set success! The current configuration is shown below.") + print(json.dumps(current_config, indent=4)) + + @staticmethod + def show_help(): + str = "config