From eb905d22e71109c65bb392efd0fa0eb1c8fcfee9 Mon Sep 17 00:00:00 2001 From: Tony Salomone <dadmobile@gmail.com> Date: Fri, 17 Jan 2025 09:38:59 -0500 Subject: [PATCH] Import Bar and ModelStore share download status so UIs are in sync --- .../components/ModelZoo/ImportModelsBar.tsx | 17 ++++++++++------- src/renderer/components/ModelZoo/ModelStore.tsx | 7 +++++-- 2 files changed, 15 insertions(+), 9 deletions(-) diff --git a/src/renderer/components/ModelZoo/ImportModelsBar.tsx b/src/renderer/components/ModelZoo/ImportModelsBar.tsx index 816de4c0..2f83ce28 100644 --- a/src/renderer/components/ModelZoo/ImportModelsBar.tsx +++ b/src/renderer/components/ModelZoo/ImportModelsBar.tsx @@ -13,8 +13,10 @@ import { PlusIcon } from 'lucide-react'; import * as chatAPI from '../../lib/transformerlab-api-sdk'; import ImportModelsModal from './ImportModelsModal'; -export default function ImportModelsBar({}) { - const [downloadingModel, setDownloadingModel] = useState(null); +// Needs to share currentlyDownloading with ModelsStore +// If you start a download on one it should stop you from starting on the other +// Also this is how the import bar tells teh model store to show a download progress bar +export default function ImportModelsBar({ currentlyDownloading, setCurrentlyDownloading }) { const [importModelsModalOpen, setImportModelsModalOpen] = useState(false); return ( @@ -56,7 +58,7 @@ export default function ImportModelsBar({}) { // only download if valid model is entered if (model) { // this triggers UI changes while download is in progress - setDownloadingModel(model); + setCurrentlyDownloading(model); // Try downloading the model const response = await chatAPI.downloadModelFromHuggingFace(model); @@ -65,17 +67,18 @@ export default function ImportModelsBar({}) { } // download complete - setDownloadingModel(null); + setCurrentlyDownloading(null); + //modelGalleryMutate(); } }} startDecorator={ - downloadingModel ? ( + currentlyDownloading ? ( <CircularProgress size="sm" thickness={2} /> ) : ( "" )} > - {downloadingModel ? ( + {currentlyDownloading ? ( "Downloading" ) : ( "Download 🤗 Model" @@ -83,7 +86,7 @@ export default function ImportModelsBar({}) { </Button> } sx={{ width: '500px' }} - disabled={downloadingModel} + disabled={currentlyDownloading} /> </FormControl> <Button diff --git a/src/renderer/components/ModelZoo/ModelStore.tsx b/src/renderer/components/ModelZoo/ModelStore.tsx index 5f517b43..f15234cb 100644 --- a/src/renderer/components/ModelZoo/ModelStore.tsx +++ b/src/renderer/components/ModelZoo/ModelStore.tsx @@ -117,7 +117,7 @@ export default function ModelStore() { } = useSWR(chatAPI.Endpoints.Models.Gallery(), fetcher); const { data: modelDownloadProgress } = useSWR( - currentlyDownloading && jobId != '-1' + currentlyDownloading && jobId && jobId != '-1' ? chatAPI.Endpoints.Jobs.Get(jobId) : null, fetcher, @@ -605,7 +605,10 @@ export default function ModelStore() { </tbody> </Table> </Sheet> - <ImportModelsBar /> + <ImportModelsBar + currentlyDownloading={currentlyDownloading} + setCurrentlyDownloading={setCurrentlyDownloading} + /> </Sheet> ); } -- GitLab