Skip to content

Commit 2665445

Browse files
Add info command
1 parent d13fba5 commit 2665445

File tree

1 file changed

+28
-0
lines changed

1 file changed

+28
-0
lines changed

machine-learning/manage-ml.py

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -62,6 +62,27 @@ def print_models(models, headers=True):
6262
print(table)
6363

6464

65+
def get_model_info(model_id):
66+
"""Get model details."""
67+
model = ml.get_model(model_id)
68+
created = datetime.fromtimestamp(model.create_time / 1000, timezone.utc)
69+
updated = datetime.fromtimestamp(model.update_time / 1000, timezone.utc)
70+
table = BeautifulTable()
71+
table.columns.append(['Name:', 'ID:', 'Tags:', 'Published:', 'ETag:',
72+
'SHA256:', 'Created:', 'Updated:'])
73+
table.columns.append([model.display_name,
74+
model.model_id,
75+
', '.join(model.tags) if model.tags else '',
76+
'Yes' if model.published else 'No',
77+
model.etag,
78+
model.model_hash,
79+
created.isoformat(' ', timespec='seconds'),
80+
updated.isoformat(' ', timespec='seconds')])
81+
table.set_style(BeautifulTable.STYLE_COMPACT)
82+
table.columns.alignment = BeautifulTable.ALIGN_LEFT
83+
print(table)
84+
85+
6586
def update_model(model_id, model_file=None, name=None,
6687
new_tags=None, remove_tags=None):
6788
"""Update one of the project's models."""
@@ -117,6 +138,11 @@ def main():
117138
help='''filter expression to limit results (see:
118139
https://firebase.google.com/docs/ml-kit/manage-hosted-models#list_your_projects_models)''')
119140

141+
info_parser = subparsers.add_parser(
142+
'info', help='')
143+
info_parser.add_argument(
144+
'model_id', type=valid_id, help='the ID of the model you want to view')
145+
120146
update_parser = subparsers.add_parser(
121147
'update', help='update one of your project\'s models')
122148
update_parser.add_argument(
@@ -144,6 +170,8 @@ def main():
144170
upload_model(args.model_file, args.name, tags)
145171
elif args.command == 'list':
146172
list_models(args.filter)
173+
elif args.command == 'info':
174+
get_model_info(args.model_id)
147175
elif args.command == 'update':
148176
new_tags = args.new_tags.split(',') if args.new_tags is not None else None
149177
remove_tags = (

0 commit comments

Comments
 (0)