diff --git a/invokeai/frontend/web/src/features/ui/components/tabs/ModelManager/subpanels/AddModelsPanel/AdvancedAddCheckpoint.tsx b/invokeai/frontend/web/src/features/ui/components/tabs/ModelManager/subpanels/AddModelsPanel/AdvancedAddCheckpoint.tsx index 8a525c543b..85dfb0ed8b 100644 --- a/invokeai/frontend/web/src/features/ui/components/tabs/ModelManager/subpanels/AddModelsPanel/AdvancedAddCheckpoint.tsx +++ b/invokeai/frontend/web/src/features/ui/components/tabs/ModelManager/subpanels/AddModelsPanel/AdvancedAddCheckpoint.tsx @@ -14,6 +14,7 @@ import { setAdvancedAddScanModel } from '../../store/modelManagerSlice'; import BaseModelSelect from '../shared/BaseModelSelect'; import CheckpointConfigsSelect from '../shared/CheckpointConfigsSelect'; import ModelVariantSelect from '../shared/ModelVariantSelect'; +import { getModelName } from './util'; type AdvancedAddCheckpointProps = { model_path?: string; @@ -28,7 +29,7 @@ export default function AdvancedAddCheckpoint( const advancedAddCheckpointForm = useForm({ initialValues: { - model_name: model_path?.match(/[^\\/]+$/)?.[0]?.split('.')[0] ?? '', + model_name: model_path ? getModelName(model_path) : '', base_model: 'sd-1', model_type: 'main', path: model_path ? model_path : '', @@ -102,10 +103,7 @@ export default function AdvancedAddCheckpoint( {...advancedAddCheckpointForm.getInputProps('path')} onBlur={(e) => { if (advancedAddCheckpointForm.values['model_name'] === '') { - const modelName = e.currentTarget.value - .match(/[^\\/]+$/)?.[0] - ?.split('.')[0]; - + const modelName = getModelName(e.currentTarget.value); if (modelName) { advancedAddCheckpointForm.setFieldValue( 'model_name', diff --git a/invokeai/frontend/web/src/features/ui/components/tabs/ModelManager/subpanels/AddModelsPanel/AdvancedAddDiffusers.tsx b/invokeai/frontend/web/src/features/ui/components/tabs/ModelManager/subpanels/AddModelsPanel/AdvancedAddDiffusers.tsx index 469c0c7061..181a6f4234 100644 --- a/invokeai/frontend/web/src/features/ui/components/tabs/ModelManager/subpanels/AddModelsPanel/AdvancedAddDiffusers.tsx +++ b/invokeai/frontend/web/src/features/ui/components/tabs/ModelManager/subpanels/AddModelsPanel/AdvancedAddDiffusers.tsx @@ -11,6 +11,7 @@ import { DiffusersModelConfig } from 'services/api/types'; import { setAdvancedAddScanModel } from '../../store/modelManagerSlice'; import BaseModelSelect from '../shared/BaseModelSelect'; import ModelVariantSelect from '../shared/ModelVariantSelect'; +import { getModelName } from './util'; type AdvancedAddDiffusersProps = { model_path?: string; @@ -25,7 +26,7 @@ export default function AdvancedAddDiffusers(props: AdvancedAddDiffusersProps) { const advancedAddDiffusersForm = useForm({ initialValues: { - model_name: model_path?.match(/[^\\/]+$/)?.[0] ?? '', + model_name: model_path ? getModelName(model_path, false) : '', base_model: 'sd-1', model_type: 'main', path: model_path ? model_path : '', @@ -94,7 +95,7 @@ export default function AdvancedAddDiffusers(props: AdvancedAddDiffusersProps) { {...advancedAddDiffusersForm.getInputProps('path')} onBlur={(e) => { if (advancedAddDiffusersForm.values['model_name'] === '') { - const modelName = e.currentTarget.value.match(/[^\\/]+$/)?.[0]; + const modelName = getModelName(e.currentTarget.value, false); if (modelName) { advancedAddDiffusersForm.setFieldValue( 'model_name', diff --git a/invokeai/frontend/web/src/features/ui/components/tabs/ModelManager/subpanels/AddModelsPanel/util.ts b/invokeai/frontend/web/src/features/ui/components/tabs/ModelManager/subpanels/AddModelsPanel/util.ts new file mode 100644 index 0000000000..7314a86908 --- /dev/null +++ b/invokeai/frontend/web/src/features/ui/components/tabs/ModelManager/subpanels/AddModelsPanel/util.ts @@ -0,0 +1,15 @@ +export function getModelName(filepath: string, isCheckpoint: boolean = true) { + let regex; + if (isCheckpoint) { + regex = new RegExp('[^\\\\/]+(?=\\.)'); + } else { + regex = new RegExp('[^\\\\/]+(?=[\\\\/]?$)'); + } + + const match = filepath.match(regex); + if (match) { + return match[0]; + } else { + return ''; + } +}