-
Notifications
You must be signed in to change notification settings - Fork 0
/
main_cli.py
60 lines (47 loc) · 1.43 KB
/
main_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
"""
main_cli.py
Author: Sean Ryan
Use an LLM to summarize text of PDF files.
Usage: main_cli.py <path to input file or input directory or URL> [options]
The options are:
[-l --language - The target output language. The default is set in config.py]
[-o --output - The output directory. By default is None, so output is to stdout (no files are output).]
[-h --help]
"""
import sys
from optparse import OptionParser
import summarizer
import config
# usage() - prints out the usage text, from the top of this file :-)
def usage():
print(__doc__)
# optparse - parse the args
parser = OptionParser(
usage="%prog <path to input file or input directory or URL> [options]"
)
parser.add_option(
"-l",
"--language",
dest="target_language",
default=config.TARGET_LANGUAGE,
help="The target output language. The default is set in config.py. Example: English.",
)
parser.add_option(
"-o",
"--output",
dest="output_dir",
default=None,
help="The output directory. By default is None, so output is to stdout (no files are output).",
)
(options, args) = parser.parse_args()
if len(args) != 1:
usage()
sys.exit(2)
path_to_input_file_or_dir_or_url = sys.argv[1]
target_language = options.target_language
path_to_output_dir = None
if options.output_dir:
path_to_output_dir = options.output_dir
summarizer.summarize_file_or_dir_or_url(
path_to_input_file_or_dir_or_url, path_to_output_dir, target_language
)