make autoimport directory optional, defaulting to inactive

This commit is contained in:
Lincoln Stein
2023-10-07 14:00:38 -04:00
parent 6303f74616
commit 00e85bcd67
5 changed files with 18 additions and 13 deletions

View File

@ -207,11 +207,8 @@ if INVOKEAI_ROOT is `/home/fred/invokeai` and the path is
| Setting | Default Value | Description | | Setting | Default Value | Description |
|----------|----------------|--------------| |----------|----------------|--------------|
| `autoimport_dir` | `autoimport/main` | At startup time, read and import any main model files found in this directory | | `autoimport_dir` | `autoimport/main` | At startup time, read and import any main model files found in this directory (not recommended)|
| `lora_dir` | `autoimport/lora` | At startup time, read and import any LoRA/LyCORIS models found in this directory | | `model_config_db` | `auto` | Location of the model configuration database. Specify `auto` to use the main invokeai.db database, or specify a `.yaml` or `.db` file to store the data externally.|
| `embedding_dir` | `autoimport/embedding` | At startup time, read and import any textual inversion (embedding) models found in this directory |
| `controlnet_dir` | `autoimport/controlnet` | At startup time, read and import any ControlNet models found in this directory |
| `conf_path` | `configs/models.yaml` | Location of the `models.yaml` model configuration file |
| `models_dir` | `models` | Location of the directory containing models installed by InvokeAI's model manager | | `models_dir` | `models` | Location of the directory containing models installed by InvokeAI's model manager |
| `legacy_conf_dir` | `configs/stable-diffusion` | Location of the directory containing the .yaml configuration files for legacy checkpoint models | | `legacy_conf_dir` | `configs/stable-diffusion` | Location of the directory containing the .yaml configuration files for legacy checkpoint models |
| `db_dir` | `databases` | Location of the directory containing InvokeAI's image, schema and session database | | `db_dir` | `databases` | Location of the directory containing InvokeAI's image, schema and session database |

View File

@ -219,10 +219,7 @@ class InvokeAIAppConfig(InvokeAISettings):
# PATHS # PATHS
root : Path = Field(default=None, description='InvokeAI runtime root directory', category='Paths') root : Path = Field(default=None, description='InvokeAI runtime root directory', category='Paths')
autoimport_dir : Path = Field(default='autoimport', description='Path to a directory of models files to be imported on startup.', category='Paths') autoimport_dir : Optional[Path] = Field(default=None, description='Path to a directory of models files to be imported on startup.', category='Paths')
lora_dir : Path = Field(default=None, description='Path to a directory of LoRA/LyCORIS models to be imported on startup.', category='Paths')
embedding_dir : Path = Field(default=None, description='Path to a directory of Textual Inversion embeddings to be imported on startup.', category='Paths')
controlnet_dir : Path = Field(default=None, description='Path to a directory of ControlNet embeddings to be imported on startup.', category='Paths')
model_config_db : Union[Path, Literal['auto'], None] = Field(default=None, description='Path to a sqlite .db file or .yaml file for storing model config records; "auto" will reuse the main sqlite db', category='Paths') model_config_db : Union[Path, Literal['auto'], None] = Field(default=None, description='Path to a sqlite .db file or .yaml file for storing model config records; "auto" will reuse the main sqlite db', category='Paths')
models_dir : Path = Field(default='models', description='Path to the models directory', category='Paths') models_dir : Path = Field(default='models', description='Path to the models directory', category='Paths')
legacy_conf_dir : Path = Field(default='configs/stable-diffusion', description='Path to directory of legacy checkpoint config files', category='Paths') legacy_conf_dir : Path = Field(default='configs/stable-diffusion', description='Path to directory of legacy checkpoint config files', category='Paths')
@ -274,6 +271,9 @@ class InvokeAIAppConfig(InvokeAISettings):
xformers_enabled : bool = Field(default=True, description="Enable/disable memory-efficient attention", category='Memory/Performance') xformers_enabled : bool = Field(default=True, description="Enable/disable memory-efficient attention", category='Memory/Performance')
tiled_decode : bool = Field(default=False, description="Whether to enable tiled VAE decode (reduces memory consumption with some performance penalty)", category='Memory/Performance') tiled_decode : bool = Field(default=False, description="Whether to enable tiled VAE decode (reduces memory consumption with some performance penalty)", category='Memory/Performance')
conf_path : Path = Field(default='configs/models.yaml', description='Path to models definition file', category='Paths') conf_path : Path = Field(default='configs/models.yaml', description='Path to models definition file', category='Paths')
lora_dir : Path = Field(default=None, description='Path to a directory of LoRA/LyCORIS models to be imported on startup.', category='Paths')
embedding_dir : Path = Field(default=None, description='Path to a directory of Textual Inversion embeddings to be imported on startup.', category='Paths')
controlnet_dir : Path = Field(default=None, description='Path to a directory of ControlNet embeddings to be imported on startup.', category='Paths')
# See InvokeAIAppConfig subclass below for CACHE and DEVICE categories # See InvokeAIAppConfig subclass below for CACHE and DEVICE categories
# fmt: on # fmt: on
@ -340,6 +340,9 @@ class InvokeAIAppConfig(InvokeAISettings):
"xformers_enabled", "xformers_enabled",
"tiled_decode", "tiled_decode",
"conf_path", "conf_path",
"lora_dir",
"embedding_dir",
"controlnet_dir",
] ]
) )
return el return el

View File

@ -178,6 +178,9 @@ class ModelInstallService(ModelInstall, ModelInstallServiceBase):
def start(self, invoker: Any): # Because .processor is giving circular import errors, declaring invoker an 'Any' def start(self, invoker: Any): # Because .processor is giving circular import errors, declaring invoker an 'Any'
"""Call automatically at process start.""" """Call automatically at process start."""
self.scan_models_directory() # synchronize new/deleted models found in models directory self.scan_models_directory() # synchronize new/deleted models found in models directory
if autoimport := self._app_config.autoimport_dir:
self._logger.info("Scanning autoimport directory for new models")
self.scan_directory(self._app_config.root_path / autoimport)
def install_model( def install_model(
self, self,

View File

@ -587,8 +587,8 @@ Use cursor arrows to make a checkbox selection, and space to toggle.
self.autoimport_dirs = {} self.autoimport_dirs = {}
self.autoimport_dirs["autoimport_dir"] = self.add_widget_intelligent( self.autoimport_dirs["autoimport_dir"] = self.add_widget_intelligent(
FileBox, FileBox,
name="Folder to recursively scan for new checkpoints, ControlNets, LoRAs and TI models", name="Optional folder to scan for new checkpoints, ControlNets, LoRAs and TI models",
value=str(config.root_path / config.autoimport_dir), value=str(config.root_path / config.autoimport_dir) if config.autoimport_dir else "",
select_dir=True, select_dir=True,
must_exist=False, must_exist=False,
use_two_lines=False, use_two_lines=False,
@ -678,6 +678,8 @@ https://huggingface.co/stabilityai/stable-diffusion-xl-base-1.0/blob/main/LICENS
setattr(new_opts, attr, getattr(self, attr).value) setattr(new_opts, attr, getattr(self, attr).value)
for attr in self.autoimport_dirs: for attr in self.autoimport_dirs:
if not self.autoimport_dirs[attr].value:
continue
directory = Path(self.autoimport_dirs[attr].value) directory = Path(self.autoimport_dirs[attr].value)
if directory.is_relative_to(config.root_path): if directory.is_relative_to(config.root_path):
directory = directory.relative_to(config.root_path) directory = directory.relative_to(config.root_path)

View File

@ -764,11 +764,11 @@ class ModelInstall(ModelInstallBase):
installed = set() installed = set()
with Chdir(self._app_config.models_path): with Chdir(self._app_config.models_path):
self._logger.info("Checking for models that have been moved or deleted from disk.") self._logger.info("Checking for models that have been moved or deleted from disk")
for model_config in self._store.all_models(): for model_config in self._store.all_models():
path = Path(model_config.path) path = Path(model_config.path)
if not path.exists(): if not path.exists():
self._logger.info(f"{model_config.name}: path {path.as_posix()} no longer exists. Unregistering.") self._logger.info(f"{model_config.name}: path {path.as_posix()} no longer exists. Unregistering")
defunct_models.add(model_config.key) defunct_models.add(model_config.key)
for key in defunct_models: for key in defunct_models:
self.unregister(key) self.unregister(key)