-
Notifications
You must be signed in to change notification settings - Fork 313
/
Copy pathutilscli.py
executable file
·46 lines (35 loc) · 1.25 KB
/
utilscli.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
#!/usr/bin/env python
import click
import mlib
import requests
@click.group()
@click.version_option("1.0")
def cli():
"""Machine Learning Utility Belt"""
@cli.command("retrain")
@click.option("--tsize", default=0.1, help="Test Size")
def retrain(tsize):
"""Retrain Model
You may want to extend this with more options, such as setting model_name
"""
click.echo(click.style("Retraining Model", bg="green", fg="white"))
accuracy, model_name = mlib.retrain(tsize=tsize)
click.echo(
click.style(f"Retrained Model Accuracy: {accuracy}", bg="blue", fg="white")
)
click.echo(click.style(f"Retrained Model Name: {model_name}", bg="red", fg="white"))
@cli.command("predict")
@click.option("--weight", default=225, help="Weight to Pass In")
@click.option("--host", default="http://localhost:8080/predict", help="Host to query")
def mkrequest(weight, host):
"""Sends prediction to ML Endpoint"""
click.echo(
click.style(
f"Querying host {host} with weight: {weight}", bg="green", fg="white"
)
)
payload = {"Weight": weight}
result = requests.post(url=host, json=payload)
click.echo(click.style(f"result: {result.text}", bg="red", fg="white"))
if __name__ == "__main__":
cli()