atlury commited on
Commit
98abda4
·
verified ·
1 Parent(s): 67af410

Update index.html

Browse files
Files changed (1) hide show
  1. index.html +25 -17
index.html CHANGED
@@ -161,7 +161,7 @@
161
  <option value="quality">Highest Quality</option>
162
  </select>
163
  <div id="model-info">
164
- TTS: Xenova/mms-tts-eng / STT: Xenova/whisper-tiny.en / LLM: Xenova/Qwen1.5-0.5B-Chat
165
  </div>
166
  </div>
167
  <div id="visualizer"></div>
@@ -176,6 +176,7 @@
176
 
177
  <script type="module">
178
  import { pipeline, env } from 'https://cdn.jsdelivr.net/npm/@xenova/[email protected]';
 
179
 
180
  env.localModelPath = './models';
181
 
@@ -198,7 +199,7 @@
198
  let myvad;
199
  let sttPipeline;
200
  let ttsPipeline;
201
- let llmPipeline;
202
  let audioContext;
203
  let analyser;
204
  let dataArray;
@@ -234,13 +235,23 @@
234
  async function initializePipelines() {
235
  try {
236
  addLog('System: Initializing pipelines...');
237
- [sttPipeline, ttsPipeline, llmPipeline] = await Promise.all([
238
  pipeline('automatic-speech-recognition', 'Xenova/whisper-tiny.en', { quantized: true }),
239
- pipeline('text-to-speech', 'Xenova/mms-tts-eng', { quantized: true }),
240
- pipeline('text-generation', 'Xenova/Qwen1.5-0.5B-Chat', { quantized: true })
241
  ]);
 
 
 
 
 
 
 
 
 
 
 
242
 
243
- addLog('System: Digital Human Voice Chat initialized with Qwen1.5-0.5B-Chat. Click "Begin Call" to start.');
244
  startButton.disabled = false;
245
  loadingDiv.style.display = 'none';
246
  } catch (error) {
@@ -252,24 +263,21 @@
252
 
253
  async function processSpeech(audio) {
254
  try {
255
- if (!sttPipeline || !ttsPipeline || !llmPipeline) {
256
  throw new Error('Pipelines not initialized');
257
  }
258
 
259
  const transcription = await sttPipeline(audio);
260
  addLog(`User: ${transcription.text}`);
261
 
262
- const messages = [
263
- { role: 'system', content: 'You are a helpful assistant.' },
264
- { role: 'user', content: transcription.text }
265
- ];
266
-
267
- const llmResponse = await llmPipeline(messages, {
268
- max_new_tokens: 128,
269
- do_sample: false
270
  });
271
 
272
- const botResponse = llmResponse[0].generated_text.find(msg => msg.role === 'assistant').content;
273
  addLog(`Bot: ${botResponse}`);
274
 
275
  isSpeaking = true;
@@ -397,7 +405,7 @@
397
  });
398
 
399
  await myvad.start();
400
- startButton.textContent = 'End Call';
401
  isListening = true;
402
  addLog('System: Listening...');
403
  } catch (error) {
 
161
  <option value="quality">Highest Quality</option>
162
  </select>
163
  <div id="model-info">
164
+ TTS: Xenova/mms-tts-eng / STT: Xenova/whisper-tiny.en / LLM: TinyLlama-1.1B-Chat-v0.4-q4f16_1-1k
165
  </div>
166
  </div>
167
  <div id="visualizer"></div>
 
176
 
177
  <script type="module">
178
  import { pipeline, env } from 'https://cdn.jsdelivr.net/npm/@xenova/[email protected]';
179
+ import * as webllm from 'https://esm.run/@mlc-ai/web-llm';
180
 
181
  env.localModelPath = './models';
182
 
 
199
  let myvad;
200
  let sttPipeline;
201
  let ttsPipeline;
202
+ let llmEngine;
203
  let audioContext;
204
  let analyser;
205
  let dataArray;
 
235
  async function initializePipelines() {
236
  try {
237
  addLog('System: Initializing pipelines...');
238
+ [sttPipeline, ttsPipeline] = await Promise.all([
239
  pipeline('automatic-speech-recognition', 'Xenova/whisper-tiny.en', { quantized: true }),
240
+ pipeline('text-to-speech', 'Xenova/mms-tts-eng', { quantized: true })
 
241
  ]);
242
+
243
+ const initProgressCallback = (report) => {
244
+ addLog(`System: ${report.text}`);
245
+ };
246
+ const selectedModel = "TinyLlama-1.1B-Chat-v0.4-q4f16_1-1k";
247
+ llmEngine = await webllm.CreateEngine(
248
+ selectedModel,
249
+ {
250
+ initProgressCallback: initProgressCallback
251
+ }
252
+ );
253
 
254
+ addLog('System: Digital Human Voice Chat initialized with WebLLM. Click "Begin Call" to start.');
255
  startButton.disabled = false;
256
  loadingDiv.style.display = 'none';
257
  } catch (error) {
 
263
 
264
  async function processSpeech(audio) {
265
  try {
266
+ if (!sttPipeline || !ttsPipeline || !llmEngine) {
267
  throw new Error('Pipelines not initialized');
268
  }
269
 
270
  const transcription = await sttPipeline(audio);
271
  addLog(`User: ${transcription.text}`);
272
 
273
+ const reply = await llmEngine.chat.completions.create({
274
+ messages: [
275
+ { role: 'system', content: 'You are a helpful assistant.' },
276
+ { role: 'user', content: transcription.text }
277
+ ]
 
 
 
278
  });
279
 
280
+ const botResponse = reply.choices[0].message.content;
281
  addLog(`Bot: ${botResponse}`);
282
 
283
  isSpeaking = true;
 
405
  });
406
 
407
  await myvad.start();
408
+ startButton.textContent = 'End Call';
409
  isListening = true;
410
  addLog('System: Listening...');
411
  } catch (error) {