Skip to content

Commit 4f2ef7c

Browse files
psychedelicioushipsterusername
authored andcommitted
refactor(ui): handle hf vs civitai/other url model install errors separately
Previously, we didn't differentiate between model install errors for different types of model install sources, resulting in a buggy UX: - If a HF model install failed, but it was a HF URL install and not a repo id install, the link to the HF model page was incorrect. - If a non-HF URL install (e.g. civitai) failed, we treated it as a HF URL install. In this case, if the user's HF token was invalid or unset, we directed the user to set it. If the HF token was valid, we displayed an empty red toast. If it's not a HF URL install, then of course neither of these are correct. Also, the logic for handling the toasts was a bit complicated. This change does a few things: - Consolidate the model install error toasts into one place - the socket.io event handler for the model install error event. There is no more global state for the toasts and there are no hooks managing them. - Handling the different cases for errors, including all combinations of HF/non-HF and unauthorized/forbidden/unknown.
1 parent d7e9ad5 commit 4f2ef7c

File tree

6 files changed

+168
-160
lines changed

6 files changed

+168
-160
lines changed

invokeai/frontend/web/public/locales/en.json

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -743,13 +743,17 @@
743743
"hfTokenHelperText": "A HF token is required to use some models. Click here to create or get your token.",
744744
"hfTokenInvalid": "Invalid or Missing HF Token",
745745
"hfForbidden": "You do not have access to this HF model",
746-
"hfForbiddenErrorMessage": "We recommend visiting the repo page on HuggingFace.com. The owner may require acceptance of terms in order to download.",
746+
"hfForbiddenErrorMessage": "We recommend visiting the repo. The owner may require acceptance of terms in order to download.",
747+
"urlForbidden": "You do not have access to this model",
748+
"urlForbiddenErrorMessage": "You may need to request permission from the site that is distributing the model.",
747749
"hfTokenInvalidErrorMessage": "Invalid or missing HuggingFace token.",
748750
"hfTokenRequired": "You are trying to download a model that requires a valid HuggingFace Token.",
749751
"hfTokenInvalidErrorMessage2": "Update it in the ",
750752
"hfTokenUnableToVerify": "Unable to Verify HF Token",
751753
"hfTokenUnableToVerifyErrorMessage": "Unable to verify HuggingFace token. This is likely due to a network error. Please try again later.",
752754
"hfTokenSaved": "HF Token Saved",
755+
"urlUnauthorizedErrorMessage": "You may need to provide an API key to access this model.",
756+
"urlUnauthorizedErrorMessage2": "Learn how here.",
753757
"imageEncoderModelId": "Image Encoder Model ID",
754758
"includesNModels": "Includes {{n}} models and their dependencies",
755759
"installQueue": "Install Queue",

invokeai/frontend/web/src/features/modelManagerV2/hooks/useHFForbiddenToast.tsx

Lines changed: 0 additions & 45 deletions
This file was deleted.

invokeai/frontend/web/src/features/modelManagerV2/hooks/useHFLoginToast.tsx

Lines changed: 0 additions & 93 deletions
This file was deleted.

invokeai/frontend/web/src/features/modelManagerV2/subpanels/AddModelPanel/HuggingFaceFolder/HFToken.tsx

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,12 +10,12 @@ import {
1010
useToast,
1111
} from '@invoke-ai/ui-library';
1212
import { skipToken } from '@reduxjs/toolkit/query';
13-
import { $isHFLoginToastOpen } from 'features/modelManagerV2/hooks/useHFLoginToast';
1413
import { useFeatureStatus } from 'features/system/hooks/useFeatureStatus';
1514
import type { ChangeEvent } from 'react';
1615
import { useCallback, useMemo, useState } from 'react';
1716
import { useTranslation } from 'react-i18next';
1817
import { useGetHFTokenStatusQuery, useSetHFTokenMutation } from 'services/api/endpoints/models';
18+
import { UNAUTHORIZED_TOAST_ID } from 'services/events/onModelInstallError';
1919

2020
export const HFToken = () => {
2121
const { t } = useTranslation();
@@ -34,11 +34,11 @@ export const HFToken = () => {
3434
if (res === 'valid') {
3535
setToken('');
3636
toast({
37+
id: UNAUTHORIZED_TOAST_ID,
3738
title: t('modelManager.hfTokenSaved'),
3839
status: 'success',
3940
duration: 3000,
4041
});
41-
$isHFLoginToastOpen.set(false);
4242
}
4343
});
4444
}, [t, toast, token, trigger]);

invokeai/frontend/web/src/features/modelManagerV2/subpanels/ModelManager.tsx

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,5 @@
11
import { Button, Flex, Heading } from '@invoke-ai/ui-library';
22
import { useAppDispatch, useAppSelector } from 'app/store/storeHooks';
3-
import { useHFForbiddenToast } from 'features/modelManagerV2/hooks/useHFForbiddenToast';
4-
import { useHFLoginToast } from 'features/modelManagerV2/hooks/useHFLoginToast';
53
import { selectSelectedModelKey, setSelectedModelKey } from 'features/modelManagerV2/store/modelManagerV2Slice';
64
import { memo, useCallback } from 'react';
75
import { useTranslation } from 'react-i18next';
@@ -18,9 +16,6 @@ export const ModelManager = memo(() => {
1816
}, [dispatch]);
1917
const selectedModelKey = useAppSelector(selectSelectedModelKey);
2018

21-
useHFLoginToast();
22-
useHFForbiddenToast();
23-
2419
return (
2520
<Flex flexDir="column" layerStyle="first" p={4} gap={4} borderRadius="base" w="50%" h="full">
2621
<Flex w="full" gap={4} justifyContent="space-between" alignItems="center">

0 commit comments

Comments
 (0)