test and fix edge cases

This commit is contained in:
Lincoln Stein 2023-06-20 09:42:10 -04:00
parent ddb3f4b02b
commit 294b1e83e6
4 changed files with 70 additions and 61 deletions

View File

@ -442,46 +442,46 @@ to allow InvokeAI to download restricted styles & subjects from the "Concept Lib
begin_entry_at=4, begin_entry_at=4,
scroll_exit=True, scroll_exit=True,
) )
self.nextrely += 1 # self.nextrely += 1
self.add_widget_intelligent( # self.add_widget_intelligent(
npyscreen.FixedText, # npyscreen.FixedText,
value="Directories containing textual inversion, controlnet and LoRA models (<tab> autocompletes, ctrl-N advances):", # value="Directories containing textual inversion, controlnet and LoRA models (<tab> autocompletes, ctrl-N advances):",
editable=False, # editable=False,
color="CONTROL", # color="CONTROL",
) # )
self.embedding_dir = self.add_widget_intelligent( # self.embedding_dir = self.add_widget_intelligent(
npyscreen.TitleFilename, # npyscreen.TitleFilename,
name=" Textual Inversion Embeddings:", # name=" Textual Inversion Embeddings:",
value=str(default_embedding_dir()), # value=str(default_embedding_dir()),
select_dir=True, # select_dir=True,
must_exist=False, # must_exist=False,
use_two_lines=False, # use_two_lines=False,
labelColor="GOOD", # labelColor="GOOD",
begin_entry_at=32, # begin_entry_at=32,
scroll_exit=True, # scroll_exit=True,
) # )
self.lora_dir = self.add_widget_intelligent( # self.lora_dir = self.add_widget_intelligent(
npyscreen.TitleFilename, # npyscreen.TitleFilename,
name=" LoRA and LyCORIS:", # name=" LoRA and LyCORIS:",
value=str(default_lora_dir()), # value=str(default_lora_dir()),
select_dir=True, # select_dir=True,
must_exist=False, # must_exist=False,
use_two_lines=False, # use_two_lines=False,
labelColor="GOOD", # labelColor="GOOD",
begin_entry_at=32, # begin_entry_at=32,
scroll_exit=True, # scroll_exit=True,
) # )
self.controlnet_dir = self.add_widget_intelligent( # self.controlnet_dir = self.add_widget_intelligent(
npyscreen.TitleFilename, # npyscreen.TitleFilename,
name=" ControlNets:", # name=" ControlNets:",
value=str(default_controlnet_dir()), # value=str(default_controlnet_dir()),
select_dir=True, # select_dir=True,
must_exist=False, # must_exist=False,
use_two_lines=False, # use_two_lines=False,
labelColor="GOOD", # labelColor="GOOD",
begin_entry_at=32, # begin_entry_at=32,
scroll_exit=True, # scroll_exit=True,
) # )
self.nextrely += 1 self.nextrely += 1
self.add_widget_intelligent( self.add_widget_intelligent(
npyscreen.TitleFixedText, npyscreen.TitleFixedText,
@ -546,10 +546,10 @@ https://huggingface.co/spaces/CompVis/stable-diffusion-license
bad_fields.append( bad_fields.append(
f"The output directory does not seem to be valid. Please check that {str(Path(opt.outdir).parent)} is an existing directory." f"The output directory does not seem to be valid. Please check that {str(Path(opt.outdir).parent)} is an existing directory."
) )
if not Path(opt.embedding_dir).parent.exists(): # if not Path(opt.embedding_dir).parent.exists():
bad_fields.append( # bad_fields.append(
f"The embedding directory does not seem to be valid. Please check that {str(Path(opt.embedding_dir).parent)} is an existing directory." # f"The embedding directory does not seem to be valid. Please check that {str(Path(opt.embedding_dir).parent)} is an existing directory."
) # )
if len(bad_fields) > 0: if len(bad_fields) > 0:
message = "The following problems were detected and must be corrected:\n" message = "The following problems were detected and must be corrected:\n"
for problem in bad_fields: for problem in bad_fields:
@ -569,9 +569,9 @@ https://huggingface.co/spaces/CompVis/stable-diffusion-license
"max_loaded_models", "max_loaded_models",
"xformers_enabled", "xformers_enabled",
"always_use_cpu", "always_use_cpu",
"embedding_dir", # "embedding_dir",
"lora_dir", # "lora_dir",
"controlnet_dir", # "controlnet_dir",
]: ]:
setattr(new_opts, attr, getattr(self, attr).value) setattr(new_opts, attr, getattr(self, attr).value)
@ -591,6 +591,7 @@ class EditOptApplication(npyscreen.NPSAppManaged):
self.program_opts = program_opts self.program_opts = program_opts
self.invokeai_opts = invokeai_opts self.invokeai_opts = invokeai_opts
self.user_cancelled = False self.user_cancelled = False
self.autoload_pending = True
self.install_selections = default_user_selections(program_opts) self.install_selections = default_user_selections(program_opts)
def onStart(self): def onStart(self):
@ -719,17 +720,17 @@ def write_opts(opts: Namespace, init_file: Path):
def default_output_dir() -> Path: def default_output_dir() -> Path:
return config.root_path / "outputs" return config.root_path / "outputs"
# ------------------------------------- # # -------------------------------------
def default_embedding_dir() -> Path: # def default_embedding_dir() -> Path:
return config.root_path / "embeddings" # return config.root_path / "embeddings"
# ------------------------------------- # # -------------------------------------
def default_lora_dir() -> Path: # def default_lora_dir() -> Path:
return config.root_path / "loras" # return config.root_path / "loras"
# ------------------------------------- # # -------------------------------------
def default_controlnet_dir() -> Path: # def default_controlnet_dir() -> Path:
return config.root_path / "controlnets" # return config.root_path / "controlnets"
# ------------------------------------- # -------------------------------------
def write_default_options(program_opts: Namespace, initfile: Path): def write_default_options(program_opts: Namespace, initfile: Path):
@ -755,7 +756,7 @@ def migrate_init_file(legacy_format:Path):
new.nsfw_checker = old.safety_checker new.nsfw_checker = old.safety_checker
new.xformers_enabled = old.xformers new.xformers_enabled = old.xformers
new.conf_path = old.conf new.conf_path = old.conf
new.embedding_dir = old.embedding_path # new.embedding_dir = old.embedding_path
invokeai_yaml = legacy_format.parent / 'invokeai.yaml' invokeai_yaml = legacy_format.parent / 'invokeai.yaml'
with open(invokeai_yaml,"w", encoding="utf-8") as outfile: with open(invokeai_yaml,"w", encoding="utf-8") as outfile:

View File

@ -227,10 +227,14 @@ class ModelInstall(object):
# the model from being probed twice in the event that it has already been probed. # the model from being probed twice in the event that it has already been probed.
def _install_path(self, path: Path, info: ModelProbeInfo=None): def _install_path(self, path: Path, info: ModelProbeInfo=None):
try: try:
logger.info(f'Probing {path}')
info = info or ModelProbe().heuristic_probe(path,self.prediction_helper) info = info or ModelProbe().heuristic_probe(path,self.prediction_helper)
if info.model_type == ModelType.Pipeline: if info.model_type == ModelType.Pipeline:
model_name = path.stem if info.format=='checkpoint' else path.name
if self.mgr.model_exists(model_name, info.base_type, info.model_type):
raise Exception(f'A model named "{model_name}" is already installed.')
attributes = self._make_attributes(path,info) attributes = self._make_attributes(path,info)
self.mgr.add_model(model_name = path.stem if info.format=='checkpoint' else path.name, self.mgr.add_model(model_name = model_name,
base_model = info.base_type, base_model = info.base_type,
model_type = info.model_type, model_type = info.model_type,
model_attributes = attributes model_attributes = attributes
@ -322,7 +326,7 @@ class ModelInstall(object):
) )
if info.format=="checkpoint": if info.format=="checkpoint":
try: try:
legacy_conf = LEGACY_CONFIGS[info.base_type][info.variant_type][info.prediction_type] if BaseModelType.StableDiffusion2 \ legacy_conf = LEGACY_CONFIGS[info.base_type][info.variant_type][info.prediction_type] if info.base_type == BaseModelType.StableDiffusion2 \
else LEGACY_CONFIGS[info.base_type][info.variant_type] else LEGACY_CONFIGS[info.base_type][info.variant_type]
except KeyError: except KeyError:
legacy_conf = 'v1-inference.yaml' # best guess legacy_conf = 'v1-inference.yaml' # best guess

View File

@ -131,6 +131,7 @@ class addModelsForm(CyclingForm, npyscreen.FormMultiPage):
window_width=window_width, window_width=window_width,
exclude = self.starter_models exclude = self.starter_models
) )
self.pipeline_models['autoload_pending'] = True
bottom_of_table = max(bottom_of_table,self.nextrely) bottom_of_table = max(bottom_of_table,self.nextrely)
self.nextrely = top_of_table self.nextrely = top_of_table
@ -545,7 +546,9 @@ class addModelsForm(CyclingForm, npyscreen.FormMultiPage):
selections.install_models.extend(downloads.value.split()) selections.install_models.extend(downloads.value.split())
# load directory and whether to scan on startup # load directory and whether to scan on startup
if self.parentApp.autoload_pending:
selections.scan_directory = self.pipeline_models['autoload_directory'].value selections.scan_directory = self.pipeline_models['autoload_directory'].value
self.parentApp.autoload_pending = False
selections.autoscan_on_startup = self.pipeline_models['autoscan_on_startup'].value selections.autoscan_on_startup = self.pipeline_models['autoscan_on_startup'].value
class AddModelApplication(npyscreen.NPSAppManaged): class AddModelApplication(npyscreen.NPSAppManaged):
@ -553,6 +556,7 @@ class AddModelApplication(npyscreen.NPSAppManaged):
super().__init__() super().__init__()
self.program_opts = opt self.program_opts = opt
self.user_cancelled = False self.user_cancelled = False
self.autoload_pending = True
self.install_selections = InstallSelections() self.install_selections = InstallSelections()
def onStart(self): def onStart(self):

View File

@ -378,7 +378,7 @@ def select_stable_diffusion_config_file(
wrap:bool =True, wrap:bool =True,
model_name:str='Unknown', model_name:str='Unknown',
): ):
message = "Please select the correct base model for the V2 checkpoint named {model_name}. Press <CANCEL> to skip installation." message = f"Please select the correct base model for the V2 checkpoint named '{model_name}'. Press <CANCEL> to skip installation."
title = "CONFIG FILE SELECTION" title = "CONFIG FILE SELECTION"
options=[ options=[
"An SD v2.x base model (512 pixels; no 'parameterization:' line in its yaml file)", "An SD v2.x base model (512 pixels; no 'parameterization:' line in its yaml file)",