From b8f43f444ac04f1205a8116fc881b69b14b4be43 Mon Sep 17 00:00:00 2001 From: Lincoln Stein Date: Wed, 26 Jul 2023 08:26:29 -0400 Subject: [PATCH] implemented startup sanity checks on core models --- invokeai/app/api_app.py | 5 ++++- invokeai/backend/install/check_root.py | 29 ++++++++++++++++++++++++++ 2 files changed, 33 insertions(+), 1 deletion(-) create mode 100644 invokeai/backend/install/check_root.py diff --git a/invokeai/app/api_app.py b/invokeai/app/api_app.py index 824b697d54..044271779c 100644 --- a/invokeai/app/api_app.py +++ b/invokeai/app/api_app.py @@ -203,7 +203,10 @@ def invoke_api(): return find_port(port=port + 1) else: return port - + + from invokeai.backend.install.check_root import check_invokeai_root + check_invokeai_root(app_config) # note, may exit with an exception if root not set up + port = find_port(app_config.port) if port != app_config.port: logger.warn(f"Port {app_config.port} in use, using port {port}") diff --git a/invokeai/backend/install/check_root.py b/invokeai/backend/install/check_root.py new file mode 100644 index 0000000000..4dab16adcc --- /dev/null +++ b/invokeai/backend/install/check_root.py @@ -0,0 +1,29 @@ +""" +Check that the invokeai_root is correctly configured and exit if not. +""" +import sys +from invokeai.app.services.config import ( + InvokeAIAppConfig, +) + +def check_invokeai_root(config: InvokeAIAppConfig): + try: + assert config.model_conf_path.exists() + assert config.db_path.exists() + assert config.models_path.exists() + for model in [ + 'CLIP-ViT-bigG-14-laion2B-39B-b160k', + 'bert-base-uncased', + 'clip-vit-large-patch14', + 'sd-vae-ft-mse', + 'stable-diffusion-2-clip', + 'stable-diffusion-safety-checker']: + assert (config.models_path / f'core/convert/{model}').exists() + except: + print() + print('== STARTUP ABORTED ==') + print('** One or more necessary files is missing from your InvokeAI root directory **') + print('** Please rerun the configuration script to fix this problem. From the launcher, this is option [7] **') + input('Press any key to continue...') + sys.exit(0) +