Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(ui): allow inplace installs #5890

Merged
merged 4 commits into from
Mar 8, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions invokeai/frontend/web/public/locales/en.json
Original file line number Diff line number Diff line change
Expand Up @@ -766,11 +766,14 @@
"importModels": "Import Models",
"importQueue": "Import Queue",
"inpainting": "v1 Inpainting",
"inplaceInstall": "In-place install",
"inplaceInstallDesc": "Install models without copying the files. When using the model, it will be loaded from its this location. If disabled, the model file(s) will be copied into the Invoke-managed models directory during installation.",
"interpolationType": "Interpolation Type",
"inverseSigmoid": "Inverse Sigmoid",
"invokeAIFolder": "Invoke AI Folder",
"invokeRoot": "InvokeAI folder",
"load": "Load",
"localOnly": "local only",
"loraModels": "LoRAs",
"manual": "Manual",
"merge": "Merge",
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { Button, Flex, FormControl, FormLabel, Input } from '@invoke-ai/ui-library';
import { Button, Checkbox, Flex, FormControl, FormHelperText, FormLabel, Input } 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';
Expand All @@ -10,6 +10,7 @@ import { useInstallModelMutation } from 'services/api/endpoints/models';

type SimpleImportModelConfig = {
location: string;
inplace: boolean;
};

export const InstallModelForm = () => {
Expand All @@ -20,6 +21,7 @@ export const InstallModelForm = () => {
const { register, handleSubmit, formState, reset } = useForm<SimpleImportModelConfig>({
defaultValues: {
location: '',
inplace: true,
},
mode: 'onChange',
});
Expand All @@ -30,7 +32,7 @@ export const InstallModelForm = () => {
return;
}

installModel({ source: values.location })
installModel({ source: values.location, inplace: values.inplace })
.unwrap()
.then((_) => {
dispatch(
Expand All @@ -41,10 +43,10 @@ export const InstallModelForm = () => {
})
)
);
reset();
reset(undefined, { keepValues: true });
})
.catch((error) => {
reset();
reset(undefined, { keepValues: true });
if (error) {
dispatch(
addToast(
Expand All @@ -62,16 +64,35 @@ export const InstallModelForm = () => {

return (
<form onSubmit={handleSubmit(onSubmit)}>
<Flex gap={2} alignItems="flex-end" justifyContent="space-between">
<FormControl>
<Flex direction="column" w="full">
<Flex flexDir="column" gap={4}>
<Flex gap={2} alignItems="flex-end" justifyContent="space-between">
<FormControl orientation="vertical">
<FormLabel>{t('modelManager.modelLocation')}</FormLabel>
<Input {...register('location')} />
</FormControl>
<Button
onClick={handleSubmit(onSubmit)}
isDisabled={!formState.dirtyFields.location}
isLoading={isLoading}
type="submit"
size="sm"
mb={1}
>
{t('modelManager.addModel')}
</Button>
</Flex>

<FormControl>
<Flex flexDir="column" gap={2}>
<Flex gap={4}>
<Checkbox {...register('inplace')} />
<FormLabel>
{t('modelManager.inplaceInstall')} ({t('modelManager.localOnly')})
</FormLabel>
</Flex>
<FormHelperText>{t('modelManager.inplaceInstallDesc')}</FormHelperText>
</Flex>
</FormControl>
<Button onClick={handleSubmit(onSubmit)} isDisabled={!formState.isDirty} isLoading={isLoading} type="submit">
{t('modelManager.addModel')}
</Button>
</Flex>
</form>
);
Expand Down
5 changes: 3 additions & 2 deletions invokeai/frontend/web/src/services/api/endpoints/models.ts
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,7 @@ type ConvertMainModelResponse =

type InstallModelArg = {
source: paths['/api/v2/models/install']['post']['parameters']['query']['source'];
inplace?: paths['/api/v2/models/install']['post']['parameters']['query']['inplace'];
};
type InstallModelResponse = paths['/api/v2/models/install']['post']['responses']['201']['content']['application/json'];

Expand Down Expand Up @@ -176,10 +177,10 @@ export const modelsApi = api.injectEndpoints({
invalidatesTags: ['Model'],
}),
installModel: build.mutation<InstallModelResponse, InstallModelArg>({
query: ({ source }) => {
query: ({ source, inplace = true }) => {
return {
url: buildModelsUrl('install'),
params: { source },
params: { source, inplace },
method: 'POST',
};
},
Expand Down
Loading