Skip to content

Commit

Permalink
Fix #36 Display an error when no models are found
Browse files Browse the repository at this point in the history
  • Loading branch information
philipws committed Jun 18, 2024
1 parent c67fb18 commit 8949498
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 6 deletions.
14 changes: 9 additions & 5 deletions website/src/page/readable/hooks/useReadableModels.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -83,25 +83,29 @@ export const UseReadableModels = () => {
});
const allModels = result.data.readableListModels.items;
const textModels = allModels.filter(
(model) => model.type === ItemValues.TEXT
(model) => model.type === ItemValues.TEXT
);
const imageModels = allModels.filter(
(model) => model.type === ItemValues.IMAGE
);

setModelDataOfType(textModels, ItemValues.TEXT);
if (textModels.length === 0 && imageModels.length === 0) {
throw new Error("No models found. Please make sure models are configured correctly. See https://aws-samples.github.io/document-translation/docs/readable/post-install/models/ for details.");
}

setModelDataOfType(textModels, ItemValues.TEXT);
setModelDataOfType(imageModels, ItemValues.IMAGE);

setLoading(false);
} catch (error) {
console.log("Error fetching models:", error);
setError(error);
setLoading(false);
setError(error.message);
setLoading(false);
}
};

fetchModels();
}, []);

return { modelState, modelDefault, loading, error };
return { modelState, modelDefault, loading, error };
};
10 changes: 9 additions & 1 deletion website/src/page/readable/view.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -48,11 +48,19 @@ export default function ReadableNew() {
const [imageState, setImageState] = useState({});
const [itemViewState, setItemViewState] = useState({});

const { modelState, modelDefault } = UseReadableModels();
const { modelState, modelDefault, loading, error } = UseReadableModels();
const LoadingStatus = [ItemStatus.GENERATE, ItemStatus.PROCESSING];

UseReadableSubscription(setMetadataState, setTextState, setImageState);

if (error) {
return (
<div className="alert alert-danger" role="alert">
{error} <a href="https://aws-samples.github.io/document-translation/docs/readable/post-install/models/" target="_blank" rel="noopener noreferrer">Learn more</a>
</div>
);
}

async function createNewTextItem(order) {
const authSession = await fetchAuthSession();
try {
Expand Down

0 comments on commit 8949498

Please sign in to comment.