Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Implemented cancel download ❌ #9

Closed
wants to merge 2 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
"type": "module",
"scripts": {
"dev": "vite",
"build": "[ -f .env ] || cp env.sample .env && vite build && cp _headers dist/_headers",
"build": "vite build && cp _headers dist/_headers",
"preview": "vite preview",
"check": "svelte-check --tsconfig ./tsconfig.json",
"test": "vitest",
Expand Down
30 changes: 22 additions & 8 deletions src/lib/pickers/Model.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,8 @@
const DB_VERSION = 1;

const WHISPER_FILE_NAME = "whisper.bin";

let CANCEL_DOWNLOAD = false;

let MODEL_TITLE = "Download Model?";

Expand Down Expand Up @@ -216,6 +218,13 @@
let completed = false

while (!completed) {

if (CANCEL_DOWNLOAD){
downloadingmodel = false;
reader.cancel()
break
}

const { done, value } = await reader.read();

completed = done;
Expand All @@ -232,15 +241,20 @@
}
}

let position = 0;
let chunksAll = new Uint8Array(receivedLength);
if (!CANCEL_DOWNLOAD){
let position = 0;
let chunksAll = new Uint8Array(receivedLength);

for (var chunk of chunks) {
chunksAll.set(chunk, position);
position += chunk.length;
for (var chunk of chunks) {
chunksAll.set(chunk, position);
position += chunk.length;
}

LoadModelToDB(chunksAll);
}
else{
CANCEL_DOWNLOAD = false;
}

LoadModelToDB(chunksAll);

}).catch((err: Error) => {
console.error(err)
Expand Down Expand Up @@ -364,7 +378,7 @@
{/if}

{#if downloadingmodel}
<progress class="progress w-[60%]" value="{progressCur}" max="100"></progress><span>{progressCur}</span>
<progress class="progress w-[60%]" value="{progressCur}" max="100"></progress><span>{progressCur}%</span><button class="btn btn-square btn-sm btn-outline btn-error" on:click={()=>{CANCEL_DOWNLOAD=true}}>X</button>
{/if}

<dialog bind:this={popup} class="modal">
Expand Down
Loading