better error toast

This commit is contained in:
Qing 2023-05-18 13:07:12 +08:00
parent 24737ec3dd
commit a85d87a744
5 changed files with 60 additions and 16 deletions

View File

@ -22,6 +22,8 @@
padding: 15px;
display: flex;
align-items: center;
max-width: 400px;
cursor: pointer;
gap: 12px;

View File

@ -19,6 +19,27 @@ export enum AIModel {
PIX2PIX = 'instruct_pix2pix',
}
export enum ControlNetMethod {
canny = 'canny',
inpaint = 'inpaint',
openpose = 'openpose',
depth = 'depth',
}
export const ControlNetMethodMap: any = {
canny: 'control_v11p_sd15_canny',
inpaint: 'control_v11p_sd15_inpaint',
openpose: 'control_v11p_sd15_openpose',
depth: 'control_v11f1p_sd15_depth',
}
export const ControlNetMethodMap2: any = {
control_v11p_sd15_canny: 'canny',
control_v11p_sd15_inpaint: 'inpaint',
control_v11p_sd15_openpose: 'openpose',
control_v11f1p_sd15_depth: 'depth',
}
export const maskState = atom<File | undefined>({
key: 'maskState',
default: undefined,
@ -52,6 +73,7 @@ interface AppState {
gifImage: HTMLImageElement | undefined
brushSize: number
isControlNet: boolean
controlNetMethod: string
plugins: string[]
isPluginRunning: boolean
}
@ -74,6 +96,7 @@ export const appState = atom<AppState>({
gifImage: undefined,
brushSize: 40,
isControlNet: false,
controlNetMethod: ControlNetMethod.canny,
plugins: [],
isPluginRunning: false,
},
@ -119,6 +142,7 @@ export const serverConfigState = selector({
const app = get(appState)
return {
isControlNet: app.isControlNet,
controlNetMethod: app.controlNetMethod,
isDisableModelSwitchState: app.isDisableModelSwitch,
isEnableAutoSaving: app.isEnableAutoSaving,
enableFileManager: app.enableFileManager,
@ -127,7 +151,14 @@ export const serverConfigState = selector({
},
set: ({ get, set }, newValue: any) => {
const app = get(appState)
set(appState, { ...app, ...newValue })
const methodShortName = ControlNetMethodMap2[newValue.controlNetMethod]
set(appState, { ...app, ...newValue, controlnetMethod: methodShortName })
const setting = get(settingState)
set(settingState, {
...setting,
controlnetMethod: methodShortName,
})
},
})
@ -547,18 +578,6 @@ export enum SDSampler {
uni_pc = 'uni_pc',
}
export enum ControlNetMethod {
canny = 'canny',
inpaint = 'inpaint',
openpose = 'openpose',
}
export const ControlNetMethodMap: any = {
canny: 'control_v11p_sd15_canny',
inpaint: 'control_v11p_sd15_inpaint',
openpose: 'control_v11p_sd15_openpose',
}
export enum SDMode {
text2img = 'text2img',
img2img = 'img2img',
@ -610,7 +629,7 @@ export const settingStateDefault: Settings = {
p2pGuidanceScale: 7.5,
// ControlNet
controlnetConditioningScale: 1.0,
controlnetConditioningScale: 0.4,
controlnetMethod: ControlNetMethod.canny,
}

View File

@ -152,7 +152,9 @@ class ControlNet(DiffusionInpaintModel):
controlnet = ControlNetModel.from_pretrained(
f"lllyasviel/{sd_controlnet_method}", torch_dtype=torch_dtype
)
self.is_local_sd_model = False
if kwargs.get("sd_local_model_path", None):
self.is_local_sd_model = True
self.model = load_from_local_model(
kwargs["sd_local_model_path"],
torch_dtype=torch_dtype,
@ -194,7 +196,6 @@ class ControlNet(DiffusionInpaintModel):
mask: [H, W, 1] 255 means area to repaint
return: BGR IMAGE
"""
scheduler_config = self.model.scheduler.config
scheduler = get_scheduler(config.sd_sampler, scheduler_config)
self.model.scheduler = scheduler

View File

@ -85,6 +85,24 @@ class ModelManager:
return
if self.kwargs["sd_controlnet_method"] == control_method:
return
if self.model.is_local_sd_model:
# is_native_control_inpaint 表示加载了普通 SD 模型
if (
self.model.is_native_control_inpaint
and control_method != "control_v11p_sd15_inpaint"
):
raise RuntimeError(
f"--sd-local-model-path load a normal SD model, "
f"to use {control_method} you should load an inpainting SD model"
)
elif (
not self.model.is_native_control_inpaint
and control_method == "control_v11p_sd15_inpaint"
):
raise RuntimeError(
f"--sd-local-model-path load an inpainting SD model, "
f"to use {control_method} you should load a norml SD model"
)
del self.model
torch_gc()

View File

@ -110,6 +110,7 @@ device = None
input_image_path: str = None
is_disable_model_switch: bool = False
is_controlnet: bool = False
controlnet_method: str = "control_v11p_sd15_canny"
is_enable_file_manager: bool = False
is_enable_auto_saving: bool = False
is_desktop: bool = False
@ -286,7 +287,7 @@ def process():
return "CUDA out of memory", 500
else:
logger.exception(e)
return "Internal Server Error", 500
return f"{str(e)}", 500
finally:
logger.info(f"process time: {(time.time() - start) * 1000}ms")
torch.cuda.empty_cache()
@ -407,6 +408,7 @@ def run_plugin():
def get_server_config():
return {
"isControlNet": is_controlnet,
"controlNetMethod": controlnet_method,
"isDisableModelSwitchState": is_disable_model_switch,
"isEnableAutoSaving": is_enable_auto_saving,
"enableFileManager": is_enable_file_manager,
@ -526,6 +528,7 @@ def main(args):
global output_dir
global is_enable_auto_saving
global is_controlnet
global controlnet_method
global image_quality
build_plugins(args)
@ -534,6 +537,7 @@ def main(args):
if args.sd_controlnet and args.model in SD15_MODELS:
is_controlnet = True
controlnet_method = args.sd_controlnet_method
output_dir = args.output_dir
if output_dir: