fixed error handling

This commit is contained in:
Jennifer Player
2024-03-11 11:46:49 -04:00
committed by psychedelicious
parent 6369ccd05e
commit 5ad048a161
7 changed files with 31 additions and 21 deletions

View File

@ -261,11 +261,16 @@ async def get_hugging_face_models(
hugging_face_repo: str = Query(description="Hugging face repo to search for models", default=None), hugging_face_repo: str = Query(description="Hugging face repo to search for models", default=None),
) -> List[AnyHttpUrl]: ) -> List[AnyHttpUrl]:
get_hugging_face_models = ApiDependencies.invoker.services.model_manager.install.get_hugging_face_models get_hugging_face_models = ApiDependencies.invoker.services.model_manager.install.get_hugging_face_models
get_hugging_face_models(hugging_face_repo)
try:
result = get_hugging_face_models( result = get_hugging_face_models(
source=hugging_face_repo, source=hugging_face_repo,
) )
except ValueError as e:
raise HTTPException(
status_code=400,
detail=f"{e}",
)
return result return result

View File

@ -239,7 +239,11 @@ class ModelInstallService(ModelInstallServiceBase):
if not access_token: if not access_token:
self._logger.info("No HuggingFace access token present; some models may not be downloadable.") self._logger.info("No HuggingFace access token present; some models may not be downloadable.")
try:
metadata = HuggingFaceMetadataFetch(self._session).from_id(source) metadata = HuggingFaceMetadataFetch(self._session).from_id(source)
except:
raise ValueError("No HuggingFace repository found")
assert isinstance(metadata, ModelMetadataWithFiles) assert isinstance(metadata, ModelMetadataWithFiles)
urls: List[AnyHttpUrl] = [] urls: List[AnyHttpUrl] = []

View File

@ -858,7 +858,7 @@
"settings": "Settings", "settings": "Settings",
"showExisting": "Show Existing", "showExisting": "Show Existing",
"sigmoid": "Sigmoid", "sigmoid": "Sigmoid",
"simpleModelPlaceholder": "URL or path to a local file", "simpleModelPlaceholder": "URL or path to a local file or diffusers folder",
"simpleModelDesc": "Provide a path to a local Diffusers model, local checkpoint / safetensors model a HuggingFace Repo ID, or a checkpoint/diffusers model URL.", "simpleModelDesc": "Provide a path to a local Diffusers model, local checkpoint / safetensors model a HuggingFace Repo ID, or a checkpoint/diffusers model URL.",
"source": "Source", "source": "Source",
"statusConverting": "Converting", "statusConverting": "Converting",

View File

@ -51,21 +51,20 @@ export const HuggingFaceForm = () => {
const getModels = useCallback(async () => { const getModels = useCallback(async () => {
_getHuggingFaceModels(huggingFaceRepo) _getHuggingFaceModels(huggingFaceRepo)
.unwrap()
.then((response) => { .then((response) => {
if (response.data?.some((result) => result.endsWith('model_index.json'))) { if (response.some((result: string) => result.endsWith('model_index.json'))) {
handleInstallModel(huggingFaceRepo); handleInstallModel(huggingFaceRepo);
setDisplayResults(false); setDisplayResults(false);
} else if (response.data?.length === 1 && response.data[0]) { } else if (response.length === 1 && response[0]) {
handleInstallModel(response.data[0]); handleInstallModel(response[0]);
setDisplayResults(false); setDisplayResults(false);
} else { } else {
setDisplayResults(true); setDisplayResults(true);
} }
}) })
.catch((error) => { .catch((error) => {
if (error) { setErrorMessage(error.data.detail || '');
setErrorMessage(error.data.detail);
}
}); });
}, [_getHuggingFaceModels, handleInstallModel, huggingFaceRepo]); }, [_getHuggingFaceModels, handleInstallModel, huggingFaceRepo]);

View File

@ -4,7 +4,7 @@ import { addToast } from 'features/system/store/systemSlice';
import { makeToast } from 'features/system/util/makeToast'; import { makeToast } from 'features/system/util/makeToast';
import { useCallback } from 'react'; import { useCallback } from 'react';
import { useTranslation } from 'react-i18next'; import { useTranslation } from 'react-i18next';
import { IoAdd } from 'react-icons/io5'; import { PiPlusBold } from 'react-icons/pi';
import { useInstallModelMutation } from 'services/api/endpoints/models'; import { useInstallModelMutation } from 'services/api/endpoints/models';
type Props = { type Props = {
@ -51,7 +51,7 @@ export const HuggingFaceResultItem = ({ result }: Props) => {
</Flex> </Flex>
<Box> <Box>
<Tooltip label={t('modelManager.quickAdd')}> <Tooltip label={t('modelManager.quickAdd')}>
<IconButton aria-label={t('modelManager.quickAdd')} icon={<IoAdd />} onClick={handleQuickAdd} /> <IconButton aria-label={t('modelManager.quickAdd')} icon={<PiPlusBold />} onClick={handleQuickAdd} />
</Tooltip> </Tooltip>
</Box> </Box>
</Flex> </Flex>

View File

@ -17,7 +17,9 @@ export const ScanModelsForm = () => {
const [_scanFolder, { isLoading, data }] = useLazyScanFolderQuery(); const [_scanFolder, { isLoading, data }] = useLazyScanFolderQuery();
const scanFolder = useCallback(async () => { const scanFolder = useCallback(async () => {
_scanFolder({ scan_path: scanPath }).catch((error) => { _scanFolder({ scan_path: scanPath })
.unwrap()
.catch((error) => {
if (error) { if (error) {
setErrorMessage(error.data.detail); setErrorMessage(error.data.detail);
} }

View File

@ -4,7 +4,7 @@ import { addToast } from 'features/system/store/systemSlice';
import { makeToast } from 'features/system/util/makeToast'; import { makeToast } from 'features/system/util/makeToast';
import { useCallback } from 'react'; import { useCallback } from 'react';
import { useTranslation } from 'react-i18next'; import { useTranslation } from 'react-i18next';
import { IoAdd } from 'react-icons/io5'; import { PiPlusBold } from 'react-icons/pi';
import type { ScanFolderResponse } from 'services/api/endpoints/models'; import type { ScanFolderResponse } from 'services/api/endpoints/models';
import { useInstallModelMutation } from 'services/api/endpoints/models'; import { useInstallModelMutation } from 'services/api/endpoints/models';
@ -55,7 +55,7 @@ export const ScanModelResultItem = ({ result }: Props) => {
<Badge>{t('common.installed')}</Badge> <Badge>{t('common.installed')}</Badge>
) : ( ) : (
<Tooltip label={t('modelManager.quickAdd')}> <Tooltip label={t('modelManager.quickAdd')}>
<IconButton aria-label={t('modelManager.quickAdd')} icon={<IoAdd />} onClick={handleQuickAdd} /> <IconButton aria-label={t('modelManager.quickAdd')} icon={<PiPlusBold />} onClick={handleQuickAdd} />
</Tooltip> </Tooltip>
)} )}
</Box> </Box>