From 2db252af3194c95540f7224a478771793be2ff06 Mon Sep 17 00:00:00 2001 From: Jennifer Player Date: Thu, 22 Feb 2024 18:56:51 -0500 Subject: [PATCH] added advanced import forms, not fully working yet --- invokeai/frontend/web/public/locales/en.json | 1 + .../AddModelPanel/AdvancedImport.tsx | 56 ++++++ .../AdvancedImportCheckpoint.tsx | 160 ++++++++++++++++++ .../AddModelPanel/AdvancedImportDiffusers.tsx | 132 +++++++++++++++ .../AddModelPanel/BaseModelSelect.tsx | 38 +++++ .../AddModelPanel/CheckpointConfigsSelect.tsx | 32 ++++ .../AddModelPanel/ImportQueueModel.tsx | 9 +- .../AddModelPanel/ModelVariantSelect.tsx | 36 ++++ .../AddModelPanel/ScanModels/ScanModels.tsx | 3 +- .../ScanModels/ScanModelsForm.tsx | 9 +- .../ScanModels/ScanModelsResults.tsx | 10 +- .../subpanels/AddModelPanel/SimpleImport.tsx | 75 ++++---- .../modelManagerV2/subpanels/ImportModels.tsx | 9 +- .../web/src/services/api/endpoints/models.ts | 2 +- 14 files changed, 522 insertions(+), 50 deletions(-) create mode 100644 invokeai/frontend/web/src/features/modelManagerV2/subpanels/AddModelPanel/AdvancedImport.tsx create mode 100644 invokeai/frontend/web/src/features/modelManagerV2/subpanels/AddModelPanel/AdvancedImportCheckpoint.tsx create mode 100644 invokeai/frontend/web/src/features/modelManagerV2/subpanels/AddModelPanel/AdvancedImportDiffusers.tsx create mode 100644 invokeai/frontend/web/src/features/modelManagerV2/subpanels/AddModelPanel/BaseModelSelect.tsx create mode 100644 invokeai/frontend/web/src/features/modelManagerV2/subpanels/AddModelPanel/CheckpointConfigsSelect.tsx create mode 100644 invokeai/frontend/web/src/features/modelManagerV2/subpanels/AddModelPanel/ModelVariantSelect.tsx diff --git a/invokeai/frontend/web/public/locales/en.json b/invokeai/frontend/web/public/locales/en.json index 4d40f7105c..dfb0103dff 100644 --- a/invokeai/frontend/web/public/locales/en.json +++ b/invokeai/frontend/web/public/locales/en.json @@ -696,6 +696,7 @@ "addNewModel": "Add New Model", "addSelected": "Add Selected", "advanced": "Advanced", + "advancedImportInfo": "The advanced tab allows for manual configuration of core model settings. Only use this tab if you are confident that you know the correct model type and configuration for the selected model.", "allModels": "All Models", "alpha": "Alpha", "availableModels": "Available Models", diff --git a/invokeai/frontend/web/src/features/modelManagerV2/subpanels/AddModelPanel/AdvancedImport.tsx b/invokeai/frontend/web/src/features/modelManagerV2/subpanels/AddModelPanel/AdvancedImport.tsx new file mode 100644 index 0000000000..9ec39a0649 --- /dev/null +++ b/invokeai/frontend/web/src/features/modelManagerV2/subpanels/AddModelPanel/AdvancedImport.tsx @@ -0,0 +1,56 @@ +import type { ComboboxOnChange, ComboboxOption } from '@invoke-ai/ui-library'; +import { Combobox, Flex, FormLabel,Text } from '@invoke-ai/ui-library'; +import ScrollableContent from 'common/components/OverlayScrollbars/ScrollableContent'; +import { useCallback, useMemo, useState } from 'react'; +import { useTranslation } from 'react-i18next'; +import { z } from 'zod'; + +import { AdvancedImportCheckpoint } from './AdvancedImportCheckpoint'; +import { AdvancedImportDiffusers } from './AdvancedImportDiffusers'; + +export const zManualAddMode = z.enum(['diffusers', 'checkpoint']); +export type ManualAddMode = z.infer; +export const isManualAddMode = (v: unknown): v is ManualAddMode => zManualAddMode.safeParse(v).success; + +export const AdvancedImport = () => { + const [advancedAddMode, setAdvancedAddMode] = useState('diffusers'); + + const { t } = useTranslation(); + const handleChange: ComboboxOnChange = useCallback((v) => { + if (!isManualAddMode(v?.value)) { + return; + } + setAdvancedAddMode(v.value); + }, []); + + const options: ComboboxOption[] = useMemo( + () => [ + { label: t('modelManager.diffusersModels'), value: 'diffusers' }, + { label: t('modelManager.checkpointOrSafetensors'), value: 'checkpoint' }, + ], + [t] + ); + + const value = useMemo(() => options.find((o) => o.value === advancedAddMode), [options, advancedAddMode]); + + return ( + + + + + {t('modelManager.modelType')} + + + + {t('modelManager.advancedImportInfo')} + + + + + {advancedAddMode === 'diffusers' && } + {advancedAddMode === 'checkpoint' && } + + + + ); +}; diff --git a/invokeai/frontend/web/src/features/modelManagerV2/subpanels/AddModelPanel/AdvancedImportCheckpoint.tsx b/invokeai/frontend/web/src/features/modelManagerV2/subpanels/AddModelPanel/AdvancedImportCheckpoint.tsx new file mode 100644 index 0000000000..bf22ef12d1 --- /dev/null +++ b/invokeai/frontend/web/src/features/modelManagerV2/subpanels/AddModelPanel/AdvancedImportCheckpoint.tsx @@ -0,0 +1,160 @@ +import { + Button, + Checkbox, + Flex, + FormControl, + FormErrorMessage, + FormLabel, + Input, + Textarea, +} from '@invoke-ai/ui-library'; +import { useAppDispatch } from 'app/store/storeHooks'; +import { addToast } from 'features/system/store/systemSlice'; +import { makeToast } from 'features/system/util/makeToast'; +import type { CSSProperties } from 'react'; +import { useCallback, useState } from 'react'; +import type { SubmitHandler } from 'react-hook-form'; +import { useForm } from 'react-hook-form'; +import { useTranslation } from 'react-i18next'; +import { useAddMainModelsMutation } from 'services/api/endpoints/models'; +import type { CheckpointModelConfig, DiffusersModelConfig } from 'services/api/types'; + +import BaseModelSelect from './BaseModelSelect'; +import CheckpointConfigsSelect from './CheckpointConfigsSelect'; +import ModelVariantSelect from './ModelVariantSelect'; + +export const AdvancedImportCheckpoint = () => { + const { t } = useTranslation(); + const dispatch = useAppDispatch(); + + const [addMainModel] = useAddMainModelsMutation(); + + const [useCustomConfig, setUseCustomConfig] = useState(false); + + const { + register, + handleSubmit, + control, + formState: { errors }, + reset, + } = useForm({ + defaultValues: { + name: '', + base: 'sd-1', + type: 'main', + path: '', + description: '', + format: 'checkpoint', + vae: '', + variant: 'normal', + config: '', + }, + mode: 'onChange', + }); + + const onSubmit = useCallback>( + (values) => { + addMainModel({ + body: values, + }) + .unwrap() + .then((_) => { + dispatch( + addToast( + makeToast({ + title: t('modelManager.modelAdded', { + modelName: values.name, + }), + status: 'success', + }) + ) + ); + reset(); + }) + .catch((error) => { + if (error) { + dispatch( + addToast( + makeToast({ + title: t('toast.modelAddFailed'), + status: 'error', + }) + ) + ); + } + }); + }, + [addMainModel, dispatch, reset, t] + ); + + const handleChangeUseCustomConfig = useCallback(() => setUseCustomConfig((prev) => !prev), []); + + return ( +
+ + + + {t('modelManager.name')} + value.trim().length > 3 || 'Must be at least 3 characters', + })} + /> + {errors.name?.message && {errors.name?.message}} + + + + + + {t('modelManager.description')} +