Skip to content
Snippets Groups Projects
Commit 409d57c8 authored by Tony Salomone's avatar Tony Salomone
Browse files

Update ImportModelBar to use a jobID so its downloads get a progress bar

parent 268c7528
No related branches found
No related tags found
No related merge requests found
...@@ -13,10 +13,10 @@ import { PlusIcon } from 'lucide-react'; ...@@ -13,10 +13,10 @@ import { PlusIcon } from 'lucide-react';
import * as chatAPI from '../../lib/transformerlab-api-sdk'; import * as chatAPI from '../../lib/transformerlab-api-sdk';
import ImportModelsModal from './ImportModelsModal'; import ImportModelsModal from './ImportModelsModal';
// Needs to share currentlyDownloading with ModelsStore // Needs to share jobId with ModelsStore
// If you start a download on one it should stop you from starting on the other // 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 // Also this is how the import bar tells teh model store to show a download progress bar
export default function ImportModelsBar({ currentlyDownloading, setCurrentlyDownloading }) { export default function ImportModelsBar({ jobId, setJobId }) {
const [importModelsModalOpen, setImportModelsModalOpen] = useState(false); const [importModelsModalOpen, setImportModelsModalOpen] = useState(false);
return ( return (
...@@ -57,28 +57,42 @@ export default function ImportModelsBar({ currentlyDownloading, setCurrentlyDown ...@@ -57,28 +57,42 @@ export default function ImportModelsBar({ currentlyDownloading, setCurrentlyDown
// only download if valid model is entered // only download if valid model is entered
if (model) { if (model) {
// this triggers UI changes while download is in progress setJobId(-1);
setCurrentlyDownloading(model); try {
const jobResponse = await fetch(
chatAPI.Endpoints.Jobs.Create()
);
const newJobId = await jobResponse.json();
setJobId(newJobId);
// Try downloading the model // Try downloading the model
const response = await chatAPI.downloadModelFromHuggingFace(model); const response = await chatAPI.downloadModelFromHuggingFace(
if (response?.status == 'error') { model,
alert('Download failed!\n' + response.message); newJobId
} );
console.log(response);
if (response?.status == 'error') {
alert('Download failed!\n' + response.message);
}
// download complete
setJobId(null);
// download complete } catch (e) {
setCurrentlyDownloading(null); setJobId(null);
//modelGalleryMutate(); console.log(e);
return alert('Failed to download');
}
} }
}} }}
startDecorator={ startDecorator={
currentlyDownloading ? ( jobId ? (
<CircularProgress size="sm" thickness={2} /> <CircularProgress size="sm" thickness={2} />
) : ( ) : (
"" ""
)} )}
> >
{currentlyDownloading ? ( {jobId ? (
"Downloading" "Downloading"
) : ( ) : (
"Download 🤗 Model" "Download 🤗 Model"
...@@ -86,7 +100,7 @@ export default function ImportModelsBar({ currentlyDownloading, setCurrentlyDown ...@@ -86,7 +100,7 @@ export default function ImportModelsBar({ currentlyDownloading, setCurrentlyDown
</Button> </Button>
} }
sx={{ width: '500px' }} sx={{ width: '500px' }}
disabled={currentlyDownloading} disabled={jobId != null}
/> />
</FormControl> </FormControl>
<Button <Button
......
...@@ -117,7 +117,7 @@ export default function ModelStore() { ...@@ -117,7 +117,7 @@ export default function ModelStore() {
} = useSWR(chatAPI.Endpoints.Models.Gallery(), fetcher); } = useSWR(chatAPI.Endpoints.Models.Gallery(), fetcher);
const { data: modelDownloadProgress } = useSWR( const { data: modelDownloadProgress } = useSWR(
currentlyDownloading && jobId && jobId != '-1' jobId && jobId != '-1'
? chatAPI.Endpoints.Jobs.Get(jobId) ? chatAPI.Endpoints.Jobs.Get(jobId)
: null, : null,
fetcher, fetcher,
...@@ -606,8 +606,8 @@ export default function ModelStore() { ...@@ -606,8 +606,8 @@ export default function ModelStore() {
</Table> </Table>
</Sheet> </Sheet>
<ImportModelsBar <ImportModelsBar
currentlyDownloading={currentlyDownloading} jobId={jobId}
setCurrentlyDownloading={setCurrentlyDownloading} setJobId={setJobId}
/> />
</Sheet> </Sheet>
); );
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment