VickyRDP commited on
Commit
4e9fd49
·
verified ·
1 Parent(s): 92cdbd8

Use current Transformers.js 3.x for fp16 KV cache

Browse files
Files changed (1) hide show
  1. index.html +437 -211
index.html CHANGED
@@ -1,212 +1,438 @@
1
- <!DOCTYPE html>
2
- <html lang="en">
3
- <head>
4
- <meta charset="UTF-8">
5
- <meta name="viewport" content="width=device-width, initial-scale=1.0">
6
- <title>GPU Mart Assistant — voice + text AI for RDP GPU Mart</title>
7
- <meta name="description" content="Ask anything about RDP GPU Mart (rdp.in/gpu-mart) — India's datacenter-grade GPU marketplace. A small fine-tuned model, running right in your browser, with voice and text.">
8
- <style>
9
- :root { --red:#d82228; --bg:#e8e8e8; --ink:#1a1a1a; --card:#ffffff; }
10
- * { box-sizing:border-box; margin:0; padding:0; }
11
- body { font-family:'Segoe UI',system-ui,-apple-system,sans-serif; background:var(--bg); color:var(--ink);
12
- display:flex; flex-direction:column; align-items:center; min-height:100vh; }
13
- header { width:100%; background:#fff; border-bottom:3px solid var(--red); padding:14px 20px; text-align:center; }
14
- header h1 { font-size:1.25rem; } header h1 span { color:var(--red); }
15
- header p { font-size:.85rem; color:#555; margin-top:2px; }
16
- #status { width:min(760px,94vw); margin:10px auto 0; font-size:.85rem; color:#444; background:#fff;
17
- border-radius:10px; padding:8px 14px; border-left:4px solid var(--red); }
18
- #bar { height:6px; background:#eee; border-radius:3px; margin-top:6px; overflow:hidden; display:none; }
19
- #bar > div { height:100%; width:0%; background:var(--red); transition:width .3s; }
20
- #chat { width:min(760px,94vw); flex:1; margin:12px auto; background:var(--card); border-radius:14px;
21
- padding:16px; overflow-y:auto; min-height:340px; max-height:56vh; box-shadow:0 1px 4px rgba(0,0,0,.08); }
22
- .msg { margin:8px 0; padding:10px 14px; border-radius:12px; max-width:85%; line-height:1.45; font-size:.95rem;
23
- white-space:pre-wrap; word-wrap:break-word; }
24
- .user { background:var(--red); color:#fff; margin-left:auto; }
25
- .bot { background:#f2f2f2; }
26
- #controls { width:min(760px,94vw); margin:0 auto 8px; display:flex; gap:8px; }
27
- #box { flex:1; padding:12px 14px; border:1px solid #ccc; border-radius:10px; font-size:1rem; outline:none; }
28
- #box:focus { border-color:var(--red); }
29
- button { border:none; border-radius:10px; padding:12px 18px; font-size:1rem; cursor:pointer; }
30
- #send { background:var(--red); color:#fff; }
31
- #mic { background:#fff; color:var(--red); border:2px solid var(--red); }
32
- #mic.listening { background:var(--red); color:#fff; animation:pulse 1.2s infinite; }
33
- @keyframes pulse { 50% { opacity:.6; } }
34
- #opts { width:min(760px,94vw); margin:0 auto 10px; display:flex; align-items:center; gap:14px; font-size:.85rem; color:#444; flex-wrap:wrap; }
35
- .chip { background:#fff; border:1px solid #ddd; border-radius:16px; padding:5px 12px; cursor:pointer; font-size:.8rem; }
36
- .chip:hover { border-color:var(--red); color:var(--red); }
37
- footer { width:100%; text-align:center; font-size:.75rem; color:#777; padding:10px; }
38
- footer a { color:var(--red); text-decoration:none; }
39
- </style>
40
- </head>
41
- <body>
42
- <header>
43
- <h1>🖥️ GPU Mart <span>Assistant</span></h1>
44
- <p>India's datacenter-grade GPU marketplace — ask by typing or speaking. Runs entirely in your browser.</p>
45
- </header>
46
-
47
-
48
- <div id="status">⏳ Loading the GPU Mart model…<div id="bar"><div></div></div></div>
49
-
50
-
51
- <div id="chat"></div>
52
-
53
-
54
- <div id="opts">
55
- <label><input type="checkbox" id="speakToggle" checked> 🔊 Speak replies</label>
56
- <span class="chip" data-q="What is GPU Mart?">What is GPU Mart?</span>
57
- <span class="chip" data-q="Explain CARINA, QUASAR and DRACO">CARINA / QUASAR / DRACO</span>
58
- <span class="chip" data-q="Price of the DRACO 8x H200 server?">DRACO 8× H200 price</span>
59
- <span class="chip" data-q="How do I get a quote?">Get a quote</span>
60
- </div>
61
-
62
-
63
- <div id="controls">
64
- <input id="box" type="text" placeholder="Ask about GPU Mart…" autocomplete="off">
65
- <button id="mic" title="Speak your question">🎤</button>
66
- <button id="send">Send</button>
67
- </div>
68
-
69
-
70
- <footer>
71
- Model: <a href="https://huggingface.co/VickyRDP/gpumart-qwen2.5-0.5b-instruct" target="_blank">gpumart fine-tune</a> ·
72
- Store: <a href="https://rdp.in/gpu-mart/" target="_blank">rdp.in/gpu-mart</a> ·
73
- Sales: +91&nbsp;720&nbsp;794&nbsp;8743
74
- </footer>
75
-
76
-
77
- <script type="module">
78
- const MODEL_ID = 'VickyRDP/gpumart-qwen2.5-0.5b-instruct';
79
- const SYSTEM = "You are the GPU Mart assistant for RDP GPU Mart (rdp.in/gpu-mart), India's datacenter-grade GPU marketplace by RDP Computers India Private Limited. Answer questions about GPU Mart products, series, pricing, policies and support accurately and concisely.";
80
-
81
-
82
- const chatEl = document.getElementById('chat');
83
- const statusEl = document.getElementById('status');
84
- const barWrap = document.getElementById('bar');
85
- const bar = barWrap.querySelector('div');
86
- const box = document.getElementById('box');
87
- const sendBtn = document.getElementById('send');
88
- const micBtn = document.getElementById('mic');
89
- const speakToggle = document.getElementById('speakToggle');
90
-
91
-
92
- const history = [];
93
- let generator = null, busy = false;
94
-
95
-
96
- function addMsg(text, cls) {
97
- const d = document.createElement('div');
98
- d.className = 'msg ' + cls;
99
- d.textContent = text;
100
- chatEl.appendChild(d);
101
- chatEl.scrollTop = chatEl.scrollHeight;
102
- return d;
103
- }
104
-
105
-
106
- function speak(text) {
107
- if (!speakToggle.checked || !window.speechSynthesis) return;
108
- speechSynthesis.cancel();
109
- const u = new SpeechSynthesisUtterance(text.slice(0, 800));
110
- u.lang = 'en-IN'; u.rate = 1.02;
111
- const vs = speechSynthesis.getVoices();
112
- u.voice = vs.find(v => v.lang === 'en-IN') || vs.find(v => v.lang.startsWith('en')) || null;
113
- speechSynthesis.speak(u);
114
- }
115
-
116
-
117
- async function loadModel() {
118
- try {
119
- const { pipeline, TextStreamer } = await import('https://cdn.jsdelivr.net/npm/@huggingface/transformers@3.5.2');
120
- window.__TextStreamer = TextStreamer;
121
- if (!navigator.gpu) {
122
- statusEl.firstChild.textContent = '🔴 GPU Mart requires WebGPU. Open this Space in the latest Chrome or Edge with WebGPU enabled.';
123
- return;
124
- }
125
- const adapter = await navigator.gpu.requestAdapter();
126
- if (!adapter) {
127
- statusEl.firstChild.textContent = '🔴 WebGPU is unavailable. Open this Space in the latest Chrome or Edge with WebGPU enabled.';
128
- return;
129
- }
130
- const device = 'webgpu';
131
- statusEl.firstChild.textContent = '⏳ Downloading the GPU Mart model (~1.2 GB, one-time, cached after) — WEBGPU mode…';
132
- barWrap.style.display = 'block';
133
- const files = {};
134
- generator = await pipeline('text-generation', MODEL_ID, {
135
- device, dtype: 'fp16',
136
- session_options: { graphOptimizationLevel: 'disabled' },
137
- progress_callback: p => {
138
- if (p.status === 'progress' && p.total) {
139
- files[p.file] = [p.loaded, p.total];
140
- let l = 0, t = 0; for (const k in files) { l += files[k][0]; t += files[k][1]; }
141
- bar.style.width = Math.round(100 * l / t) + '%';
142
- }
143
- }
144
- });
145
- barWrap.style.display = 'none';
146
- statusEl.firstChild.textContent = '🟢 GPU Mart model loaded — ask away (type or tap the mic).';
147
- addMsg("Namaste! I'm the GPU Mart assistant — trained on RDP GPU Mart's catalog and policies. Ask me about products, CARINA/QUASAR/DRACO series, pricing, quotes, shipping, warranty or support.", 'bot');
148
- } catch (e) {
149
- console.error(e);
150
- statusEl.firstChild.textContent = '🔴 Could not load the model — it may still be uploading to Hugging Face. Please refresh in a few minutes. Meanwhile, visit rdp.in/gpu-mart or call +91 720 794 8743.';
151
- }
152
- }
153
-
154
-
155
- async function respond(text) {
156
- if (!text.trim() || busy) return;
157
- box.value = '';
158
- addMsg(text, 'user');
159
- if (!generator) { addMsg('The model is still loading — one moment please…', 'bot'); return; }
160
- busy = true; sendBtn.disabled = true;
161
- const botEl = addMsg('…', 'bot');
162
- try {
163
- const msgs = [{ role: 'system', content: SYSTEM }, ...history.slice(-6), { role: 'user', content: text }];
164
- let out = '';
165
- const streamer = new window.__TextStreamer(generator.tokenizer, {
166
- skip_prompt: true, skip_special_tokens: true,
167
- callback_function: t => { out += t; botEl.textContent = out; chatEl.scrollTop = chatEl.scrollHeight; }
168
- });
169
- const res = await generator(msgs, { max_new_tokens: 220, do_sample: true, temperature: 0.3, top_p: 0.9, repetition_penalty: 1.1, streamer });
170
- const full = (res[0].generated_text.at(-1).content || out).trim();
171
- botEl.textContent = full;
172
- history.push({ role: 'user', content: text }, { role: 'assistant', content: full });
173
- speak(full);
174
- } catch (e) {
175
- console.error(e);
176
- botEl.textContent = 'Sorry, something went wrong generating a reply. Please try again.';
177
- }
178
- busy = false; sendBtn.disabled = false;
179
- }
180
-
181
-
182
- sendBtn.onclick = () => respond(box.value);
183
- box.addEventListener('keydown', e => { if (e.key === 'Enter') respond(box.value); });
184
- document.querySelectorAll('.chip').forEach(c => c.onclick = () => respond(c.dataset.q));
185
-
186
-
187
- // ---- Voice input (Web Speech API) ----
188
- const SR = window.SpeechRecognition || window.webkitSpeechRecognition;
189
- if (!SR) { micBtn.disabled = true; micBtn.title = 'Voice input not supported in this browser'; }
190
- let rec = null, listening = false;
191
- micBtn.onclick = () => {
192
- if (!SR) return;
193
- if (listening) { rec && rec.stop(); return; }
194
- rec = new SR();
195
- rec.lang = 'en-IN'; rec.interimResults = true;
196
- let finalTxt = '';
197
- rec.onresult = e => { let t = ''; for (const r of e.results) t += r[0].transcript; box.value = t;
198
- if (e.results[e.results.length - 1].isFinal) finalTxt = t; };
199
- rec.onend = () => { listening = false; micBtn.classList.remove('listening'); micBtn.textContent = '🎤';
200
- if (finalTxt.trim()) respond(finalTxt); };
201
- rec.onerror = () => { listening = false; micBtn.classList.remove('listening'); micBtn.textContent = '🎤'; };
202
- listening = true; micBtn.classList.add('listening'); micBtn.textContent = '🔴';
203
- rec.start();
204
- };
205
- if (window.speechSynthesis) speechSynthesis.getVoices();
206
-
207
-
208
- loadModel();
209
- </script>
210
- </body>
211
- </html>
212
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <!DOCTYPE html>
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
2
 
3
+ <html lang="en">
4
+
5
+ <head>
6
+
7
+ <meta charset="UTF-8">
8
+
9
+ <meta name="viewport" content="width=device-width, initial-scale=1.0">
10
+
11
+ <title>GPU Mart Assistant — voice + text AI for RDP GPU Mart</title>
12
+
13
+ <meta name="description" content="Ask anything about RDP GPU Mart (rdp.in/gpu-mart) — India's datacenter-grade GPU marketplace. A small fine-tuned model, running right in your browser, with voice and text.">
14
+
15
+ <style>
16
+
17
+ :root { --red:#d82228; --bg:#e8e8e8; --ink:#1a1a1a; --card:#ffffff; }
18
+
19
+ * { box-sizing:border-box; margin:0; padding:0; }
20
+
21
+ body { font-family:'Segoe UI',system-ui,-apple-system,sans-serif; background:var(--bg); color:var(--ink);
22
+
23
+ display:flex; flex-direction:column; align-items:center; min-height:100vh; }
24
+
25
+ header { width:100%; background:#fff; border-bottom:3px solid var(--red); padding:14px 20px; text-align:center; }
26
+
27
+ header h1 { font-size:1.25rem; } header h1 span { color:var(--red); }
28
+
29
+ header p { font-size:.85rem; color:#555; margin-top:2px; }
30
+
31
+ #status { width:min(760px,94vw); margin:10px auto 0; font-size:.85rem; color:#444; background:#fff;
32
+
33
+ border-radius:10px; padding:8px 14px; border-left:4px solid var(--red); }
34
+
35
+ #bar { height:6px; background:#eee; border-radius:3px; margin-top:6px; overflow:hidden; display:none; }
36
+
37
+ #bar > div { height:100%; width:0%; background:var(--red); transition:width .3s; }
38
+
39
+ #chat { width:min(760px,94vw); flex:1; margin:12px auto; background:var(--card); border-radius:14px;
40
+
41
+ padding:16px; overflow-y:auto; min-height:340px; max-height:56vh; box-shadow:0 1px 4px rgba(0,0,0,.08); }
42
+
43
+ .msg { margin:8px 0; padding:10px 14px; border-radius:12px; max-width:85%; line-height:1.45; font-size:.95rem;
44
+
45
+ white-space:pre-wrap; word-wrap:break-word; }
46
+
47
+ .user { background:var(--red); color:#fff; margin-left:auto; }
48
+
49
+ .bot { background:#f2f2f2; }
50
+
51
+ #controls { width:min(760px,94vw); margin:0 auto 8px; display:flex; gap:8px; }
52
+
53
+ #box { flex:1; padding:12px 14px; border:1px solid #ccc; border-radius:10px; font-size:1rem; outline:none; }
54
+
55
+ #box:focus { border-color:var(--red); }
56
+
57
+ button { border:none; border-radius:10px; padding:12px 18px; font-size:1rem; cursor:pointer; }
58
+
59
+ #send { background:var(--red); color:#fff; }
60
+
61
+ #mic { background:#fff; color:var(--red); border:2px solid var(--red); }
62
+
63
+ #mic.listening { background:var(--red); color:#fff; animation:pulse 1.2s infinite; }
64
+
65
+ @keyframes pulse { 50% { opacity:.6; } }
66
+
67
+ #opts { width:min(760px,94vw); margin:0 auto 10px; display:flex; align-items:center; gap:14px; font-size:.85rem; color:#444; flex-wrap:wrap; }
68
+
69
+ .chip { background:#fff; border:1px solid #ddd; border-radius:16px; padding:5px 12px; cursor:pointer; font-size:.8rem; }
70
+
71
+ .chip:hover { border-color:var(--red); color:var(--red); }
72
+
73
+ footer { width:100%; text-align:center; font-size:.75rem; color:#777; padding:10px; }
74
+
75
+ footer a { color:var(--red); text-decoration:none; }
76
+
77
+ </style>
78
+
79
+ </head>
80
+
81
+ <body>
82
+
83
+ <header>
84
+
85
+ <h1>🖥️ GPU Mart <span>Assistant</span></h1>
86
+
87
+ <p>India's datacenter-grade GPU marketplace — ask by typing or speaking. Runs entirely in your browser.</p>
88
+
89
+ </header>
90
+
91
+
92
+
93
+
94
+
95
+
96
+
97
+ <div id="status">⏳ Loading the GPU Mart model…<div id="bar"><div></div></div></div>
98
+
99
+
100
+
101
+
102
+
103
+
104
+
105
+ <div id="chat"></div>
106
+
107
+
108
+
109
+
110
+
111
+
112
+
113
+ <div id="opts">
114
+
115
+ <label><input type="checkbox" id="speakToggle" checked> 🔊 Speak replies</label>
116
+
117
+ <span class="chip" data-q="What is GPU Mart?">What is GPU Mart?</span>
118
+
119
+ <span class="chip" data-q="Explain CARINA, QUASAR and DRACO">CARINA / QUASAR / DRACO</span>
120
+
121
+ <span class="chip" data-q="Price of the DRACO 8x H200 server?">DRACO 8× H200 price</span>
122
+
123
+ <span class="chip" data-q="How do I get a quote?">Get a quote</span>
124
+
125
+ </div>
126
+
127
+
128
+
129
+
130
+
131
+
132
+
133
+ <div id="controls">
134
+
135
+ <input id="box" type="text" placeholder="Ask about GPU Mart…" autocomplete="off">
136
+
137
+ <button id="mic" title="Speak your question">🎤</button>
138
+
139
+ <button id="send">Send</button>
140
+
141
+ </div>
142
+
143
+
144
+
145
+
146
+
147
+
148
+
149
+ <footer>
150
+
151
+ Model: <a href="https://huggingface.co/VickyRDP/gpumart-qwen2.5-0.5b-instruct" target="_blank">gpumart fine-tune</a> ·
152
+
153
+ Store: <a href="https://rdp.in/gpu-mart/" target="_blank">rdp.in/gpu-mart</a> ·
154
+
155
+ Sales: +91&nbsp;720&nbsp;794&nbsp;8743
156
+
157
+ </footer>
158
+
159
+
160
+
161
+
162
+
163
+
164
+
165
+ <script type="module">
166
+
167
+ const MODEL_ID = 'VickyRDP/gpumart-qwen2.5-0.5b-instruct';
168
+
169
+ const SYSTEM = "You are the GPU Mart assistant for RDP GPU Mart (rdp.in/gpu-mart), India's datacenter-grade GPU marketplace by RDP Computers India Private Limited. Answer questions about GPU Mart products, series, pricing, policies and support accurately and concisely.";
170
+
171
+
172
+
173
+
174
+
175
+ const chatEl = document.getElementById('chat');
176
+
177
+ const statusEl = document.getElementById('status');
178
+
179
+ const barWrap = document.getElementById('bar');
180
+
181
+ const bar = barWrap.querySelector('div');
182
+
183
+ const box = document.getElementById('box');
184
+
185
+ const sendBtn = document.getElementById('send');
186
+
187
+ const micBtn = document.getElementById('mic');
188
+
189
+ const speakToggle = document.getElementById('speakToggle');
190
+
191
+
192
+
193
+
194
+
195
+ const history = [];
196
+
197
+ let generator = null, busy = false;
198
+
199
+
200
+
201
+
202
+
203
+ function addMsg(text, cls) {
204
+
205
+ const d = document.createElement('div');
206
+
207
+ d.className = 'msg ' + cls;
208
+
209
+ d.textContent = text;
210
+
211
+ chatEl.appendChild(d);
212
+
213
+ chatEl.scrollTop = chatEl.scrollHeight;
214
+
215
+ return d;
216
+
217
+ }
218
+
219
+
220
+
221
+
222
+
223
+ function speak(text) {
224
+
225
+ if (!speakToggle.checked || !window.speechSynthesis) return;
226
+
227
+ speechSynthesis.cancel();
228
+
229
+ const u = new SpeechSynthesisUtterance(text.slice(0, 800));
230
+
231
+ u.lang = 'en-IN'; u.rate = 1.02;
232
+
233
+ const vs = speechSynthesis.getVoices();
234
+
235
+ u.voice = vs.find(v => v.lang === 'en-IN') || vs.find(v => v.lang.startsWith('en')) || null;
236
+
237
+ speechSynthesis.speak(u);
238
+
239
+ }
240
+
241
+
242
+
243
+
244
+
245
+ async function loadModel() {
246
+
247
+ try {
248
+
249
+ const { pipeline, TextStreamer } = await import('https://cdn.jsdelivr.net/npm/@huggingface/transformers@3');
250
+
251
+ window.__TextStreamer = TextStreamer;
252
+
253
+ if (!navigator.gpu) {
254
+
255
+ statusEl.firstChild.textContent = '🔴 GPU Mart requires WebGPU. Open this Space in the latest Chrome or Edge with WebGPU enabled.';
256
+
257
+ return;
258
+
259
+ }
260
+
261
+ const adapter = await navigator.gpu.requestAdapter();
262
+
263
+ if (!adapter) {
264
+
265
+ statusEl.firstChild.textContent = '🔴 WebGPU is unavailable. Open this Space in the latest Chrome or Edge with WebGPU enabled.';
266
+
267
+ return;
268
+
269
+ }
270
+
271
+ const device = 'webgpu';
272
+
273
+ statusEl.firstChild.textContent = '⏳ Downloading the GPU Mart model (~1.2 GB, one-time, cached after) — WEBGPU mode…';
274
+
275
+ barWrap.style.display = 'block';
276
+
277
+ const files = {};
278
+
279
+ generator = await pipeline('text-generation', MODEL_ID, {
280
+
281
+ device, dtype: 'fp16',
282
+
283
+ session_options: { graphOptimizationLevel: 'disabled' },
284
+
285
+ progress_callback: p => {
286
+
287
+ if (p.status === 'progress' && p.total) {
288
+
289
+ files[p.file] = [p.loaded, p.total];
290
+
291
+ let l = 0, t = 0; for (const k in files) { l += files[k][0]; t += files[k][1]; }
292
+
293
+ bar.style.width = Math.round(100 * l / t) + '%';
294
+
295
+ }
296
+
297
+ }
298
+
299
+ });
300
+
301
+ barWrap.style.display = 'none';
302
+
303
+ statusEl.firstChild.textContent = '🟢 GPU Mart model loaded — ask away (type or tap the mic).';
304
+
305
+ addMsg("Namaste! I'm the GPU Mart assistant — trained on RDP GPU Mart's catalog and policies. Ask me about products, CARINA/QUASAR/DRACO series, pricing, quotes, shipping, warranty or support.", 'bot');
306
+
307
+ } catch (e) {
308
+
309
+ console.error(e);
310
+
311
+ statusEl.firstChild.textContent = '🔴 Could not load the model — it may still be uploading to Hugging Face. Please refresh in a few minutes. Meanwhile, visit rdp.in/gpu-mart or call +91 720 794 8743.';
312
+
313
+ }
314
+
315
+ }
316
+
317
+
318
+
319
+
320
+
321
+ async function respond(text) {
322
+
323
+ if (!text.trim() || busy) return;
324
+
325
+ box.value = '';
326
+
327
+ addMsg(text, 'user');
328
+
329
+ if (!generator) { addMsg('The model is still loading — one moment please…', 'bot'); return; }
330
+
331
+ busy = true; sendBtn.disabled = true;
332
+
333
+ const botEl = addMsg('…', 'bot');
334
+
335
+ try {
336
+
337
+ const msgs = [{ role: 'system', content: SYSTEM }, ...history.slice(-6), { role: 'user', content: text }];
338
+
339
+ let out = '';
340
+
341
+ const streamer = new window.__TextStreamer(generator.tokenizer, {
342
+
343
+ skip_prompt: true, skip_special_tokens: true,
344
+
345
+ callback_function: t => { out += t; botEl.textContent = out; chatEl.scrollTop = chatEl.scrollHeight; }
346
+
347
+ });
348
+
349
+ const res = await generator(msgs, { max_new_tokens: 220, do_sample: true, temperature: 0.3, top_p: 0.9, repetition_penalty: 1.1, streamer });
350
+
351
+ const full = (res[0].generated_text.at(-1).content || out).trim();
352
+
353
+ botEl.textContent = full;
354
+
355
+ history.push({ role: 'user', content: text }, { role: 'assistant', content: full });
356
+
357
+ speak(full);
358
+
359
+ } catch (e) {
360
+
361
+ console.error(e);
362
+
363
+ botEl.textContent = 'Sorry, something went wrong generating a reply. Please try again.';
364
+
365
+ }
366
+
367
+ busy = false; sendBtn.disabled = false;
368
+
369
+ }
370
+
371
+
372
+
373
+
374
+
375
+ sendBtn.onclick = () => respond(box.value);
376
+
377
+ box.addEventListener('keydown', e => { if (e.key === 'Enter') respond(box.value); });
378
+
379
+ document.querySelectorAll('.chip').forEach(c => c.onclick = () => respond(c.dataset.q));
380
+
381
+
382
+
383
+
384
+
385
+ // ---- Voice input (Web Speech API) ----
386
+
387
+ const SR = window.SpeechRecognition || window.webkitSpeechRecognition;
388
+
389
+ if (!SR) { micBtn.disabled = true; micBtn.title = 'Voice input not supported in this browser'; }
390
+
391
+ let rec = null, listening = false;
392
+
393
+ micBtn.onclick = () => {
394
+
395
+ if (!SR) return;
396
+
397
+ if (listening) { rec && rec.stop(); return; }
398
+
399
+ rec = new SR();
400
+
401
+ rec.lang = 'en-IN'; rec.interimResults = true;
402
+
403
+ let finalTxt = '';
404
+
405
+ rec.onresult = e => { let t = ''; for (const r of e.results) t += r[0].transcript; box.value = t;
406
+
407
+ if (e.results[e.results.length - 1].isFinal) finalTxt = t; };
408
+
409
+ rec.onend = () => { listening = false; micBtn.classList.remove('listening'); micBtn.textContent = '🎤';
410
+
411
+ if (finalTxt.trim()) respond(finalTxt); };
412
+
413
+ rec.onerror = () => { listening = false; micBtn.classList.remove('listening'); micBtn.textContent = '🎤'; };
414
+
415
+ listening = true; micBtn.classList.add('listening'); micBtn.textContent = '🔴';
416
+
417
+ rec.start();
418
+
419
+ };
420
+
421
+ if (window.speechSynthesis) speechSynthesis.getVoices();
422
+
423
+
424
+
425
+
426
+
427
+ loadModel();
428
+
429
+ </script>
430
+
431
+ </body>
432
+
433
+ </html>
434
+
435
+
436
+
437
+
438
+