Merge branch 'main' into refactor/rename-get-logger

This commit is contained in:
Lincoln Stein
2023-08-20 16:08:32 -04:00
committed by GitHub
106 changed files with 473 additions and 458 deletions

View File

@@ -1,4 +1,4 @@
"""
Initialization file for invokeai.frontend.CLI
"""
from .CLI import main as invokeai_command_line_interface
from .CLI import main as invokeai_command_line_interface # noqa: F401

View File

@@ -1,4 +1,4 @@
"""
Wrapper for invokeai.backend.configure.invokeai_configure
"""
from ...backend.install.invokeai_configure import main as invokeai_configure
from ...backend.install.invokeai_configure import main as invokeai_configure # noqa: F401

View File

@@ -80,7 +80,7 @@ def welcome(versions: dict):
def get_extras():
extras = ""
try:
dist = pkg_resources.get_distribution("xformers")
_ = pkg_resources.get_distribution("xformers")
extras = "[xformers]"
except pkg_resources.DistributionNotFound:
pass
@@ -90,7 +90,7 @@ def get_extras():
def main():
versions = get_versions()
if invokeai_is_running():
print(f":exclamation: [bold red]Please terminate all running instances of InvokeAI before updating.[/red bold]")
print(":exclamation: [bold red]Please terminate all running instances of InvokeAI before updating.[/red bold]")
input("Press any key to continue...")
return
@@ -122,9 +122,9 @@ def main():
print("")
print("")
if os.system(cmd) == 0:
print(f":heavy_check_mark: Upgrade successful")
print(":heavy_check_mark: Upgrade successful")
else:
print(f":exclamation: [bold red]Upgrade failed[/red bold]")
print(":exclamation: [bold red]Upgrade failed[/red bold]")
if __name__ == "__main__":

View File

@@ -251,7 +251,7 @@ class addModelsForm(CyclingForm, npyscreen.FormMultiPage):
) -> dict[str, npyscreen.widget]:
"""Generic code to create model selection widgets"""
widgets = dict()
model_list = [x for x in self.all_models if self.all_models[x].model_type == model_type and not x in exclude]
model_list = [x for x in self.all_models if self.all_models[x].model_type == model_type and x not in exclude]
model_labels = [self.model_labels[x] for x in model_list]
show_recommended = len(self.installed_models) == 0
@@ -357,14 +357,14 @@ class addModelsForm(CyclingForm, npyscreen.FormMultiPage):
try:
v.hidden = True
v.editable = False
except:
except Exception:
pass
for k, v in widgets[selected_tab].items():
try:
v.hidden = False
if not isinstance(v, (npyscreen.FixedText, npyscreen.TitleFixedText, CenteredTitleText)):
v.editable = True
except:
except Exception:
pass
self.__class__.current_tab = selected_tab # for persistence
self.display()
@@ -541,7 +541,7 @@ class addModelsForm(CyclingForm, npyscreen.FormMultiPage):
self.ti_models,
]
for section in ui_sections:
if not "models_selected" in section:
if "models_selected" not in section:
continue
selected = set([section["models"][x] for x in section["models_selected"].value])
models_to_install = [x for x in selected if not self.all_models[x].installed]
@@ -637,7 +637,7 @@ def _ask_user_for_pt_tui(model_path: Path, tui_conn: Connection) -> SchedulerPre
return None
else:
return response
except:
except Exception:
return None
@@ -673,8 +673,7 @@ def process_and_execute(
def select_and_download_models(opt: Namespace):
precision = "float32" if opt.full_precision else choose_precision(torch.device(choose_torch_device()))
config.precision = precision
helper = lambda x: ask_user_for_prediction_type(x)
installer = ModelInstall(config, prediction_type_helper=helper)
installer = ModelInstall(config, prediction_type_helper=ask_user_for_prediction_type)
if opt.list_models:
installer.list_models(opt.list_models)
elif opt.add or opt.delete:

View File

@@ -102,8 +102,8 @@ def set_min_terminal_size(min_cols: int, min_lines: int) -> bool:
class IntSlider(npyscreen.Slider):
def translate_value(self):
stri = "%2d / %2d" % (self.value, self.out_of)
l = (len(str(self.out_of))) * 2 + 4
stri = stri.rjust(l)
length = (len(str(self.out_of))) * 2 + 4
stri = stri.rjust(length)
return stri
@@ -167,8 +167,8 @@ class FloatSlider(npyscreen.Slider):
# this is supposed to adjust display precision, but doesn't
def translate_value(self):
stri = "%3.2f / %3.2f" % (self.value, self.out_of)
l = (len(str(self.out_of))) * 2 + 4
stri = stri.rjust(l)
length = (len(str(self.out_of))) * 2 + 4
stri = stri.rjust(length)
return stri

View File

@@ -1,4 +1,3 @@
import os
import sys
import argparse

View File

@@ -1,4 +1,4 @@
"""
Initialization file for invokeai.frontend.merge
"""
from .merge_diffusers import main as invokeai_merge_diffusers
from .merge_diffusers import main as invokeai_merge_diffusers # noqa: F401

View File

@@ -9,19 +9,15 @@ import curses
import sys
from argparse import Namespace
from pathlib import Path
from typing import List, Union
from typing import List, Optional
import npyscreen
from diffusers import DiffusionPipeline
from diffusers import logging as dlogging
from npyscreen import widget
from omegaconf import OmegaConf
import invokeai.backend.util.logging as logger
from invokeai.app.services.config import InvokeAIAppConfig
from invokeai.backend.model_management import (
ModelMerger,
MergeInterpolationMethod,
ModelManager,
ModelType,
BaseModelType,
@@ -318,7 +314,7 @@ class mergeModelsForm(npyscreen.FormMultiPageAction):
else:
return True
def get_model_names(self, base_model: BaseModelType = None) -> List[str]:
def get_model_names(self, base_model: Optional[BaseModelType] = None) -> List[str]:
model_names = [
info["model_name"]
for info in self.model_manager.list_models(model_type=ModelType.Main, base_model=base_model)

View File

@@ -1,4 +1,4 @@
"""
Initialization file for invokeai.frontend.training
"""
from .textual_inversion import main as invokeai_textual_inversion
from .textual_inversion import main as invokeai_textual_inversion # noqa: F401

View File

@@ -59,7 +59,7 @@ class textualInversionForm(npyscreen.FormMultiPageAction):
try:
default = self.model_names.index(saved_args["model"])
except:
except Exception:
pass
self.add_widget_intelligent(
@@ -377,7 +377,7 @@ def previous_args() -> dict:
try:
conf = OmegaConf.load(conf_file)
conf["placeholder_token"] = conf["placeholder_token"].strip("<>")
except:
except Exception:
conf = None
return conf

View File

@@ -4,7 +4,7 @@ import { InvokeLogLevel } from 'app/logging/logger';
import { userInvoked } from 'app/store/actions';
import { nodeTemplatesBuilt } from 'features/nodes/store/nodesSlice';
import { t } from 'i18next';
import { startCase } from 'lodash-es';
import { startCase, upperFirst } from 'lodash-es';
import { LogLevelName } from 'roarr';
import {
isAnySessionRejected,
@@ -26,6 +26,7 @@ import {
import { ProgressImage } from 'services/events/types';
import { makeToast } from '../util/makeToast';
import { LANGUAGES } from './constants';
import { zPydanticValidationError } from './zodSchemas';
export type CancelStrategy = 'immediate' | 'scheduled';
@@ -361,9 +362,24 @@ export const systemSlice = createSlice({
state.progressImage = null;
let errorDescription = undefined;
const duration = 5000;
if (action.payload?.status === 422) {
errorDescription = 'Validation Error';
const result = zPydanticValidationError.safeParse(action.payload);
if (result.success) {
result.data.error.detail.map((e) => {
state.toastQueue.push(
makeToast({
title: upperFirst(e.msg),
status: 'error',
description: `Path:
${e.loc.slice(3).join('.')}`,
duration,
})
);
});
return;
}
} else if (action.payload?.error) {
errorDescription = action.payload?.error as string;
}
@@ -373,6 +389,7 @@ export const systemSlice = createSlice({
title: t('toast.serverError'),
status: 'error',
description: errorDescription,
duration,
})
);
});

View File

@@ -0,0 +1,14 @@
import { z } from 'zod';
export const zPydanticValidationError = z.object({
status: z.literal(422),
error: z.object({
detail: z.array(
z.object({
loc: z.array(z.string()),
msg: z.string(),
type: z.string(),
})
),
}),
});