From 223a95ef3d85e58c530f2a255d7993f026193bcc Mon Sep 17 00:00:00 2001 From: James Date: Wed, 4 Oct 2023 19:35:12 -0700 Subject: [PATCH] Adding downloading model table Signed-off-by: James --- .../DownloadingModelTable/index.tsx | 27 ++++++++ .../ExploreModelContainer/index.tsx | 65 +++++++------------ .../_components/ExploreModelItem/index.tsx | 21 +++--- .../_components/ExploreModelList/index.tsx | 24 +++++++ .../_components/ModelDownloadingRow/index.tsx | 37 +++++++++++ .../ModelDownloadingTable/index.tsx | 34 ++++++++++ web/app/_components/ModelTable/index.tsx | 2 +- .../_components/MyModelContainer/index.tsx | 2 + web/app/_hooks/useGetHuggingFaceModel.ts | 2 +- web/app/_utils/converter.ts | 5 ++ 10 files changed, 163 insertions(+), 56 deletions(-) create mode 100644 web/app/_components/DownloadingModelTable/index.tsx create mode 100644 web/app/_components/ExploreModelList/index.tsx create mode 100644 web/app/_components/ModelDownloadingRow/index.tsx create mode 100644 web/app/_components/ModelDownloadingTable/index.tsx diff --git a/web/app/_components/DownloadingModelTable/index.tsx b/web/app/_components/DownloadingModelTable/index.tsx new file mode 100644 index 000000000..5ca6872f3 --- /dev/null +++ b/web/app/_components/DownloadingModelTable/index.tsx @@ -0,0 +1,27 @@ +import React, { Fragment } from "react"; +import { modelDownloadStateAtom } from "@/_helpers/atoms/DownloadState.atom"; +import { useAtomValue } from "jotai"; +import ModelDownloadingTable from "../ModelDownloadingTable"; +import { DownloadState } from "@/_models/DownloadState"; + +const DownloadingModelTable: React.FC = () => { + const modelDownloadState = useAtomValue(modelDownloadStateAtom); + + const isAnyModelDownloading = Object.values(modelDownloadState).length > 0; + + if (!isAnyModelDownloading) return null; + + const downloadStates: DownloadState[] = []; + for (const [, value] of Object.entries(modelDownloadState)) { + downloadStates.push(value); + } + + return ( + +

Downloading Models

+ +
+ ); +}; + +export default DownloadingModelTable; diff --git a/web/app/_components/ExploreModelContainer/index.tsx b/web/app/_components/ExploreModelContainer/index.tsx index 88377cbf5..4c7ca636a 100644 --- a/web/app/_components/ExploreModelContainer/index.tsx +++ b/web/app/_components/ExploreModelContainer/index.tsx @@ -1,12 +1,8 @@ -import ExploreModelItem from "../ExploreModelItem"; import HeaderTitle from "../HeaderTitle"; import SearchBar, { SearchType } from "../SearchBar"; import SimpleCheckbox from "../SimpleCheckbox"; import SimpleTag, { TagType } from "../SimpleTag"; -import useGetHuggingFaceModel from "@/_hooks/useGetHuggingFaceModel"; -import { useAtomValue } from "jotai"; -import { modelSearchAtom } from "@/_helpers/JotaiWrapper"; -import { useEffect } from "react"; +import ExploreModelList from "../ExploreModelList"; const tags = [ "Roleplay", @@ -19,45 +15,32 @@ const tags = [ ]; const checkboxs = ["GGUF", "TensorRT", "Meow", "JigglyPuff"]; -const ExploreModelContainer: React.FC = () => { - const modelSearch = useAtomValue(modelSearchAtom); - const { modelList, getHuggingFaceModel } = useGetHuggingFaceModel(); - - useEffect(() => { - getHuggingFaceModel(modelSearch); - }, [modelSearch]); - - return ( -
- - -
-
-

Tags

- -
- {tags.map((item) => ( - - ))} -
-
-
- {checkboxs.map((item) => ( - - ))} -
-
-
- {modelList.map((item) => ( - +const ExploreModelContainer: React.FC = () => ( +
+ + +
+
+

Tags

+ +
+ {tags.map((item) => ( + ))}
+
+
+ {checkboxs.map((item) => ( + + ))} +
+
- ); -}; +
+); export default ExploreModelContainer; diff --git a/web/app/_components/ExploreModelItem/index.tsx b/web/app/_components/ExploreModelItem/index.tsx index 38fd6bd92..61ef68c47 100644 --- a/web/app/_components/ExploreModelItem/index.tsx +++ b/web/app/_components/ExploreModelItem/index.tsx @@ -2,12 +2,9 @@ import ExploreModelItemHeader from "../ExploreModelItemHeader"; import ModelVersionList from "../ModelVersionList"; -import { Fragment, useMemo, useState } from "react"; +import { Fragment, useState } from "react"; import SimpleTag, { TagType } from "../SimpleTag"; import { displayDate } from "@/_utils/datetime"; -import useDownloadModel from "@/_hooks/useDownloadModel"; -import { atom, useAtomValue } from "jotai"; -import { modelDownloadStateAtom } from "@/_helpers/atoms/DownloadState.atom"; import { Product } from "@/_models/Product"; type Props = { @@ -15,21 +12,14 @@ type Props = { }; const ExploreModelItem: React.FC = ({ model }) => { - const downloadAtom = useMemo( - () => atom((get) => get(modelDownloadStateAtom)[model.name ?? ""]), - [model.name ?? ""] - ); - const downloadState = useAtomValue(downloadAtom); - const { downloadModel } = useDownloadModel(); const [show, setShow] = useState(false); return ( -
+
@@ -88,7 +78,12 @@ const ExploreModelItem: React.FC = ({ model }) => {
{model.availableVersions.length > 0 && ( - {show && } + {show && ( + + )}