Skip to content
This repository was archived by the owner on Apr 17, 2026. It is now read-only.

Commit d13fba5

Browse files
Print with BeautifulTable
1 parent 909f39e commit d13fba5

3 files changed

Lines changed: 22 additions & 6 deletions

File tree

machine-learning/README.md

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,11 +9,12 @@ Also see the [Firebase ML API Tutorial Colab/Jupyter notebook][colab].
99

1010
## Setup
1111

12-
1. Install the Admin SDK (probably in a virtual environment):
12+
1. Install the Admin SDK and other dependencies (probably in a virtual
13+
environment):
1314

1415
```
1516
$ pip install -U pip setuptools
16-
$ pip install firebase_admin
17+
$ pip install -r requirements.txt
1718
```
1819
1920
2. Clone the quickstart repository and change to the `machine-learning`

machine-learning/manage-ml.py

100644100755
Lines changed: 17 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,10 @@
22
"""Firebase Admin SDK ML quickstart example."""
33

44
import argparse
5+
from datetime import datetime
6+
from datetime import timezone
57

8+
from beautifultable import BeautifulTable
69
import firebase_admin
710
from firebase_admin import ml
811

@@ -36,17 +39,27 @@ def upload_model(model_file, name, tags=None):
3639
ml.publish_model(new_model.model_id)
3740

3841
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)
4243

4344

4445
def list_models(filter_exp=''):
4546
"""List the models in the project."""
4647
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']
4756
for model in models:
4857
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)
5063

5164

5265
def update_model(model_id, model_file=None, name=None,

machine-learning/requirements.txt

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
beautifultable~=1.0.0
2+
firebase-admin~=4.3.0

0 commit comments

Comments
 (0)