av commited on
Commit
ed5b990
·
1 Parent(s): 1df5310

add download progress for HRM-Text and fix error handling

Browse files

- Stream HRM ONNX download with progress percentage and MB count
- Hide loading overlay on error instead of leaving it stuck
- Reset activeModel on error so retry works

Files changed (1) hide show
  1. index.html +28 -2
index.html CHANGED
@@ -474,8 +474,32 @@
474
  showLoading('HRM-Text', '~94 MB ONNX (one-time download)');
475
  try {
476
  loadingText.textContent = 'Downloading HRM-Text...';
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
477
  const ortLib = await getOrt();
478
- hrmSession = await ortLib.InferenceSession.create(HRM_ONNX_URL, {
479
  executionProviders: ['wasm'],
480
  });
481
  } catch (err) {
@@ -564,7 +588,9 @@
564
  hideLoading();
565
  analyzeBtn.disabled = false;
566
  } catch (err) {
567
- updateBadge('Error');
 
 
568
  }
569
 
570
  isLoading = false;
 
474
  showLoading('HRM-Text', '~94 MB ONNX (one-time download)');
475
  try {
476
  loadingText.textContent = 'Downloading HRM-Text...';
477
+ const response = await fetch(HRM_ONNX_URL);
478
+ if (!response.ok) throw new Error(`HTTP ${response.status}`);
479
+ const total = parseInt(response.headers.get('content-length') || '0', 10);
480
+ const reader = response.body.getReader();
481
+ const chunks = [];
482
+ let loaded = 0;
483
+ while (true) {
484
+ const { done, value } = await reader.read();
485
+ if (done) break;
486
+ chunks.push(value);
487
+ loaded += value.length;
488
+ if (total > 0) {
489
+ const pct = Math.round((loaded / total) * 100);
490
+ const mb = (loaded / 1048576).toFixed(1);
491
+ loadingText.textContent = `Downloading HRM-Text... ${pct}% (${mb} MB)`;
492
+ }
493
+ }
494
+ const buffer = new Uint8Array(loaded);
495
+ let offset = 0;
496
+ for (const chunk of chunks) {
497
+ buffer.set(chunk, offset);
498
+ offset += chunk.length;
499
+ }
500
+ loadingText.textContent = 'Initializing HRM-Text...';
501
  const ortLib = await getOrt();
502
+ hrmSession = await ortLib.InferenceSession.create(buffer.buffer, {
503
  executionProviders: ['wasm'],
504
  });
505
  } catch (err) {
 
588
  hideLoading();
589
  analyzeBtn.disabled = false;
590
  } catch (err) {
591
+ updateBadge('Error — click model to retry');
592
+ hideLoading();
593
+ activeModel = null;
594
  }
595
 
596
  isLoading = false;