Ali Abdullah commited on
Commit
5ec4e09
·
verified ·
1 Parent(s): 79fd5d1

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +19 -15
app.py CHANGED
@@ -708,7 +708,7 @@ def index():
708
 
709
  function updateCharCount() {
710
  const count = messageInput.value.length;
711
- charCount.textContent = ${count}/1000;
712
  }
713
 
714
  async function handleSubmit(e) {
@@ -752,13 +752,13 @@ def index():
752
  }
753
 
754
  const messageDiv = document.createElement('div');
755
- messageDiv.className = message ${role};
756
 
757
  const messageContent = document.createElement('div');
758
  messageContent.className = 'message-content';
759
 
760
  const avatar = document.createElement('div');
761
- avatar.className = avatar ${role};
762
 
763
  if (role === 'user') {
764
  avatar.innerHTML = '<svg width="16" height="16" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2"><path d="M20 21v-2a4 4 0 0 0-4-4H8a4 4 0 0 0-4 4v2"></path><circle cx="12" cy="7" r="4"></circle></svg>';
@@ -770,11 +770,11 @@ def index():
770
  bubble.className = 'message-bubble';
771
 
772
  if (role === 'user') {
773
- bubble.innerHTML = <div class="message-text">${content}</div>;
774
  messageContent.appendChild(bubble);
775
  messageContent.appendChild(avatar);
776
  } else {
777
- bubble.innerHTML = <div class="message-formatted">${formatMessageContent(content)}</div>;
778
  messageContent.appendChild(avatar);
779
  messageContent.appendChild(bubble);
780
  }
@@ -787,22 +787,26 @@ def index():
787
  }
788
 
789
  function formatMessageContent(content) {
790
- return content.split('\\n').map(line => {
791
  if (line.trim().startsWith('•') || line.trim().startsWith('-')) {
792
- return <div style="display: flex; align-items: flex-start; margin-bottom: 0.375rem;">
 
793
  <span style="color: #16a34a; margin-right: 0.5rem; margin-top: 0.125rem; font-size: 0.875rem; font-weight: 500;">•</span>
794
- <span style="font-size: 0.875rem; line-height: 1.5;">${line.replace(/^[•-]\\s*/, '')}</span>
795
- </div>;
796
- } else if (/^\\d+\\./.test(line.trim())) {
797
- const match = line.match(/^\\d+\\./);
798
- return <div style="display: flex; align-items: flex-start; margin-bottom: 0.375rem;">
 
 
799
  <span style="color: #16a34a; margin-right: 0.5rem; font-weight: 600; font-size: 0.875rem;">${match ? match[0] : ''}</span>
800
- <span style="font-size: 0.875rem; line-height: 1.5;">${line.replace(/^\\d+\\.\\s*/, '')}</span>
801
- </div>;
 
802
  } else if (line.trim() === '') {
803
  return '<br>';
804
  } else {
805
- return <p style="margin-bottom: 0.375rem; font-size: 0.875rem; line-height: 1.5;">${line}</p>;
806
  }
807
  }).join('');
808
  }
 
708
 
709
  function updateCharCount() {
710
  const count = messageInput.value.length;
711
+ charCount.textContent = `${count}/1000`;
712
  }
713
 
714
  async function handleSubmit(e) {
 
752
  }
753
 
754
  const messageDiv = document.createElement('div');
755
+ messageDiv.className = `message ${role}`;
756
 
757
  const messageContent = document.createElement('div');
758
  messageContent.className = 'message-content';
759
 
760
  const avatar = document.createElement('div');
761
+ avatar.className = `avatar ${role}`;
762
 
763
  if (role === 'user') {
764
  avatar.innerHTML = '<svg width="16" height="16" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2"><path d="M20 21v-2a4 4 0 0 0-4-4H8a4 4 0 0 0-4 4v2"></path><circle cx="12" cy="7" r="4"></circle></svg>';
 
770
  bubble.className = 'message-bubble';
771
 
772
  if (role === 'user') {
773
+ bubble.innerHTML = `<div class="message-text">${content}</div>`;
774
  messageContent.appendChild(bubble);
775
  messageContent.appendChild(avatar);
776
  } else {
777
+ bubble.innerHTML = `<div class="message-formatted">${formatMessageContent(content)}</div>`;
778
  messageContent.appendChild(avatar);
779
  messageContent.appendChild(bubble);
780
  }
 
787
  }
788
 
789
  function formatMessageContent(content) {
790
+ return content.split('\n').map(line => {
791
  if (line.trim().startsWith('•') || line.trim().startsWith('-')) {
792
+ return `
793
+ <div style="display: flex; align-items: flex-start; margin-bottom: 0.375rem;">
794
  <span style="color: #16a34a; margin-right: 0.5rem; margin-top: 0.125rem; font-size: 0.875rem; font-weight: 500;">•</span>
795
+ <span style="font-size: 0.875rem; line-height: 1.5;">${line.replace(/^[•-]\s*/, '')}</span>
796
+ </div>
797
+ `;
798
+ } else if (/^\d+\./.test(line.trim())) {
799
+ const match = line.match(/^\d+\./);
800
+ return `
801
+ <div style="display: flex; align-items: flex-start; margin-bottom: 0.375rem;">
802
  <span style="color: #16a34a; margin-right: 0.5rem; font-weight: 600; font-size: 0.875rem;">${match ? match[0] : ''}</span>
803
+ <span style="font-size: 0.875rem; line-height: 1.5;">${line.replace(/^\d+\.\s*/, '')}</span>
804
+ </div>
805
+ `;
806
  } else if (line.trim() === '') {
807
  return '<br>';
808
  } else {
809
+ return `<p style="margin-bottom: 0.375rem; font-size: 0.875rem; line-height: 1.5;">${line}</p>`;
810
  }
811
  }).join('');
812
  }