Update index.html
Browse files- index.html +18 -5
index.html
CHANGED
|
@@ -42,14 +42,27 @@
|
|
| 42 |
const hasWebGPU = 'gpu' in navigator;
|
| 43 |
let device = hasWebGPU ? 'webgpu' : 'wasm';
|
| 44 |
backendEl.textContent = device.toUpperCase();
|
| 45 |
-
envEl.textContent = hasWebGPU ? '✅ WebGPU detected (will fallback if slow)…'
|
| 46 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 47 |
|
| 48 |
// Load Transformers.js v3
|
| 49 |
const { pipeline } = await import('https://cdn.jsdelivr.net/npm/@huggingface/transformers@3');
|
| 50 |
|
| 51 |
// Watchdog: if WebGPU load takes too long, retry on WASM
|
| 52 |
-
const LOAD_TIMEOUT_MS = 30000;
|
| 53 |
let captioner;
|
| 54 |
|
| 55 |
async function buildPipeline(targetDevice) {
|
|
@@ -90,7 +103,7 @@
|
|
| 90 |
imgEl.src = imgURL;
|
| 91 |
});
|
| 92 |
|
| 93 |
-
// Run captioning
|
| 94 |
runBtn.addEventListener('click', async () => {
|
| 95 |
if (!captioner) return;
|
| 96 |
if (!imgURL) { logEl.textContent = 'Pick an image first.'; return; }
|
|
@@ -101,7 +114,7 @@
|
|
| 101 |
num_beams: 5,
|
| 102 |
do_sample: false,
|
| 103 |
no_repeat_ngram_size: 3
|
| 104 |
-
});
|
| 105 |
logEl.textContent = out[0].generated_text;
|
| 106 |
} catch (e) {
|
| 107 |
logEl.textContent = 'Inference error: ' + e;
|
|
|
|
| 42 |
const hasWebGPU = 'gpu' in navigator;
|
| 43 |
let device = hasWebGPU ? 'webgpu' : 'wasm';
|
| 44 |
backendEl.textContent = device.toUpperCase();
|
| 45 |
+
envEl.textContent = hasWebGPU ? '✅ WebGPU detected (will fallback if slow)…' : '⚠️ Using WASM (CPU).';
|
| 46 |
+
|
| 47 |
+
// ---------- SINGLE FIX: force ?download=1 on HF "resolve" URLs ----------
|
| 48 |
+
const _fetch = window.fetch.bind(window);
|
| 49 |
+
window.fetch = (url, opts) => {
|
| 50 |
+
try {
|
| 51 |
+
const u = new URL(url);
|
| 52 |
+
if (u.hostname === 'huggingface.co' && u.pathname.includes('/resolve/')) {
|
| 53 |
+
if (!u.searchParams.has('download')) u.searchParams.set('download', '1');
|
| 54 |
+
url = u.toString();
|
| 55 |
+
}
|
| 56 |
+
} catch {}
|
| 57 |
+
return _fetch(url, opts);
|
| 58 |
+
};
|
| 59 |
+
// -----------------------------------------------------------------------
|
| 60 |
|
| 61 |
// Load Transformers.js v3
|
| 62 |
const { pipeline } = await import('https://cdn.jsdelivr.net/npm/@huggingface/transformers@3');
|
| 63 |
|
| 64 |
// Watchdog: if WebGPU load takes too long, retry on WASM
|
| 65 |
+
const LOAD_TIMEOUT_MS = 30000;
|
| 66 |
let captioner;
|
| 67 |
|
| 68 |
async function buildPipeline(targetDevice) {
|
|
|
|
| 103 |
imgEl.src = imgURL;
|
| 104 |
});
|
| 105 |
|
| 106 |
+
// Run captioning (beam search for better quality)
|
| 107 |
runBtn.addEventListener('click', async () => {
|
| 108 |
if (!captioner) return;
|
| 109 |
if (!imgURL) { logEl.textContent = 'Pick an image first.'; return; }
|
|
|
|
| 114 |
num_beams: 5,
|
| 115 |
do_sample: false,
|
| 116 |
no_repeat_ngram_size: 3
|
| 117 |
+
});
|
| 118 |
logEl.textContent = out[0].generated_text;
|
| 119 |
} catch (e) {
|
| 120 |
logEl.textContent = 'Inference error: ' + e;
|