Javedalam commited on
Commit
94560fa
Β·
verified Β·
1 Parent(s): bb12dec

Update index.html

Browse files
Files changed (1) hide show
  1. index.html +8 -14
index.html CHANGED
@@ -59,11 +59,8 @@
59
  Tip: first load downloads the model; later loads are much faster thanks to browser cache.
60
  </div>
61
 
62
- <!-- Load UMD bundle (no ESM/dynamic import).
63
- If jsDelivr is blocked, try unpkg:
64
- https://unpkg.com/@xenova/transformers@3.0.0/dist/transformers.min.js
65
- -->
66
- <script src="https://cdn.jsdelivr.net/npm/@xenova/transformers@3.0.0/dist/transformers.min.js"></script>
67
 
68
  <script>
69
  // Grab DOM elements
@@ -76,15 +73,15 @@
76
  const bar = document.getElementById("loadProgress");
77
  const txt = document.getElementById("progressText");
78
 
79
- // Show UI immediately
80
  btn.disabled = false;
81
  btn.value = "Translate";
82
 
83
- // Transformers.js UMD exposes window.transformers
84
  const tf = window.transformers;
85
  if (!tf) {
86
  document.body.insertAdjacentHTML('beforeend',
87
- '<p style="color:#b00">Failed to load Transformers.js. Check CDN/network.</p>');
88
  }
89
 
90
  let translator = null;
@@ -113,22 +110,19 @@
113
  const { pipeline, env } = tf;
114
  env.useBrowserCache = true;
115
  env.allowLocalModels = false;
116
- // WASM fallback uses threads; harmless if WebGPU available
117
  env.backends.onnx.wasm.numThreads = Math.max(4, Math.min(8, navigator.hardwareConcurrency || 4));
118
 
119
  translator = await pipeline("translation", "Xenova/nllb-200-distilled-600M", {
120
  device: (navigator.gpu ? "webgpu" : "wasm"),
121
  progress_callback: progressCallback
122
- // If you hit issues with quant hints, you can add:
123
- // dtype: { encoder_model: "q8", decoder_model_merged: "q8" },
124
  });
125
 
126
- txt.textContent = "Model ready βœ”";
127
  bar.max = 1; bar.value = 1;
128
  return translator;
129
  } catch (e) {
130
  console.error(e);
131
- txt.textContent = "Error loading model β€” see console.";
132
  throw e;
133
  }
134
  }
@@ -143,7 +137,7 @@
143
  const res = await t(text, { src_lang: srcEl.value, tgt_lang: tgtEl.value, max_length: 128 });
144
  out.value = res?.[0]?.translation_text || "(no output)";
145
  } catch (e) {
146
- out.value = "Translation failed. See console for details.";
147
  } finally {
148
  btn.disabled = false; btn.value = prev;
149
  }
 
59
  Tip: first load downloads the model; later loads are much faster thanks to browser cache.
60
  </div>
61
 
62
+ <!-- Use unpkg CDN (jsDelivr failed in your Space) -->
63
+ <script src="https://unpkg.com/@xenova/transformers@3.0.0/dist/transformers.min.js"></script>
 
 
 
64
 
65
  <script>
66
  // Grab DOM elements
 
73
  const bar = document.getElementById("loadProgress");
74
  const txt = document.getElementById("progressText");
75
 
76
+ // Enable button right away
77
  btn.disabled = false;
78
  btn.value = "Translate";
79
 
80
+ // Transformers.js UMD bundle
81
  const tf = window.transformers;
82
  if (!tf) {
83
  document.body.insertAdjacentHTML('beforeend',
84
+ '<p style="color:#b00">❌ Failed to load Transformers.js. Check CDN/network.</p>');
85
  }
86
 
87
  let translator = null;
 
110
  const { pipeline, env } = tf;
111
  env.useBrowserCache = true;
112
  env.allowLocalModels = false;
 
113
  env.backends.onnx.wasm.numThreads = Math.max(4, Math.min(8, navigator.hardwareConcurrency || 4));
114
 
115
  translator = await pipeline("translation", "Xenova/nllb-200-distilled-600M", {
116
  device: (navigator.gpu ? "webgpu" : "wasm"),
117
  progress_callback: progressCallback
 
 
118
  });
119
 
120
+ txt.textContent = "βœ… Model ready";
121
  bar.max = 1; bar.value = 1;
122
  return translator;
123
  } catch (e) {
124
  console.error(e);
125
+ txt.textContent = "❌ Error loading model β€” see console.";
126
  throw e;
127
  }
128
  }
 
137
  const res = await t(text, { src_lang: srcEl.value, tgt_lang: tgtEl.value, max_length: 128 });
138
  out.value = res?.[0]?.translation_text || "(no output)";
139
  } catch (e) {
140
+ out.value = "❌ Translation failed. See console.";
141
  } finally {
142
  btn.disabled = false; btn.value = prev;
143
  }