PeterPinetree commited on
Commit
7efba2a
·
verified ·
1 Parent(s): 215407a

Update index.html

Browse files
Files changed (1) hide show
  1. index.html +20 -5
index.html CHANGED
@@ -35,14 +35,30 @@
35
  .help { border-bottom:1px dotted #9ab0d0; cursor:help; }
36
  </style>
37
 
38
- <!-- Transformers.js (browser build) -->
39
  <script type="module">
40
- import { env, AutoTokenizer, AutoModelForCausalLM }
41
- from "./assets/vendor/transformers-browser.js";
42
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
43
  window.HF = { env, AutoTokenizer, AutoModelForCausalLM };
 
 
44
  env.localModelPath = null;
45
- env.allowRemoteModels = false; // you flip this in the model <select> handler for distilgpt2
46
  env.useBrowserCache = true;
47
  env.backends.onnx.wasm.wasmPaths =
48
  "https://cdn.jsdelivr.net/npm/onnxruntime-web@1.17.1/dist/";
@@ -464,7 +480,6 @@
464
  predict();
465
  });
466
 
467
-
468
  /* ---------- Boot ---------- */
469
  (async function init(){
470
  await loadModel(modelSel.value); // default: qwen (local)
 
35
  .help { border-bottom:1px dotted #9ab0d0; cursor:help; }
36
  </style>
37
 
38
+ <!-- Transformers.js (browser build, MIME-safe loader) -->
39
  <script type="module">
40
+ // Use the exact vendored file you have:
41
+ const VENDORED_PATH = "./assets/vendor/transformers-3.0.0.js";
42
 
43
+ async function importVendoredModule(path) {
44
+ const res = await fetch(path);
45
+ if (!res.ok) throw new Error(`Failed to fetch ${path}: ${res.status}`);
46
+ const code = await res.text();
47
+ const blob = new Blob([code], { type: "text/javascript" });
48
+ const url = URL.createObjectURL(blob);
49
+ try {
50
+ return await import(url);
51
+ } finally {
52
+ URL.revokeObjectURL(url);
53
+ }
54
+ }
55
+
56
+ const { env, AutoTokenizer, AutoModelForCausalLM } = await importVendoredModule(VENDORED_PATH);
57
  window.HF = { env, AutoTokenizer, AutoModelForCausalLM };
58
+
59
+ // Runtime settings
60
  env.localModelPath = null;
61
+ env.allowRemoteModels = false; // you toggle this in the <select> handler for distilgpt2
62
  env.useBrowserCache = true;
63
  env.backends.onnx.wasm.wasmPaths =
64
  "https://cdn.jsdelivr.net/npm/onnxruntime-web@1.17.1/dist/";
 
480
  predict();
481
  });
482
 
 
483
  /* ---------- Boot ---------- */
484
  (async function init(){
485
  await loadModel(modelSel.value); // default: qwen (local)