mirror of
https://github.com/khoaliber/khoj.git
synced 2026-03-09 13:25:11 +00:00
Wrap application startup steps into a method
This commit is contained in:
11
src/main.py
11
src/main.py
@@ -279,26 +279,31 @@ def shutdown_event():
|
|||||||
print('INFO:\tConversation logs saved to disk.')
|
print('INFO:\tConversation logs saved to disk.')
|
||||||
|
|
||||||
|
|
||||||
if __name__ == '__main__':
|
def run():
|
||||||
# Load config from CLI
|
# Load config from CLI
|
||||||
args = cli(sys.argv[1:])
|
args = cli(sys.argv[1:])
|
||||||
|
|
||||||
# Stores the file path to the config file.
|
# Stores the file path to the config file.
|
||||||
|
global config_file
|
||||||
config_file = args.config_file
|
config_file = args.config_file
|
||||||
|
|
||||||
# Store the verbose flag
|
# Store the verbose flag
|
||||||
|
global verbose
|
||||||
verbose = args.verbose
|
verbose = args.verbose
|
||||||
|
|
||||||
# Store the raw config data.
|
# Store the raw config data.
|
||||||
|
global config
|
||||||
config = args.config
|
config = args.config
|
||||||
|
|
||||||
# Set device to GPU if available
|
# Set device to GPU if available
|
||||||
device = torch.device("cuda:0") if torch.cuda.is_available() else torch.device("cpu")
|
device = torch.device("cuda:0") if torch.cuda.is_available() else torch.device("cpu")
|
||||||
|
|
||||||
# Initialize the search model from Config
|
# Initialize the search model from Config
|
||||||
|
global model
|
||||||
model = initialize_search(args.config, args.regenerate, device=device)
|
model = initialize_search(args.config, args.regenerate, device=device)
|
||||||
|
|
||||||
# Initialize Processor from Config
|
# Initialize Processor from Config
|
||||||
|
global processor_config
|
||||||
processor_config = initialize_processor(args.config)
|
processor_config = initialize_processor(args.config)
|
||||||
|
|
||||||
# Start Application Server
|
# Start Application Server
|
||||||
@@ -306,3 +311,7 @@ if __name__ == '__main__':
|
|||||||
uvicorn.run(app, proxy_headers=True, uds=args.socket)
|
uvicorn.run(app, proxy_headers=True, uds=args.socket)
|
||||||
else:
|
else:
|
||||||
uvicorn.run(app, host=args.host, port=args.port)
|
uvicorn.run(app, host=args.host, port=args.port)
|
||||||
|
|
||||||
|
|
||||||
|
if __name__ == '__main__':
|
||||||
|
run()
|
||||||
Reference in New Issue
Block a user