-
Notifications
You must be signed in to change notification settings - Fork 10
/
Copy pathstart_app.py
93 lines (75 loc) · 2.66 KB
/
start_app.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
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
"""
start_app.py
Main entry point for the Flask web application.
This script sets up and launches the Flask web application with configurable
options for the prediction engine, logging level, and Flask debug mode.
Usage:
python start_app.py --predictor=PredictorName --log_level=INFO --debug
Options:
--predictor : str, optional
The predictor to use for predictions. Default is 'Best'.
Valid options are listed in the configuration.
--log_level : str, optional
The log level to use for logging. Options are DEBUG, INFO, WARNING, ERROR, CRITICAL. Default is 'INFO'.
--debug : bool, optional
If set, run the application in Flask debug mode. Default is False.
"""
import argparse
from src.config import config
from src.logging_config import setup_logging
from src.web_app.app import create_app
# Configuration
VALID_PREDICTORS = config["predictors"]
def main():
"""
Main entry point for launching the Flask application.
This function handles the parsing of command-line arguments, sets up logging,
initializes the Flask app, and runs the app with the specified configuration.
"""
# Parse command-line arguments
parser = argparse.ArgumentParser(
description="Launch the web app with a specified prediction engine"
)
parser.add_argument(
"--predictor",
type=str,
help=f"The predictor to use for predictions. Valid options are: {', '.join(VALID_PREDICTORS)}",
)
parser.add_argument(
"--log_level",
default="INFO",
type=str,
help="The log level to use for logging. Options are DEBUG, INFO, WARNING, ERROR, CRITICAL.",
)
parser.add_argument(
"--debug",
action="store_true",
default=False,
help="Run the application in Flask debug mode.",
)
args = parser.parse_args()
predictor = (
args.predictor
if args.predictor
else config.get("default_predictor", "Baseline")
)
log_level = args.log_level.upper()
debug_mode = args.debug
# Validate log level and predictor
valid_log_levels = ["DEBUG", "INFO", "WARNING", "ERROR", "CRITICAL"]
if log_level not in valid_log_levels:
raise ValueError(
f"Invalid log level: {log_level}. Must be one of {valid_log_levels}."
)
if predictor not in VALID_PREDICTORS:
raise ValueError(
f"Invalid predictor: {predictor}. Must be one of {VALID_PREDICTORS}."
)
# Set up logging
setup_logging(log_level=log_level)
# Create the Flask app
app = create_app(predictor=predictor)
# Run the app
app.run(debug=debug_mode)
if __name__ == "__main__":
main()