From 5e9c173b8c3f7acc5aad6a89d3b6889a2eaf63bf Mon Sep 17 00:00:00 2001 From: wuzewu Date: Tue, 1 Jun 2021 14:17:41 +0800 Subject: [PATCH] Add alias for paddle.hub.* --- paddlehub/__init__.py | 37 +++++++++++++++++++++++++++++++++++++ 1 file changed, 37 insertions(+) diff --git a/paddlehub/__init__.py b/paddlehub/__init__.py index 06eab2c6..4b5d935f 100644 --- a/paddlehub/__init__.py +++ b/paddlehub/__init__.py @@ -66,3 +66,40 @@ common = EasyDict(paddle_helper=paddle_utils) dataset = EasyDict(Couplet=couplet.Couplet) finetune = EasyDict(strategy=EasyDict(ULMFiTStrategy=ULMFiTStrategy)) logger = EasyDict(logger=log.logger) + + +# Alias for paddle.hub.* +def load(*args, **kwargs): + if _paddle_version < Version('2.1.0') and _paddle_version != Version('0.0.0'): + raise RuntimeError( + '`hub.load` is only available in PaddlePaddle 2.1 and above, please upgrade the PaddlePaddle version.') + + from paddle.hub import load as phload + from paddlehub.server.server import CacheUpdater + + CacheUpdater("paddle.hub.load").start() + return phload(*args, **kwargs) + + +def list(*args, **kwargs): + if _paddle_version < Version('2.1.0') and _paddle_version != Version('0.0.0'): + raise RuntimeError( + '`hub.list` is only available in PaddlePaddle 2.1 and above, please upgrade the PaddlePaddle version.') + + from paddle.hub import list as phlist + from paddlehub.server.server import CacheUpdater + + CacheUpdater("paddle.hub.list").start() + return phlist(*args, **kwargs) + + +def help(*args, **kwargs): + if _paddle_version < Version('2.1.0') and _paddle_version != Version('0.0.0'): + raise RuntimeError( + '`hub.help` is only available in PaddlePaddle 2.1 and above, please upgrade the PaddlePaddle version.') + + from paddle.hub import help as phhelp + from paddlehub.server.server import CacheUpdater + + CacheUpdater("paddle.hub.help").start() + return phhelp(*args, **kwargs) -- GitLab