Spaces:
Runtime error
Runtime error
Update index.html
Browse files- index.html +32 -16
index.html
CHANGED
|
@@ -318,26 +318,42 @@
|
|
| 318 |
});
|
| 319 |
return;
|
| 320 |
}
|
|
|
|
|
|
|
|
|
|
| 321 |
|
| 322 |
-
|
| 323 |
-
|
| 324 |
-
|
| 325 |
-
|
| 326 |
-
|
| 327 |
-
|
| 328 |
-
|
| 329 |
|
| 330 |
-
|
| 331 |
-
|
| 332 |
-
|
| 333 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 334 |
|
| 335 |
-
|
| 336 |
-
files,
|
| 337 |
-
local_files_only: true,
|
| 338 |
-
progress_callback: onProgress,
|
| 339 |
-
});
|
| 340 |
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 341 |
|
| 342 |
// Core model state (module scope)
|
| 343 |
let tokenizer = null, model = null;
|
|
|
|
| 318 |
});
|
| 319 |
return;
|
| 320 |
}
|
| 321 |
+
// ---- fallback: legacy BPE (vocab.json + merges.txt) ----
|
| 322 |
+
const vocabURL = new URL("vocab.json", base).href;
|
| 323 |
+
const mergesURL = new URL("merges.txt", base).href;
|
| 324 |
|
| 325 |
+
// Load raw file contents
|
| 326 |
+
const [vocabText, mergesText, cfgMaybe] = await Promise.all([
|
| 327 |
+
fetch(vocabURL).then(r => { if (!r.ok) throw new Error("missing vocab.json"); return r.text(); }),
|
| 328 |
+
fetch(mergesURL).then(r => { if (!r.ok) throw new Error("missing merges.txt"); return r.text(); }),
|
| 329 |
+
// tokenizer_config.json is optional; we'll sanitize it if present
|
| 330 |
+
fetch(new URL("tokenizer_config.json", base).href).then(r => r.ok ? r.json() : null),
|
| 331 |
+
]);
|
| 332 |
|
| 333 |
+
const files = new Map();
|
| 334 |
+
|
| 335 |
+
// IMPORTANT: pass merges as the **raw text string**
|
| 336 |
+
files.set("vocab.json", new Blob([vocabText], { type: "application/json" }));
|
| 337 |
+
files.set("merges.txt", new Blob([mergesText], { type: "text/plain" }));
|
| 338 |
+
|
| 339 |
+
// If you include tokenizer_config.json, strip fields that can confuse the BPE loader
|
| 340 |
+
if (cfgMaybe) {
|
| 341 |
+
const cfg = { ...cfgMaybe };
|
| 342 |
+
// These sometimes show up as arrays/objects; the BPE loader expects to read merges.txt itself.
|
| 343 |
+
if (Array.isArray(cfg.merges)) delete cfg.merges;
|
| 344 |
+
if (typeof cfg.merges === "object") delete cfg.merges;
|
| 345 |
+
// (Optional) also remove tokenizer_file pointers which can trigger alternate code paths
|
| 346 |
+
if (cfg.tokenizer_file) delete cfg.tokenizer_file;
|
| 347 |
|
| 348 |
+
files.set("tokenizer_config.json", new Blob([JSON.stringify(cfg)], { type: "application/json" }));
|
|
|
|
|
|
|
|
|
|
|
|
|
| 349 |
}
|
| 350 |
+
|
| 351 |
+
// Now build the tokenizer strictly from local files
|
| 352 |
+
tokenizer = await AutoTokenizer.from_pretrained("", {
|
| 353 |
+
files,
|
| 354 |
+
local_files_only: true,
|
| 355 |
+
progress_callback: onProgress,
|
| 356 |
+
});
|
| 357 |
|
| 358 |
// Core model state (module scope)
|
| 359 |
let tokenizer = null, model = null;
|