better error toast
This commit is contained in:
parent
24737ec3dd
commit
a85d87a744
@ -22,6 +22,8 @@
|
|||||||
padding: 15px;
|
padding: 15px;
|
||||||
display: flex;
|
display: flex;
|
||||||
align-items: center;
|
align-items: center;
|
||||||
|
max-width: 400px;
|
||||||
|
cursor: pointer;
|
||||||
|
|
||||||
gap: 12px;
|
gap: 12px;
|
||||||
|
|
||||||
|
@ -19,6 +19,27 @@ export enum AIModel {
|
|||||||
PIX2PIX = 'instruct_pix2pix',
|
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>({
|
export const maskState = atom<File | undefined>({
|
||||||
key: 'maskState',
|
key: 'maskState',
|
||||||
default: undefined,
|
default: undefined,
|
||||||
@ -52,6 +73,7 @@ interface AppState {
|
|||||||
gifImage: HTMLImageElement | undefined
|
gifImage: HTMLImageElement | undefined
|
||||||
brushSize: number
|
brushSize: number
|
||||||
isControlNet: boolean
|
isControlNet: boolean
|
||||||
|
controlNetMethod: string
|
||||||
plugins: string[]
|
plugins: string[]
|
||||||
isPluginRunning: boolean
|
isPluginRunning: boolean
|
||||||
}
|
}
|
||||||
@ -74,6 +96,7 @@ export const appState = atom<AppState>({
|
|||||||
gifImage: undefined,
|
gifImage: undefined,
|
||||||
brushSize: 40,
|
brushSize: 40,
|
||||||
isControlNet: false,
|
isControlNet: false,
|
||||||
|
controlNetMethod: ControlNetMethod.canny,
|
||||||
plugins: [],
|
plugins: [],
|
||||||
isPluginRunning: false,
|
isPluginRunning: false,
|
||||||
},
|
},
|
||||||
@ -119,6 +142,7 @@ export const serverConfigState = selector({
|
|||||||
const app = get(appState)
|
const app = get(appState)
|
||||||
return {
|
return {
|
||||||
isControlNet: app.isControlNet,
|
isControlNet: app.isControlNet,
|
||||||
|
controlNetMethod: app.controlNetMethod,
|
||||||
isDisableModelSwitchState: app.isDisableModelSwitch,
|
isDisableModelSwitchState: app.isDisableModelSwitch,
|
||||||
isEnableAutoSaving: app.isEnableAutoSaving,
|
isEnableAutoSaving: app.isEnableAutoSaving,
|
||||||
enableFileManager: app.enableFileManager,
|
enableFileManager: app.enableFileManager,
|
||||||
@ -127,7 +151,14 @@ export const serverConfigState = selector({
|
|||||||
},
|
},
|
||||||
set: ({ get, set }, newValue: any) => {
|
set: ({ get, set }, newValue: any) => {
|
||||||
const app = get(appState)
|
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',
|
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 {
|
export enum SDMode {
|
||||||
text2img = 'text2img',
|
text2img = 'text2img',
|
||||||
img2img = 'img2img',
|
img2img = 'img2img',
|
||||||
@ -610,7 +629,7 @@ export const settingStateDefault: Settings = {
|
|||||||
p2pGuidanceScale: 7.5,
|
p2pGuidanceScale: 7.5,
|
||||||
|
|
||||||
// ControlNet
|
// ControlNet
|
||||||
controlnetConditioningScale: 1.0,
|
controlnetConditioningScale: 0.4,
|
||||||
controlnetMethod: ControlNetMethod.canny,
|
controlnetMethod: ControlNetMethod.canny,
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -152,7 +152,9 @@ class ControlNet(DiffusionInpaintModel):
|
|||||||
controlnet = ControlNetModel.from_pretrained(
|
controlnet = ControlNetModel.from_pretrained(
|
||||||
f"lllyasviel/{sd_controlnet_method}", torch_dtype=torch_dtype
|
f"lllyasviel/{sd_controlnet_method}", torch_dtype=torch_dtype
|
||||||
)
|
)
|
||||||
|
self.is_local_sd_model = False
|
||||||
if kwargs.get("sd_local_model_path", None):
|
if kwargs.get("sd_local_model_path", None):
|
||||||
|
self.is_local_sd_model = True
|
||||||
self.model = load_from_local_model(
|
self.model = load_from_local_model(
|
||||||
kwargs["sd_local_model_path"],
|
kwargs["sd_local_model_path"],
|
||||||
torch_dtype=torch_dtype,
|
torch_dtype=torch_dtype,
|
||||||
@ -194,7 +196,6 @@ class ControlNet(DiffusionInpaintModel):
|
|||||||
mask: [H, W, 1] 255 means area to repaint
|
mask: [H, W, 1] 255 means area to repaint
|
||||||
return: BGR IMAGE
|
return: BGR IMAGE
|
||||||
"""
|
"""
|
||||||
|
|
||||||
scheduler_config = self.model.scheduler.config
|
scheduler_config = self.model.scheduler.config
|
||||||
scheduler = get_scheduler(config.sd_sampler, scheduler_config)
|
scheduler = get_scheduler(config.sd_sampler, scheduler_config)
|
||||||
self.model.scheduler = scheduler
|
self.model.scheduler = scheduler
|
||||||
|
@ -85,6 +85,24 @@ class ModelManager:
|
|||||||
return
|
return
|
||||||
if self.kwargs["sd_controlnet_method"] == control_method:
|
if self.kwargs["sd_controlnet_method"] == control_method:
|
||||||
return
|
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
|
del self.model
|
||||||
torch_gc()
|
torch_gc()
|
||||||
|
@ -110,6 +110,7 @@ device = None
|
|||||||
input_image_path: str = None
|
input_image_path: str = None
|
||||||
is_disable_model_switch: bool = False
|
is_disable_model_switch: bool = False
|
||||||
is_controlnet: bool = False
|
is_controlnet: bool = False
|
||||||
|
controlnet_method: str = "control_v11p_sd15_canny"
|
||||||
is_enable_file_manager: bool = False
|
is_enable_file_manager: bool = False
|
||||||
is_enable_auto_saving: bool = False
|
is_enable_auto_saving: bool = False
|
||||||
is_desktop: bool = False
|
is_desktop: bool = False
|
||||||
@ -286,7 +287,7 @@ def process():
|
|||||||
return "CUDA out of memory", 500
|
return "CUDA out of memory", 500
|
||||||
else:
|
else:
|
||||||
logger.exception(e)
|
logger.exception(e)
|
||||||
return "Internal Server Error", 500
|
return f"{str(e)}", 500
|
||||||
finally:
|
finally:
|
||||||
logger.info(f"process time: {(time.time() - start) * 1000}ms")
|
logger.info(f"process time: {(time.time() - start) * 1000}ms")
|
||||||
torch.cuda.empty_cache()
|
torch.cuda.empty_cache()
|
||||||
@ -407,6 +408,7 @@ def run_plugin():
|
|||||||
def get_server_config():
|
def get_server_config():
|
||||||
return {
|
return {
|
||||||
"isControlNet": is_controlnet,
|
"isControlNet": is_controlnet,
|
||||||
|
"controlNetMethod": controlnet_method,
|
||||||
"isDisableModelSwitchState": is_disable_model_switch,
|
"isDisableModelSwitchState": is_disable_model_switch,
|
||||||
"isEnableAutoSaving": is_enable_auto_saving,
|
"isEnableAutoSaving": is_enable_auto_saving,
|
||||||
"enableFileManager": is_enable_file_manager,
|
"enableFileManager": is_enable_file_manager,
|
||||||
@ -526,6 +528,7 @@ def main(args):
|
|||||||
global output_dir
|
global output_dir
|
||||||
global is_enable_auto_saving
|
global is_enable_auto_saving
|
||||||
global is_controlnet
|
global is_controlnet
|
||||||
|
global controlnet_method
|
||||||
global image_quality
|
global image_quality
|
||||||
|
|
||||||
build_plugins(args)
|
build_plugins(args)
|
||||||
@ -534,6 +537,7 @@ def main(args):
|
|||||||
|
|
||||||
if args.sd_controlnet and args.model in SD15_MODELS:
|
if args.sd_controlnet and args.model in SD15_MODELS:
|
||||||
is_controlnet = True
|
is_controlnet = True
|
||||||
|
controlnet_method = args.sd_controlnet_method
|
||||||
|
|
||||||
output_dir = args.output_dir
|
output_dir = args.output_dir
|
||||||
if output_dir:
|
if output_dir:
|
||||||
|
Loading…
Reference in New Issue
Block a user