This repository has been archived by the owner on Sep 4, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 6
/
Copy pathrun_app.py
42 lines (32 loc) · 1.6 KB
/
run_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
'''Driver script to start and run InterpreT.'''
import socket
import argparse
from importlib import import_module
from app import app_configuration
def build_model(model_name, *args, **kwargs):
model = getattr(import_module(f'app.database.models.{model_name.lower()}'), model_name.title())
return model(*args, **kwargs)
def main(port, db_path, model_name=None, model_params=None):
print(f'Running on port {port} with database {db_path}' +
f' and {model_name} model' if model_name else '')
model = build_model(model_name, *model_params) if model_name else None
app = app_configuration.configure_app(db_path, model=model)
hostname = socket.gethostname()
ip_address = socket.gethostbyname(hostname)
app_configuration.print_page_link(hostname, port)
application = app.server
application.run(debug=False, threaded=True, host=ip_address, port=int(port))
if __name__ == '__main__':
parser = argparse.ArgumentParser()
parser.add_argument('-p', '--port', required=True,
help='The port number to run this app on.')
parser.add_argument('-d', '--database', required=True,
help='The path to a database. See app/database/db_example.py')
parser.add_argument('-m', '--model', nargs='+', required=False,
help='Your model name to run, followed by the arguments '
'that need to be passed to start the model.')
args = parser.parse_args()
if args.model:
main(args.port, args.database, args.model[0], args.model[1:])
else:
main(args.port, args.database)