Update index.html
Browse files- index.html +18 -5
index.html
CHANGED
|
@@ -95,10 +95,13 @@
|
|
| 95 |
const CDN_PRIMARY = 'https://cdn.jsdelivr.net/npm/@huggingface/transformers@3.0.0';
|
| 96 |
const CDN_FALLBACK = 'https://cdn.jsdelivr.net/npm/@xenova/transformers@2.17.2';
|
| 97 |
|
|
|
|
|
|
|
|
|
|
| 98 |
// Smallest first: q4 → q4f16 → int8 → fp16
|
| 99 |
const options = {
|
| 100 |
-
device
|
| 101 |
-
dtype: 'q4',
|
| 102 |
progress_callback: setProgress,
|
| 103 |
};
|
| 104 |
|
|
@@ -182,9 +185,13 @@ def f(nums):
|
|
| 182 |
let pipe=null, cancelled=false, abortGen=null;
|
| 183 |
|
| 184 |
// ================= Utils =================
|
| 185 |
-
function log(...a){
|
|
|
|
| 186 |
logDiv.textContent += s + '
|
| 187 |
-
';
|
|
|
|
|
|
|
|
|
|
| 188 |
function chip(kind,text){ statusChip.className='chip '+(kind||''); statusChip.textContent=text; statusChip.style.display='inline-flex'; }
|
| 189 |
function clearChip(){ statusChip.style.display='none'; }
|
| 190 |
function setProgress(evt){ if(evt?.status==='progress'){ const pct=Math.round(Math.max(0,Math.min(100,evt.progress||0))); pbar.value=pct; plabel.textContent=`${pct}% ${evt?.name||evt?.file||''}`.trim(); } else if(evt?.status){ log(`status: ${evt.status} ${evt?.name||evt?.file||''}`); } }
|
|
@@ -199,7 +206,7 @@ def f(nums):
|
|
| 199 |
|
| 200 |
function renderExamples(){
|
| 201 |
exWrap.innerHTML='';
|
| 202 |
-
EXAMPLES.forEach((ex
|
| 203 |
const b=document.createElement('button');
|
| 204 |
b.textContent=ex.title; b.className='ghost';
|
| 205 |
b.addEventListener('click',()=>{
|
|
@@ -229,6 +236,12 @@ def f(nums):
|
|
| 229 |
cancelBtn.style.display='inline-block';
|
| 230 |
loading.style.display='block'; pbar.value=0; plabel.textContent='0%';
|
| 231 |
const { pipeline } = await importTransformers();
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 232 |
log('Transformers.js loaded. Creating text-generation pipeline…');
|
| 233 |
pipe = await pipeline('text-generation', MODEL_ID, options);
|
| 234 |
if(cancelled) log('Note: cancel only resets UI and cannot interrupt underlying downloads.');
|
|
|
|
| 95 |
const CDN_PRIMARY = 'https://cdn.jsdelivr.net/npm/@huggingface/transformers@3.0.0';
|
| 96 |
const CDN_FALLBACK = 'https://cdn.jsdelivr.net/npm/@xenova/transformers@2.17.2';
|
| 97 |
|
| 98 |
+
// Prefer WebGPU; gracefully fall back if unavailable
|
| 99 |
+
const device = ('gpu' in navigator) ? 'webgpu' : 'auto';
|
| 100 |
+
|
| 101 |
// Smallest first: q4 → q4f16 → int8 → fp16
|
| 102 |
const options = {
|
| 103 |
+
device, // prefer WebGPU; fallback to auto if not available
|
| 104 |
+
dtype: 'q4', // smallest ONNX weights (model_q4.onnx + .onnx_data)
|
| 105 |
progress_callback: setProgress,
|
| 106 |
};
|
| 107 |
|
|
|
|
| 185 |
let pipe=null, cancelled=false, abortGen=null;
|
| 186 |
|
| 187 |
// ================= Utils =================
|
| 188 |
+
function log(...a){
|
| 189 |
+
const s=a.map(x=>typeof x==='string'?x:JSON.stringify(x)).join(' ');
|
| 190 |
logDiv.textContent += s + '
|
| 191 |
+
';
|
| 192 |
+
logDiv.scrollTop=logDiv.scrollHeight;
|
| 193 |
+
console.log('[LOG]',...a);
|
| 194 |
+
}
|
| 195 |
function chip(kind,text){ statusChip.className='chip '+(kind||''); statusChip.textContent=text; statusChip.style.display='inline-flex'; }
|
| 196 |
function clearChip(){ statusChip.style.display='none'; }
|
| 197 |
function setProgress(evt){ if(evt?.status==='progress'){ const pct=Math.round(Math.max(0,Math.min(100,evt.progress||0))); pbar.value=pct; plabel.textContent=`${pct}% ${evt?.name||evt?.file||''}`.trim(); } else if(evt?.status){ log(`status: ${evt.status} ${evt?.name||evt?.file||''}`); } }
|
|
|
|
| 206 |
|
| 207 |
function renderExamples(){
|
| 208 |
exWrap.innerHTML='';
|
| 209 |
+
EXAMPLES.forEach((ex)=>{
|
| 210 |
const b=document.createElement('button');
|
| 211 |
b.textContent=ex.title; b.className='ghost';
|
| 212 |
b.addEventListener('click',()=>{
|
|
|
|
| 236 |
cancelBtn.style.display='inline-block';
|
| 237 |
loading.style.display='block'; pbar.value=0; plabel.textContent='0%';
|
| 238 |
const { pipeline } = await importTransformers();
|
| 239 |
+
if (device !== 'webgpu') {
|
| 240 |
+
log('WebGPU not detected; falling back to device=auto (WASM/CPU).');
|
| 241 |
+
chip('warn','WebGPU not detected — using auto');
|
| 242 |
+
} else {
|
| 243 |
+
log('WebGPU detected.');
|
| 244 |
+
}
|
| 245 |
log('Transformers.js loaded. Creating text-generation pipeline…');
|
| 246 |
pipe = await pipeline('text-generation', MODEL_ID, options);
|
| 247 |
if(cancelled) log('Note: cancel only resets UI and cannot interrupt underlying downloads.');
|