|
2 | 2 | """Firebase Admin SDK ML quickstart example.""" |
3 | 3 |
|
4 | 4 | import argparse |
| 5 | +from datetime import datetime |
| 6 | +from datetime import timezone |
5 | 7 |
|
| 8 | +from beautifultable import BeautifulTable |
6 | 9 | import firebase_admin |
7 | 10 | from firebase_admin import ml |
8 | 11 |
|
@@ -36,17 +39,27 @@ def upload_model(model_file, name, tags=None): |
36 | 39 | ml.publish_model(new_model.model_id) |
37 | 40 |
|
38 | 41 | print('Model uploaded and published:') |
39 | | - tags = ', '.join(new_model.tags) if new_model.tags is not None else '' |
40 | | - print('{:<20}{:<10} {}'.format(new_model.display_name, new_model.model_id, |
41 | | - tags)) |
| 42 | + print_models([new_model], headers=False) |
42 | 43 |
|
43 | 44 |
|
44 | 45 | def list_models(filter_exp=''): |
45 | 46 | """List the models in the project.""" |
46 | 47 | models = ml.list_models(list_filter=filter_exp).iterate_all() |
| 48 | + print_models(models) |
| 49 | + |
| 50 | + |
| 51 | +def print_models(models, headers=True): |
| 52 | + """Prettyprint a list of models.""" |
| 53 | + table = BeautifulTable() |
| 54 | + if headers: |
| 55 | + table.columns.header = ['Name', 'ID', 'Tags'] |
47 | 56 | for model in models: |
48 | 57 | tags = ', '.join(model.tags) if model.tags is not None else '' |
49 | | - print('{:<20}{:<10} {}'.format(model.display_name, model.model_id, tags)) |
| 58 | + table.rows.append([model.display_name, model.model_id, tags]) |
| 59 | + table.set_style(BeautifulTable.STYLE_COMPACT) |
| 60 | + table.columns.header.alignment = BeautifulTable.ALIGN_CENTER |
| 61 | + table.columns.alignment = BeautifulTable.ALIGN_LEFT |
| 62 | + print(table) |
50 | 63 |
|
51 | 64 |
|
52 | 65 | def update_model(model_id, model_file=None, name=None, |
|
0 commit comments