Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
PaddlePaddle
PaddleHub
提交
2d2b9fdd
P
PaddleHub
项目概览
PaddlePaddle
/
PaddleHub
大约 1 年 前同步成功
通知
282
Star
12117
Fork
2091
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
Issue
200
列表
看板
标记
里程碑
合并请求
4
Wiki
0
Wiki
分析
仓库
DevOps
项目成员
Pages
P
PaddleHub
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Issue
200
Issue
200
列表
看板
标记
里程碑
合并请求
4
合并请求
4
Pages
分析
分析
仓库分析
DevOps
Wiki
0
Wiki
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
创建新Issue
提交
Issue看板
提交
2d2b9fdd
编写于
4月 09, 2019
作者:
W
wuzewu
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
update show command
上级
73cec8d2
变更
2
隐藏空白更改
内联
并排
Showing
2 changed file
with
95 addition
and
27 deletion
+95
-27
paddlehub/commands/cml_utils.py
paddlehub/commands/cml_utils.py
+30
-7
paddlehub/commands/show.py
paddlehub/commands/show.py
+65
-20
未找到文件。
paddlehub/commands/cml_utils.py
浏览文件 @
2d2b9fdd
...
...
@@ -45,8 +45,20 @@ def colorful_text(color, text):
class
TablePrinter
:
def
__init__
(
self
,
titles
,
placeholders
):
def
__init__
(
self
,
titles
,
placeholders
,
title_colors
=
None
,
title_aligns
=
None
):
self
.
titles
=
titles
if
title_colors
is
None
:
self
.
title_colors
=
[
"light_green"
]
*
len
(
self
.
titles
)
else
:
self
.
title_colors
=
title_colors
if
title_aligns
is
None
:
self
.
title_aligns
=
[
"^"
]
*
len
(
self
.
titles
)
else
:
self
.
title_aligns
=
title_aligns
self
.
placeholders
=
placeholders
self
.
text
=
"
\n
"
self
.
add_title
()
...
...
@@ -62,16 +74,22 @@ class TablePrinter:
self
.
add_horizontal_line
()
title_text
=
"|"
for
index
,
title
in
enumerate
(
self
.
titles
):
title
=
colorful_text
(
"light_green"
,
title
)
_ph
=
11
title_text
+=
(
"{0:^%d}|"
%
(
self
.
placeholders
[
index
]
+
2
+
_ph
)).
format
(
title
)
if
self
.
title_colors
[
index
]:
title
=
colorful_text
(
self
.
title_colors
[
index
],
title
)
_ph
=
11
else
:
_ph
=
0
title_text
+=
(
"{0:%s%d}|"
%
(
self
.
title_aligns
[
index
],
self
.
placeholders
[
index
]
+
2
+
_ph
)).
format
(
title
)
title_text
+=
'
\n
'
self
.
text
+=
title_text
def
add_line
(
self
,
contents
,
colors
=
None
):
def
add_line
(
self
,
contents
,
colors
=
None
,
aligns
=
None
):
self
.
add_horizontal_line
()
max_lines
=
0
if
aligns
is
None
:
aligns
=
[
None
]
*
len
(
contents
)
marks
=
[
False
]
*
len
(
contents
)
colors
=
[
None
]
*
len
(
contents
)
if
colors
is
None
else
colors
offset
=
[
0
]
*
len
(
contents
)
...
...
@@ -93,7 +111,12 @@ class TablePrinter:
_ph
=
11
else
:
_ph
=
0
align
=
"<"
if
marks
[
index
]
else
"^"
if
aligns
[
index
]
is
None
:
align
=
"<"
if
marks
[
index
]
else
"^"
else
:
align
=
aligns
[
index
]
line
+=
(
"{0:%s%d}|"
%
(
align
,
self
.
placeholders
[
index
]
+
2
+
_ph
)
).
format
(
split_text
)
...
...
paddlehub/commands/show.py
浏览文件 @
2d2b9fdd
...
...
@@ -21,6 +21,7 @@ import argparse
from
paddlehub.common.logger
import
logger
from
paddlehub.commands.base_command
import
BaseCommand
,
ENTRY
from
paddlehub.commands.cml_utils
import
TablePrinter
from
paddlehub.module.manager
import
default_module_manager
from
paddlehub.module.module
import
Module
from
paddlehub.io.reader
import
yaml_reader
...
...
@@ -39,6 +40,66 @@ class ShowCommand(BaseCommand):
usage
=
'%(prog)s'
,
add_help
=
False
)
def
show_model_info
(
self
,
model_info_file
):
model_info
=
yaml_reader
.
read
(
model_info_file
)
tp
=
TablePrinter
(
titles
=
[
"ModelName"
,
model_info
[
'name'
]],
placeholders
=
[
15
,
50
],
title_colors
=
[
"yellow"
,
None
],
title_aligns
=
[
"^"
,
"<"
])
tp
.
add_line
(
contents
=
[
"Type"
,
model_info
[
'type'
]],
colors
=
[
"yellow"
,
None
],
aligns
=
[
"^"
,
"<"
])
tp
.
add_line
(
contents
=
[
"Version"
,
model_info
[
'version'
]],
colors
=
[
"yellow"
,
None
],
aligns
=
[
"^"
,
"<"
])
tp
.
add_line
(
contents
=
[
"Summary"
,
model_info
[
'description'
]],
colors
=
[
"yellow"
,
None
],
aligns
=
[
"^"
,
"<"
])
tp
.
add_line
(
contents
=
[
"Author"
,
model_info
[
'author'
]],
colors
=
[
"yellow"
,
None
],
aligns
=
[
"^"
,
"<"
])
tp
.
add_line
(
contents
=
[
"Author-Email"
,
model_info
[
'author_email'
]],
colors
=
[
"yellow"
,
None
],
aligns
=
[
"^"
,
"<"
])
print
(
tp
.
get_text
())
return
True
def
show_module_info
(
self
,
module_dir
):
module
=
Module
(
module_dir
=
module_dir
)
tp
=
TablePrinter
(
titles
=
[
"ModuleName"
,
module
.
name
],
placeholders
=
[
15
,
50
],
title_colors
=
[
"light_red"
,
None
],
title_aligns
=
[
"^"
,
"<"
])
tp
.
add_line
(
contents
=
[
"Version"
,
module
.
version
],
colors
=
[
"light_red"
,
None
],
aligns
=
[
"^"
,
"<"
])
tp
.
add_line
(
contents
=
[
"Summary"
,
module
.
summary
],
colors
=
[
"light_red"
,
None
],
aligns
=
[
"^"
,
"<"
])
tp
.
add_line
(
contents
=
[
"Author"
,
module
.
author
],
colors
=
[
"light_red"
,
None
],
aligns
=
[
"^"
,
"<"
])
tp
.
add_line
(
contents
=
[
"Author-Email"
,
module
.
author_email
],
colors
=
[
"light_red"
,
None
],
aligns
=
[
"^"
,
"<"
])
tp
.
add_line
(
contents
=
[
"Location"
,
module_dir
],
colors
=
[
"light_red"
,
None
],
aligns
=
[
"^"
,
"<"
])
print
(
tp
.
get_text
())
return
True
def
exec
(
self
,
argv
):
if
not
argv
:
print
(
"ERROR: Please specify a module or a model
\n
"
)
...
...
@@ -48,17 +109,9 @@ class ShowCommand(BaseCommand):
module_name
=
argv
[
0
]
# nlp model
model_info
=
os
.
path
.
join
(
module_name
,
"info.yml"
)
if
os
.
path
.
exists
(
model_info
):
model_info
=
yaml_reader
.
read
(
model_info
)
show_text
=
"Name:%s
\n
"
%
model_info
[
'name'
]
show_text
+=
"Type:%s
\n
"
%
model_info
[
'type'
]
show_text
+=
"Version:%s
\n
"
%
model_info
[
'version'
]
show_text
+=
"Summary:
\n
"
show_text
+=
" %s
\n
"
%
model_info
[
'description'
]
show_text
+=
"Author:%s
\n
"
%
model_info
[
'author'
]
show_text
+=
"Author-Email:%s
\n
"
%
model_info
[
'author_email'
]
print
(
show_text
)
model_info_file
=
os
.
path
.
join
(
module_name
,
"info.yml"
)
if
os
.
path
.
exists
(
model_info_file
):
self
.
show_model_info
(
model_info_file
)
return
True
cwd
=
os
.
getcwd
()
...
...
@@ -68,15 +121,7 @@ class ShowCommand(BaseCommand):
if
not
module_dir
or
not
os
.
path
.
exists
(
module_dir
):
return
True
module
=
Module
(
module_dir
=
module_dir
)
show_text
=
"Name:%s
\n
"
%
module
.
name
show_text
+=
"Version:%s
\n
"
%
module
.
version
show_text
+=
"Summary:
\n
"
show_text
+=
" %s
\n
"
%
module
.
summary
show_text
+=
"Author:%s
\n
"
%
module
.
author
show_text
+=
"Author-Email:%s
\n
"
%
module
.
author_email
show_text
+=
"Location:%s
\n
"
%
module_dir
print
(
show_text
)
self
.
show_module_info
(
module_dir
)
return
True
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录