Update templates/index.html
Browse files- templates/index.html +122 -40
templates/index.html
CHANGED
@@ -9,51 +9,66 @@
|
|
9 |
</head>
|
10 |
<body class="bg-gray-100 h-screen">
|
11 |
<div class="container mx-auto p-4 h-full flex flex-col">
|
12 |
-
|
13 |
-
|
14 |
-
<div class="
|
15 |
-
<
|
16 |
-
|
17 |
-
|
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 |
-
<!--
|
28 |
-
<div class="
|
29 |
-
|
30 |
-
<
|
31 |
-
|
32 |
-
|
33 |
-
|
34 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
35 |
|
36 |
-
|
37 |
-
|
38 |
-
|
39 |
-
|
40 |
-
|
41 |
-
|
|
|
42 |
</div>
|
|
|
43 |
</div>
|
44 |
-
{% endfor %}
|
45 |
-
</div>
|
46 |
|
47 |
-
|
48 |
-
|
49 |
-
|
50 |
-
|
51 |
-
|
52 |
-
|
53 |
-
|
54 |
-
|
55 |
-
|
56 |
-
|
|
|
57 |
</div>
|
58 |
</div>
|
59 |
</div>
|
@@ -65,6 +80,52 @@
|
|
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,12 +138,24 @@
|
|
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,7 +167,8 @@
|
|
94 |
},
|
95 |
body: JSON.stringify({
|
96 |
message: message,
|
97 |
-
web_search: webSearchToggle.checked
|
|
|
98 |
})
|
99 |
});
|
100 |
|
@@ -143,12 +217,20 @@
|
|
143 |
async function clearChat() {
|
144 |
try {
|
145 |
await fetch('/clear_chat', { method: 'POST' });
|
146 |
-
|
147 |
-
|
|
|
|
|
|
|
|
|
|
|
148 |
} catch (error) {
|
149 |
alert(`Erreur: ${error.message}`);
|
150 |
}
|
151 |
}
|
|
|
|
|
|
|
152 |
</script>
|
153 |
</body>
|
154 |
</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 |
+
<!-- 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 with improved scrolling -->
|
51 |
+
<div id="chatMessages" class="flex-1 overflow-y-auto mb-4 space-y-4 bg-gray-50 p-4 rounded-lg">
|
52 |
+
{% for message in messages %}
|
53 |
+
<div class="flex {% if message.role == 'user' %}justify-end{% endif %}">
|
54 |
+
<div class="max-w-3/4 p-3 rounded-lg {% if message.role == 'user' %}bg-blue-500 text-white{% else %}bg-gray-200{% endif %}">
|
55 |
+
{{ message.content }}
|
56 |
+
</div>
|
57 |
</div>
|
58 |
+
{% endfor %}
|
59 |
</div>
|
|
|
|
|
60 |
|
61 |
+
<!-- Input Area -->
|
62 |
+
<div class="border-t pt-4">
|
63 |
+
<div class="flex space-x-4">
|
64 |
+
<input type="text" id="messageInput"
|
65 |
+
class="flex-1 border rounded-lg px-4 py-2 focus:outline-none focus:ring-2 focus:ring-blue-500"
|
66 |
+
placeholder="Écrivez votre message...">
|
67 |
+
<button onclick="sendMessage()"
|
68 |
+
class="bg-blue-500 text-white px-6 py-2 rounded-lg hover:bg-blue-600 transition duration-200">
|
69 |
+
Envoyer
|
70 |
+
</button>
|
71 |
+
</div>
|
72 |
</div>
|
73 |
</div>
|
74 |
</div>
|
|
|
80 |
const webSearchToggle = document.getElementById('webSearchToggle');
|
81 |
const fileUpload = document.getElementById('fileUpload');
|
82 |
const fileName = document.getElementById('fileName');
|
83 |
+
const conversationsList = document.getElementById('conversationsList');
|
84 |
+
|
85 |
+
let conversations = [];
|
86 |
+
let currentConversationId = null;
|
87 |
+
|
88 |
+
function startNewConversation() {
|
89 |
+
const conversationId = Date.now().toString();
|
90 |
+
const conversation = {
|
91 |
+
id: conversationId,
|
92 |
+
title: `Conversation ${conversations.length + 1}`,
|
93 |
+
messages: []
|
94 |
+
};
|
95 |
+
|
96 |
+
conversations.push(conversation);
|
97 |
+
currentConversationId = conversationId;
|
98 |
+
updateConversationsList();
|
99 |
+
clearChatMessages();
|
100 |
+
}
|
101 |
+
|
102 |
+
function updateConversationsList() {
|
103 |
+
conversationsList.innerHTML = '';
|
104 |
+
conversations.forEach(conv => {
|
105 |
+
const convDiv = document.createElement('div');
|
106 |
+
convDiv.className = `p-2 rounded cursor-pointer ${conv.id === currentConversationId ? 'bg-blue-100' : 'hover:bg-gray-100'}`;
|
107 |
+
convDiv.onclick = () => loadConversation(conv.id);
|
108 |
+
convDiv.textContent = conv.title;
|
109 |
+
conversationsList.appendChild(convDiv);
|
110 |
+
});
|
111 |
+
}
|
112 |
+
|
113 |
+
function loadConversation(conversationId) {
|
114 |
+
currentConversationId = conversationId;
|
115 |
+
const conversation = conversations.find(c => c.id === conversationId);
|
116 |
+
updateConversationsList();
|
117 |
+
|
118 |
+
if (conversation) {
|
119 |
+
clearChatMessages();
|
120 |
+
conversation.messages.forEach(msg => {
|
121 |
+
addMessage(msg.content, msg.isUser);
|
122 |
+
});
|
123 |
+
}
|
124 |
+
}
|
125 |
+
|
126 |
+
function clearChatMessages() {
|
127 |
+
chatMessages.innerHTML = '';
|
128 |
+
}
|
129 |
|
130 |
function addMessage(content, isUser = false) {
|
131 |
const messageDiv = document.createElement('div');
|
|
|
138 |
messageDiv.appendChild(innerDiv);
|
139 |
chatMessages.appendChild(messageDiv);
|
140 |
chatMessages.scrollTop = chatMessages.scrollHeight;
|
141 |
+
|
142 |
+
// Save message to current conversation
|
143 |
+
if (currentConversationId) {
|
144 |
+
const conversation = conversations.find(c => c.id === currentConversationId);
|
145 |
+
if (conversation) {
|
146 |
+
conversation.messages.push({ content, isUser });
|
147 |
+
}
|
148 |
+
}
|
149 |
}
|
150 |
|
151 |
async function sendMessage() {
|
152 |
const message = messageInput.value.trim();
|
153 |
if (!message) return;
|
154 |
|
155 |
+
if (!currentConversationId) {
|
156 |
+
startNewConversation();
|
157 |
+
}
|
158 |
+
|
159 |
addMessage(message, true);
|
160 |
messageInput.value = '';
|
161 |
|
|
|
167 |
},
|
168 |
body: JSON.stringify({
|
169 |
message: message,
|
170 |
+
web_search: webSearchToggle.checked,
|
171 |
+
conversation_id: currentConversationId
|
172 |
})
|
173 |
});
|
174 |
|
|
|
217 |
async function clearChat() {
|
218 |
try {
|
219 |
await fetch('/clear_chat', { method: 'POST' });
|
220 |
+
if (currentConversationId) {
|
221 |
+
const conversation = conversations.find(c => c.id === currentConversationId);
|
222 |
+
if (conversation) {
|
223 |
+
conversation.messages = [];
|
224 |
+
}
|
225 |
+
}
|
226 |
+
clearChatMessages();
|
227 |
} catch (error) {
|
228 |
alert(`Erreur: ${error.message}`);
|
229 |
}
|
230 |
}
|
231 |
+
|
232 |
+
// Start with a new conversation
|
233 |
+
startNewConversation();
|
234 |
</script>
|
235 |
</body>
|
236 |
</html>
|