Athspi commited on
Commit
5f5db57
·
verified ·
1 Parent(s): 3ec474d

Update static/index.html

Browse files
Files changed (1) hide show
  1. static/index.html +5 -20
static/index.html CHANGED
@@ -317,28 +317,23 @@
317
  const welcomeScreen = document.querySelector('.welcome-screen');
318
  const sendButton = document.getElementById('send-button');
319
  let currentAudio = null;
320
-
321
  const adjustTextareaHeight = () => {
322
  messageInput.style.height = 'auto';
323
  messageInput.style.height = `${messageInput.scrollHeight}px`;
324
  updateSendButtonState();
325
  };
326
-
327
  const updateSendButtonState = () => {
328
  const isDisabled = messageInput.value.trim() === '';
329
  sendButton.classList.toggle('disabled', isDisabled);
330
  sendButton.disabled = isDisabled;
331
  };
332
-
333
  const scrollToBottom = () => {
334
  chatArea.scrollTop = chatArea.scrollHeight;
335
  };
336
-
337
  const addMessage = (content, sender, isHTML = false, audioFilename = null) => {
338
  welcomeScreen.classList.add('hidden');
339
  const messageElement = document.createElement('div');
340
  messageElement.classList.add('message', `${sender}-message`);
341
-
342
  const contentDiv = document.createElement('div');
343
  if (isHTML) {
344
  contentDiv.classList.add(`${sender}-message-content`);
@@ -347,9 +342,8 @@
347
  contentDiv.textContent = content;
348
  }
349
  messageElement.appendChild(contentDiv);
350
-
351
  if (sender === 'ai' && audioFilename) {
352
- // Download button
353
  const downloadButton = document.createElement('button');
354
  downloadButton.classList.add('download-button');
355
  downloadButton.title = "Download audio";
@@ -362,8 +356,7 @@
362
  window.location.href = `/download/${audioFilename}`;
363
  });
364
  messageElement.appendChild(downloadButton);
365
-
366
- // Play button
367
  const playButton = document.createElement('button');
368
  playButton.classList.add('audio-button');
369
  playButton.dataset.audioUrl = `/static/audio/${audioFilename}`;
@@ -379,16 +372,13 @@
379
  playAudio(e.currentTarget, url);
380
  });
381
  messageElement.appendChild(playButton);
382
-
383
- // Auto-play first AI audio
384
  setTimeout(() => playButton.click(), 300);
385
  }
386
-
387
  chatArea.appendChild(messageElement);
388
  scrollToBottom();
389
  return messageElement;
390
  };
391
-
392
  const showTypingIndicator = () => {
393
  const indicatorElement = document.createElement('div');
394
  indicatorElement.classList.add('message', 'ai-message', 'typing-indicator');
@@ -397,7 +387,6 @@
397
  scrollToBottom();
398
  return indicatorElement;
399
  };
400
-
401
  const playAudio = async (buttonElement, audioUrl) => {
402
  if (currentAudio) {
403
  currentAudio.pause();
@@ -428,7 +417,6 @@
428
  buttonElement.disabled = false;
429
  }
430
  };
431
-
432
  const getAIResponse = async (userMessage) => {
433
  const indicator = showTypingIndicator();
434
  try {
@@ -443,8 +431,8 @@
443
  }
444
  chatArea.removeChild(indicator);
445
  addMessage(
446
- data.response_html,
447
- 'ai',
448
  true,
449
  data.audio_filename
450
  );
@@ -454,7 +442,6 @@
454
  console.error("Error:", error);
455
  }
456
  };
457
-
458
  chatForm.addEventListener('submit', async (e) => {
459
  e.preventDefault();
460
  const message = messageInput.value.trim();
@@ -465,14 +452,12 @@
465
  await getAIResponse(message);
466
  }
467
  });
468
-
469
  messageInput.addEventListener('keydown', (e) => {
470
  if (e.key === 'Enter' && !e.shiftKey) {
471
  e.preventDefault();
472
  chatForm.dispatchEvent(new Event('submit'));
473
  }
474
  });
475
-
476
  messageInput.addEventListener('input', adjustTextareaHeight);
477
  updateSendButtonState();
478
  messageInput.focus();
 
317
  const welcomeScreen = document.querySelector('.welcome-screen');
318
  const sendButton = document.getElementById('send-button');
319
  let currentAudio = null;
 
320
  const adjustTextareaHeight = () => {
321
  messageInput.style.height = 'auto';
322
  messageInput.style.height = `${messageInput.scrollHeight}px`;
323
  updateSendButtonState();
324
  };
 
325
  const updateSendButtonState = () => {
326
  const isDisabled = messageInput.value.trim() === '';
327
  sendButton.classList.toggle('disabled', isDisabled);
328
  sendButton.disabled = isDisabled;
329
  };
 
330
  const scrollToBottom = () => {
331
  chatArea.scrollTop = chatArea.scrollHeight;
332
  };
 
333
  const addMessage = (content, sender, isHTML = false, audioFilename = null) => {
334
  welcomeScreen.classList.add('hidden');
335
  const messageElement = document.createElement('div');
336
  messageElement.classList.add('message', `${sender}-message`);
 
337
  const contentDiv = document.createElement('div');
338
  if (isHTML) {
339
  contentDiv.classList.add(`${sender}-message-content`);
 
342
  contentDiv.textContent = content;
343
  }
344
  messageElement.appendChild(contentDiv);
 
345
  if (sender === 'ai' && audioFilename) {
346
+ // Add download button
347
  const downloadButton = document.createElement('button');
348
  downloadButton.classList.add('download-button');
349
  downloadButton.title = "Download audio";
 
356
  window.location.href = `/download/${audioFilename}`;
357
  });
358
  messageElement.appendChild(downloadButton);
359
+ // Add play button
 
360
  const playButton = document.createElement('button');
361
  playButton.classList.add('audio-button');
362
  playButton.dataset.audioUrl = `/static/audio/${audioFilename}`;
 
372
  playAudio(e.currentTarget, url);
373
  });
374
  messageElement.appendChild(playButton);
375
+ // Auto-play audio
 
376
  setTimeout(() => playButton.click(), 300);
377
  }
 
378
  chatArea.appendChild(messageElement);
379
  scrollToBottom();
380
  return messageElement;
381
  };
 
382
  const showTypingIndicator = () => {
383
  const indicatorElement = document.createElement('div');
384
  indicatorElement.classList.add('message', 'ai-message', 'typing-indicator');
 
387
  scrollToBottom();
388
  return indicatorElement;
389
  };
 
390
  const playAudio = async (buttonElement, audioUrl) => {
391
  if (currentAudio) {
392
  currentAudio.pause();
 
417
  buttonElement.disabled = false;
418
  }
419
  };
 
420
  const getAIResponse = async (userMessage) => {
421
  const indicator = showTypingIndicator();
422
  try {
 
431
  }
432
  chatArea.removeChild(indicator);
433
  addMessage(
434
+ data.response_html,
435
+ 'ai',
436
  true,
437
  data.audio_filename
438
  );
 
442
  console.error("Error:", error);
443
  }
444
  };
 
445
  chatForm.addEventListener('submit', async (e) => {
446
  e.preventDefault();
447
  const message = messageInput.value.trim();
 
452
  await getAIResponse(message);
453
  }
454
  });
 
455
  messageInput.addEventListener('keydown', (e) => {
456
  if (e.key === 'Enter' && !e.shiftKey) {
457
  e.preventDefault();
458
  chatForm.dispatchEvent(new Event('submit'));
459
  }
460
  });
 
461
  messageInput.addEventListener('input', adjustTextareaHeight);
462
  updateSendButtonState();
463
  messageInput.focus();