Docfile commited on
Commit
49603e8
·
verified ·
1 Parent(s): b79a6a1

Update templates/index.html

Browse files
Files changed (1) hide show
  1. templates/index.html +133 -10
templates/index.html CHANGED
@@ -6,6 +6,8 @@
6
  <title>Mariam AI</title>
7
  <script src="https://cdn.tailwindcss.com"></script>
8
  <link href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/6.0.0/css/all.min.css" rel="stylesheet">
 
 
9
  <style>
10
  .message-transition {
11
  transition: all 0.3s ease-in-out;
@@ -13,6 +15,47 @@
13
  .gradient-background {
14
  background: linear-gradient(120deg, #84fab0 0%, #8fd3f4 100%);
15
  }
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
16
  </style>
17
  </head>
18
  <body class="bg-gray-50 min-h-screen">
@@ -32,11 +75,16 @@
32
  <span class="text-gray-700">Activer la recherche web</span>
33
  </label>
34
  </div>
35
- <div class="relative">
36
- <input type="file" id="fileInput" class="hidden" accept="image/*,.pdf,.txt">
37
- <button onclick="document.getElementById('fileInput').click()" class="bg-blue-500 hover:bg-blue-600 text-white px-4 py-2 rounded-lg transition duration-200">
38
- <i class="fas fa-upload mr-2"></i>Télécharger un fichier
39
  </button>
 
 
 
 
 
 
40
  </div>
41
  </div>
42
  </div>
@@ -45,7 +93,20 @@
45
  <div class="bg-white rounded-lg shadow-md h-[600px] flex flex-col">
46
  <!-- Messages Area -->
47
  <div id="chatMessages" class="flex-1 overflow-y-auto p-4 space-y-4">
48
- <!-- Messages will be inserted here -->
 
 
 
 
 
 
 
 
 
 
 
 
 
49
  </div>
50
 
51
  <!-- Input Area -->
@@ -63,6 +124,20 @@
63
  <script>
64
  let currentFile = null;
65
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
66
  document.getElementById('fileInput').addEventListener('change', async (e) => {
67
  const file = e.target.files[0];
68
  if (!file) return;
@@ -89,6 +164,22 @@
89
  }
90
  });
91
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
92
  document.getElementById('chatForm').addEventListener('submit', async (e) => {
93
  e.preventDefault();
94
 
@@ -124,7 +215,8 @@
124
  if (data.error) {
125
  addMessage('assistant', `Erreur: ${data.error}`);
126
  } else {
127
- addMessage('assistant', data.response);
 
128
  }
129
 
130
  // Reset current file
@@ -135,7 +227,7 @@
135
  }
136
  });
137
 
138
- function addMessage(role, content) {
139
  const messagesContainer = document.getElementById('chatMessages');
140
  const messageDiv = document.createElement('div');
141
  messageDiv.className = `flex ${role === 'user' ? 'justify-end' : 'justify-start'} message-transition`;
@@ -146,11 +238,19 @@
146
  ? 'bg-blue-500 text-white rounded-br-none'
147
  : 'bg-gray-100 text-gray-800 rounded-bl-none'
148
  }`;
149
- messageBubble.textContent = content;
 
 
 
 
 
 
 
 
150
 
151
  messageDiv.appendChild(messageBubble);
152
  messagesContainer.appendChild(messageDiv);
153
- messagesContainer.scrollTop = messagesContainer.scrollHeight;
154
  }
155
 
156
  function addTypingIndicator() {
@@ -168,7 +268,7 @@
168
  </div>
169
  `;
170
  messagesContainer.appendChild(indicatorDiv);
171
- messagesContainer.scrollTop = messagesContainer.scrollHeight;
172
  }
173
 
174
  function removeTypingIndicator() {
@@ -177,6 +277,29 @@
177
  indicator.remove();
178
  }
179
  }
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
180
  </script>
181
  </body>
182
  </html>
 
6
  <title>Mariam AI</title>
7
  <script src="https://cdn.tailwindcss.com"></script>
8
  <link href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/6.0.0/css/all.min.css" rel="stylesheet">
9
+ <link href="https://cdnjs.cloudflare.com/ajax/libs/highlight.js/11.9.0/styles/github.min.css" rel="stylesheet">
10
+ <script src="https://cdnjs.cloudflare.com/ajax/libs/highlight.js/11.9.0/highlight.min.js"></script>
11
  <style>
12
  .message-transition {
13
  transition: all 0.3s ease-in-out;
 
15
  .gradient-background {
16
  background: linear-gradient(120deg, #84fab0 0%, #8fd3f4 100%);
17
  }
18
+ .message-content pre {
19
+ background-color: #f6f8fa;
20
+ border-radius: 6px;
21
+ padding: 16px;
22
+ overflow-x: auto;
23
+ margin: 8px 0;
24
+ }
25
+ .message-content code {
26
+ font-family: ui-monospace, SFMono-Regular, Menlo, Monaco, Consolas, monospace;
27
+ font-size: 0.9em;
28
+ }
29
+ .message-content p {
30
+ margin-bottom: 0.5rem;
31
+ }
32
+ .message-content ul, .message-content ol {
33
+ margin-left: 1.5rem;
34
+ margin-bottom: 0.5rem;
35
+ }
36
+ .message-content ul {
37
+ list-style-type: disc;
38
+ }
39
+ .message-content ol {
40
+ list-style-type: decimal;
41
+ }
42
+ .message-content a {
43
+ color: #2563eb;
44
+ text-decoration: underline;
45
+ }
46
+ .message-content table {
47
+ border-collapse: collapse;
48
+ margin: 8px 0;
49
+ width: 100%;
50
+ }
51
+ .message-content th, .message-content td {
52
+ border: 1px solid #e5e7eb;
53
+ padding: 8px;
54
+ text-align: left;
55
+ }
56
+ .message-content th {
57
+ background-color: #f9fafb;
58
+ }
59
  </style>
60
  </head>
61
  <body class="bg-gray-50 min-h-screen">
 
75
  <span class="text-gray-700">Activer la recherche web</span>
76
  </label>
77
  </div>
78
+ <div class="flex space-x-4">
79
+ <button onclick="clearHistory()" class="bg-red-500 hover:bg-red-600 text-white px-4 py-2 rounded-lg transition duration-200">
80
+ <i class="fas fa-trash mr-2"></i>Effacer l'historique
 
81
  </button>
82
+ <div class="relative">
83
+ <input type="file" id="fileInput" class="hidden" accept="image/*,.pdf,.txt">
84
+ <button onclick="document.getElementById('fileInput').click()" class="bg-blue-500 hover:bg-blue-600 text-white px-4 py-2 rounded-lg transition duration-200">
85
+ <i class="fas fa-upload mr-2"></i>Télécharger un fichier
86
+ </button>
87
+ </div>
88
  </div>
89
  </div>
90
  </div>
 
93
  <div class="bg-white rounded-lg shadow-md h-[600px] flex flex-col">
94
  <!-- Messages Area -->
95
  <div id="chatMessages" class="flex-1 overflow-y-auto p-4 space-y-4">
96
+ <!-- Existing chat history -->
97
+ {% for message in chat_history %}
98
+ <div class="flex {{ 'justify-end' if message.role == 'user' else 'justify-start' }} message-transition">
99
+ <div class="max-w-[70%] p-3 rounded-lg {{ 'bg-blue-500 text-white rounded-br-none' if message.role == 'user' else 'bg-gray-100 text-gray-800 rounded-bl-none' }}">
100
+ {% if message.role == 'user' %}
101
+ {{ message.content }}
102
+ {% else %}
103
+ <div class="message-content prose">
104
+ {{ message.content_html | safe }}
105
+ </div>
106
+ {% endif %}
107
+ </div>
108
+ </div>
109
+ {% endfor %}
110
  </div>
111
 
112
  <!-- Input Area -->
 
124
  <script>
125
  let currentFile = null;
126
 
127
+ // Initialize highlight.js
128
+ document.addEventListener('DOMContentLoaded', (event) => {
129
+ document.querySelectorAll('pre code').forEach((el) => {
130
+ hljs.highlightElement(el);
131
+ });
132
+ });
133
+
134
+ // Function to highlight code in new messages
135
+ function highlightCode() {
136
+ document.querySelectorAll('pre code').forEach((el) => {
137
+ hljs.highlightElement(el);
138
+ });
139
+ }
140
+
141
  document.getElementById('fileInput').addEventListener('change', async (e) => {
142
  const file = e.target.files[0];
143
  if (!file) return;
 
164
  }
165
  });
166
 
167
+ async function clearHistory() {
168
+ try {
169
+ const response = await fetch('/clear', {
170
+ method: 'POST'
171
+ });
172
+ const data = await response.json();
173
+
174
+ if (data.success) {
175
+ document.getElementById('chatMessages').innerHTML = '';
176
+ }
177
+ } catch (error) {
178
+ console.error('Error:', error);
179
+ alert('Erreur lors de la suppression de l\'historique');
180
+ }
181
+ }
182
+
183
  document.getElementById('chatForm').addEventListener('submit', async (e) => {
184
  e.preventDefault();
185
 
 
215
  if (data.error) {
216
  addMessage('assistant', `Erreur: ${data.error}`);
217
  } else {
218
+ addMessage('assistant', data.response, data.response_html);
219
+ highlightCode();
220
  }
221
 
222
  // Reset current file
 
227
  }
228
  });
229
 
230
+ function addMessage(role, content, contentHtml = null) {
231
  const messagesContainer = document.getElementById('chatMessages');
232
  const messageDiv = document.createElement('div');
233
  messageDiv.className = `flex ${role === 'user' ? 'justify-end' : 'justify-start'} message-transition`;
 
238
  ? 'bg-blue-500 text-white rounded-br-none'
239
  : 'bg-gray-100 text-gray-800 rounded-bl-none'
240
  }`;
241
+
242
+ if (role === 'user' || !contentHtml) {
243
+ messageBubble.textContent = content;
244
+ } else {
245
+ const contentWrapper = document.createElement('div');
246
+ contentWrapper.className = 'message-content prose';
247
+ contentWrapper.innerHTML = contentHtml;
248
+ messageBubble.appendChild(contentWrapper);
249
+ }
250
 
251
  messageDiv.appendChild(messageBubble);
252
  messagesContainer.appendChild(messageDiv);
253
+ scrollToBottom();
254
  }
255
 
256
  function addTypingIndicator() {
 
268
  </div>
269
  `;
270
  messagesContainer.appendChild(indicatorDiv);
271
+ scrollToBottom();
272
  }
273
 
274
  function removeTypingIndicator() {
 
277
  indicator.remove();
278
  }
279
  }
280
+
281
+ function scrollToBottom() {
282
+ const messagesContainer = document.getElementById('chatMessages');
283
+ messagesContainer.scrollTop = messagesContainer.scrollHeight;
284
+ }
285
+
286
+ // Handle keyboard shortcuts
287
+ document.addEventListener('keydown', (e) => {
288
+ // Ctrl/Cmd + Enter to submit
289
+ if ((e.ctrlKey || e.metaKey) && e.key === 'Enter') {
290
+ document.getElementById('chatForm').dispatchEvent(new Event('submit'));
291
+ }
292
+ });
293
+
294
+ // Auto-resize input field
295
+ const messageInput = document.getElementById('messageInput');
296
+ messageInput.addEventListener('input', function() {
297
+ this.style.height = 'auto';
298
+ this.style.height = (this.scrollHeight) + 'px';
299
+ });
300
+
301
+ // Initialize scroll position
302
+ scrollToBottom();
303
  </script>
304
  </body>
305
  </html>