Docfile commited on
Commit
0abab50
·
verified ·
1 Parent(s): f97a643

Update templates/index.html

Browse files
Files changed (1) hide show
  1. templates/index.html +48 -173
templates/index.html CHANGED
@@ -9,154 +9,62 @@
9
  </head>
10
  <body class="bg-gray-100 h-screen">
11
  <div class="container mx-auto p-4 h-full flex flex-col">
12
- <!-- Sidebar for conversations -->
13
- <div class="grid grid-cols-4 gap-4 h-full">
14
- <div class="bg-white rounded-lg shadow-lg p-4">
15
- <div class="flex flex-col h-full">
16
- <button onclick="startNewConversation()" class="w-full bg-blue-500 text-white px-4 py-2 rounded hover:bg-blue-600 mb-4">
17
- Nouvelle conversation
 
 
 
 
 
18
  </button>
19
- <div id="conversationsList" class="flex-1 overflow-y-auto space-y-2">
20
- <!-- Conversations will be listed here -->
21
- </div>
22
  </div>
23
  </div>
24
 
25
- <!-- Main chat area -->
26
- <div class="col-span-3 bg-white rounded-lg shadow-lg p-6 flex flex-col">
27
- <!-- Header -->
28
- <div class="flex justify-between items-center mb-6">
29
- <h1 class="text-2xl font-bold">Mariam AI</h1>
30
- <div class="flex space-x-4">
31
- <label class="flex items-center">
32
- <input type="checkbox" id="webSearchToggle" class="mr-2">
33
- Activer la recherche web
34
- </label>
35
- <button onclick="clearChat()" class="bg-red-500 text-white px-4 py-2 rounded hover:bg-red-600">
36
- Effacer le chat
37
- </button>
38
- </div>
39
- </div>
40
-
41
- <!-- File Upload -->
42
- <div class="mb-4">
43
- <input type="file" id="fileUpload" class="hidden" accept=".jpg,.jpeg,.png,.pdf,.txt,.mp3,.mp4">
44
- <label for="fileUpload" class="cursor-pointer bg-blue-500 text-white px-4 py-2 rounded hover:bg-blue-600">
45
- Télécharger un fichier
46
- </label>
47
- <span id="fileName" class="ml-2 text-gray-600"></span>
48
- </div>
49
 
50
- <!-- Chat Messages -->
51
- <div id="chatMessages" class="flex-1 overflow-y-auto mb-4 space-y-4 bg-gray-50 p-4 rounded-lg">
52
- <!-- Messages will be displayed here -->
 
 
 
 
53
  </div>
 
 
54
 
55
- <!-- Input Area -->
56
- <div class="border-t pt-4">
57
- <div class="flex space-x-4">
58
- <input type="text" id="messageInput"
59
- class="flex-1 border rounded-lg px-4 py-2 focus:outline-none focus:ring-2 focus:ring-blue-500"
60
- placeholder="Écrivez votre message...">
61
- <button onclick="sendMessage()"
62
- class="bg-blue-500 text-white px-6 py-2 rounded-lg hover:bg-blue-600 transition duration-200">
63
- Envoyer
64
- </button>
65
- </div>
66
  </div>
67
  </div>
68
  </div>
69
  </div>
70
 
71
  <script>
72
- // Global variables
73
  const messageInput = document.getElementById('messageInput');
74
  const chatMessages = document.getElementById('chatMessages');
75
  const webSearchToggle = document.getElementById('webSearchToggle');
76
  const fileUpload = document.getElementById('fileUpload');
77
  const fileName = document.getElementById('fileName');
78
- const conversationsList = document.getElementById('conversationsList');
79
-
80
- let conversations = [];
81
- let currentConversationId = null;
82
-
83
- // Conversation Management
84
- function startNewConversation() {
85
- const conversationId = Date.now().toString();
86
- const conversation = {
87
- id: conversationId,
88
- title: `Conversation ${conversations.length + 1}`,
89
- messages: []
90
- };
91
-
92
- conversations.push(conversation);
93
- currentConversationId = conversationId;
94
- updateConversationsList();
95
- clearChatMessages();
96
- }
97
-
98
- function updateConversationsList() {
99
- conversationsList.innerHTML = '';
100
- conversations.forEach(conv => {
101
- const convDiv = document.createElement('div');
102
- convDiv.className = `p-2 rounded cursor-pointer ${conv.id === currentConversationId ? 'bg-blue-100' : 'hover:bg-gray-100'}`;
103
- convDiv.onclick = () => loadConversation(conv.id);
104
- convDiv.textContent = conv.title;
105
- conversationsList.appendChild(convDiv);
106
- });
107
- }
108
-
109
- // Modifiez la fonction loadConversation :
110
- async function loadConversation(conversationId) {
111
- if (conversationId === currentConversationId) return;
112
-
113
- try {
114
- // Informer le backend du changement de conversation
115
- const response = await fetch('/switch_conversation', {
116
- method: 'POST',
117
- headers: {
118
- 'Content-Type': 'application/json'
119
- },
120
- body: JSON.stringify({
121
- conversation_id: conversationId
122
- })
123
- });
124
-
125
- const data = await response.json();
126
- if (data.error) {
127
- alert(`Erreur: ${data.error}`);
128
- return;
129
- }
130
-
131
- currentConversationId = conversationId;
132
- const conversation = conversations.find(c => c.id === conversationId);
133
- updateConversationsList();
134
-
135
- if (conversation) {
136
- clearChatMessages();
137
-
138
- conversation.messages.forEach(msg => {
139
- const messageDiv = document.createElement('div');
140
- messageDiv.className = `flex ${msg.isUser ? 'justify-end' : ''}`;
141
-
142
- const innerDiv = document.createElement('div');
143
- innerDiv.className = `max-w-3/4 p-3 rounded-lg ${msg.isUser ? 'bg-blue-500 text-white' : 'bg-gray-200'}`;
144
- innerDiv.innerHTML = marked.parse(msg.content);
145
-
146
- messageDiv.appendChild(innerDiv);
147
- chatMessages.appendChild(messageDiv);
148
- });
149
-
150
- chatMessages.scrollTop = chatMessages.scrollHeight;
151
- }
152
- } catch (error) {
153
- alert(`Erreur lors du changement de conversation: ${error.message}`);
154
- }
155
- }
156
-
157
- function clearChatMessages() {
158
- chatMessages.innerHTML = '';
159
- }
160
 
161
  function addMessage(content, isUser = false) {
162
  const messageDiv = document.createElement('div');
@@ -169,24 +77,12 @@ async function loadConversation(conversationId) {
169
  messageDiv.appendChild(innerDiv);
170
  chatMessages.appendChild(messageDiv);
171
  chatMessages.scrollTop = chatMessages.scrollHeight;
172
-
173
- if (currentConversationId) {
174
- const conversation = conversations.find(c => c.id === currentConversationId);
175
- if (conversation) {
176
- conversation.messages.push({ content, isUser });
177
- }
178
- }
179
  }
180
 
181
- // Message Handling
182
  async function sendMessage() {
183
  const message = messageInput.value.trim();
184
  if (!message) return;
185
 
186
- if (!currentConversationId) {
187
- startNewConversation();
188
- }
189
-
190
  addMessage(message, true);
191
  messageInput.value = '';
192
 
@@ -198,8 +94,7 @@ async function loadConversation(conversationId) {
198
  },
199
  body: JSON.stringify({
200
  message: message,
201
- web_search: webSearchToggle.checked,
202
- conversation_id: currentConversationId
203
  })
204
  });
205
 
@@ -214,7 +109,12 @@ async function loadConversation(conversationId) {
214
  }
215
  }
216
 
217
- // File Upload Handling
 
 
 
 
 
218
  fileUpload.addEventListener('change', async (e) => {
219
  const file = e.target.files[0];
220
  if (!file) return;
@@ -240,40 +140,15 @@ async function loadConversation(conversationId) {
240
  }
241
  });
242
 
243
- // Chat Clear Handling
244
  async function clearChat() {
245
  try {
246
- await fetch('/clear_chat', {
247
- method: 'POST',
248
- headers: {
249
- 'Content-Type': 'application/json'
250
- },
251
- body: JSON.stringify({
252
- conversation_id: currentConversationId
253
- })
254
- });
255
-
256
- if (currentConversationId) {
257
- const conversation = conversations.find(c => c.id === currentConversationId);
258
- if (conversation) {
259
- conversation.messages = [];
260
- }
261
- }
262
- clearChatMessages();
263
  } catch (error) {
264
  alert(`Erreur: ${error.message}`);
265
  }
266
  }
267
-
268
- // Event Listeners
269
- messageInput.addEventListener('keypress', (e) => {
270
- if (e.key === 'Enter') {
271
- sendMessage();
272
- }
273
- });
274
-
275
- // Initialize
276
- startNewConversation();
277
  </script>
278
  </body>
279
  </html>
 
9
  </head>
10
  <body class="bg-gray-100 h-screen">
11
  <div class="container mx-auto p-4 h-full flex flex-col">
12
+ <div class="bg-white rounded-lg shadow-lg p-6 h-full flex flex-col">
13
+ <!-- Header -->
14
+ <div class="flex justify-between items-center mb-6">
15
+ <h1 class="text-2xl font-bold">Mariam AI</h1>
16
+ <div class="flex space-x-4">
17
+ <label class="flex items-center">
18
+ <input type="checkbox" id="webSearchToggle" class="mr-2">
19
+ Activer la recherche web
20
+ </label>
21
+ <button onclick="clearChat()" class="bg-red-500 text-white px-4 py-2 rounded hover:bg-red-600">
22
+ Effacer le chat
23
  </button>
 
 
 
24
  </div>
25
  </div>
26
 
27
+ <!-- File Upload -->
28
+ <div class="mb-4">
29
+ <input type="file" id="fileUpload" class="hidden" accept=".jpg,.jpeg,.png,.pdf,.txt,.mp3,.mp4">
30
+ <label for="fileUpload" class="cursor-pointer bg-blue-500 text-white px-4 py-2 rounded hover:bg-blue-600">
31
+ Télécharger un fichier
32
+ </label>
33
+ <span id="fileName" class="ml-2 text-gray-600"></span>
34
+ </div>
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
35
 
36
+ <!-- Chat Messages -->
37
+ <div id="chatMessages" class="flex-1 overflow-y-auto mb-4 space-y-4">
38
+ {% for message in messages %}
39
+ <div class="flex {% if message.role == 'user' %}justify-end{% endif %}">
40
+ <div class="max-w-3/4 p-3 rounded-lg {% if message.role == 'user' %}bg-blue-500 text-white{% else %}bg-gray-200{% endif %}">
41
+ {{ message.content }}
42
+ </div>
43
  </div>
44
+ {% endfor %}
45
+ </div>
46
 
47
+ <!-- Input Area -->
48
+ <div class="border-t pt-4">
49
+ <div class="flex space-x-4">
50
+ <input type="text" id="messageInput"
51
+ class="flex-1 border rounded-lg px-4 py-2 focus:outline-none focus:ring-2 focus:ring-blue-500"
52
+ placeholder="Écrivez votre message...">
53
+ <button onclick="sendMessage()"
54
+ class="bg-blue-500 text-white px-6 py-2 rounded-lg hover:bg-blue-600 transition duration-200">
55
+ Envoyer
56
+ </button>
 
57
  </div>
58
  </div>
59
  </div>
60
  </div>
61
 
62
  <script>
 
63
  const messageInput = document.getElementById('messageInput');
64
  const chatMessages = document.getElementById('chatMessages');
65
  const webSearchToggle = document.getElementById('webSearchToggle');
66
  const fileUpload = document.getElementById('fileUpload');
67
  const fileName = document.getElementById('fileName');
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
68
 
69
  function addMessage(content, isUser = false) {
70
  const messageDiv = document.createElement('div');
 
77
  messageDiv.appendChild(innerDiv);
78
  chatMessages.appendChild(messageDiv);
79
  chatMessages.scrollTop = chatMessages.scrollHeight;
 
 
 
 
 
 
 
80
  }
81
 
 
82
  async function sendMessage() {
83
  const message = messageInput.value.trim();
84
  if (!message) return;
85
 
 
 
 
 
86
  addMessage(message, true);
87
  messageInput.value = '';
88
 
 
94
  },
95
  body: JSON.stringify({
96
  message: message,
97
+ web_search: webSearchToggle.checked
 
98
  })
99
  });
100
 
 
109
  }
110
  }
111
 
112
+ messageInput.addEventListener('keypress', (e) => {
113
+ if (e.key === 'Enter') {
114
+ sendMessage();
115
+ }
116
+ });
117
+
118
  fileUpload.addEventListener('change', async (e) => {
119
  const file = e.target.files[0];
120
  if (!file) return;
 
140
  }
141
  });
142
 
 
143
  async function clearChat() {
144
  try {
145
+ await fetch('/clear_chat', { method: 'POST' });
146
+ chatMessages.innerHTML = '';
147
+ location.reload();
 
 
 
 
 
 
 
 
 
 
 
 
 
 
148
  } catch (error) {
149
  alert(`Erreur: ${error.message}`);
150
  }
151
  }
 
 
 
 
 
 
 
 
 
 
152
  </script>
153
  </body>
154
  </html>