-
Notifications
You must be signed in to change notification settings - Fork 12
/
_cli.py
75 lines (57 loc) · 2.19 KB
/
_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
67
68
69
70
71
72
73
74
75
import logging
import sys
from pathlib import Path
import click
from extra_model._errors import ExtraModelError
from extra_model._run import run
from extra_model._setup import setup
logger = logging.getLogger(__name__)
OUTPUT_PATH = "/io"
OUTPUT_FILENAME = "result.csv"
EMBEDDINGS_PATH = "/embeddings"
@click.command()
@click.argument("input_path", type=Path)
@click.option("-op", "--output-path", type=Path, default=OUTPUT_PATH, show_default=True)
@click.option(
"-of", "--output-filename", type=Path, default=OUTPUT_FILENAME, show_default=True
)
@click.option(
"-ep", "--embeddings-path", type=Path, default=EMBEDDINGS_PATH, show_default=True
)
@click.option("--debug", is_flag=True, help="Enable debug logging")
def entrypoint(
input_path: Path,
output_path: Path,
output_filename: Path,
embeddings_path: Path,
debug: bool = False,
) -> None:
"""Run the Extra algorithm for unsupervised topic extraction.
INPUT_PATH (required) is the path to the input csv file with the user generated texts. It must contain
`CommentId` and `Comments` columns that are spelled exactly this way.
OUTPUT_PATH (option) is the path to the output directory. Default is `/io`.
OUTPUT_FILENAME (option) is the filename of the output file. Default is `result.csv`.
The `.csv` file extension is not enforced. Please take care of this accordingly.
EMBEDDINGS_PATH (option) is the path where the extra model will load the embeddings from.
defaults to `/embeddings`.
"""
logging.getLogger("extra_model").setLevel("DEBUG" if debug else "INFO")
try:
run(input_path, output_path, output_filename, embeddings_path)
sys.exit(0)
except ExtraModelError as e:
logger.exception(e) if debug else logger.error(e)
sys.exit(1)
@click.command()
@click.argument("output_path", type=Path, default=EMBEDDINGS_PATH)
def entrypoint_setup(output_path: Path) -> None:
"""Download resources.
Will download and format glove embeddings.
OUTPUT_PATH is the path to the output directory. Default is `/embeddings`.
"""
try:
setup(output_path)
sys.exit(0)
except ExtraModelError as e:
logger.error(e)
sys.exit(1)