-
Notifications
You must be signed in to change notification settings - Fork 0
/
categories_classification_cli.py
66 lines (51 loc) · 1.71 KB
/
categories_classification_cli.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
import json
from json import JSONDecodeError
import click
from categories_classification.predictor import predict_categories
from categories_classification.trainer import train_model
class JsonOption(click.Option):
"""
A simple Click library class for json arguments. Can be used for python dict or lists.
"""
def type_cast_value(self, ctx, value):
"""
Parse input as JSON.
:param ctx:
:param value:
:return:
"""
try:
return json.loads(value)
except JSONDecodeError as err:
raise click.BadParameter(value) from err
@click.command()
@click.option('--client_id', help='The id of the client.', required=True)
@click.option('--features', cls=JsonOption, help='The list of input features.', required=True)
@click.option('--model_params', cls=JsonOption, help='Params to be passed to model.', required=True)
@click.option('--training_date', help='The training date.', required=True)
def trainer(client_id, features, model_params, training_date):
"""
:param training_date:
:param client_id:
:param features:
:param model_params:
:return:
"""
train_model(client_id, features, model_params, training_date)
@click.command()
@click.option('--client_id', help='The id of the client.', required=True)
@click.option('--inference_date', help='The inference date.', required=True)
def predictor(client_id, inference_date):
"""
:param client_id:
:param inference_date:
:return:
"""
predict_categories(client_id, inference_date)
@click.group()
def main():
"""Better Categories 4All Demo"""
if __name__ == '__main__':
main.add_command(trainer)
main.add_command(predictor)
main()