Update templates/index.html
Browse files- templates/index.html +156 -138
templates/index.html
CHANGED
@@ -1,154 +1,172 @@
|
|
1 |
<!DOCTYPE html>
|
2 |
<html lang="fr">
|
3 |
<head>
|
4 |
-
|
5 |
-
|
6 |
-
|
7 |
-
|
8 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
9 |
</head>
|
10 |
-
<body class="bg-
|
11 |
-
|
12 |
-
|
13 |
-
|
14 |
-
|
15 |
-
|
16 |
-
|
17 |
-
|
18 |
-
|
19 |
-
|
20 |
-
|
21 |
-
|
22 |
-
|
23 |
-
|
24 |
-
|
25 |
-
</div>
|
26 |
|
27 |
-
|
28 |
-
|
29 |
-
|
30 |
-
|
31 |
-
|
32 |
-
|
33 |
-
|
34 |
-
|
35 |
-
|
36 |
-
|
37 |
-
|
38 |
-
|
39 |
-
|
40 |
-
|
41 |
-
|
42 |
-
|
43 |
-
|
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 |
-
|
61 |
-
|
62 |
-
|
63 |
-
|
64 |
-
|
65 |
-
|
66 |
-
|
67 |
-
|
68 |
-
|
69 |
-
|
70 |
-
|
71 |
-
|
72 |
-
|
73 |
-
|
74 |
-
|
75 |
-
|
76 |
-
|
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 |
|
89 |
-
|
90 |
-
|
91 |
-
|
92 |
-
|
93 |
-
|
94 |
-
|
95 |
-
|
96 |
-
|
97 |
-
|
98 |
-
})
|
99 |
-
});
|
100 |
|
101 |
-
|
102 |
-
|
103 |
-
|
104 |
-
|
105 |
-
|
106 |
-
|
107 |
-
|
108 |
-
|
109 |
-
|
110 |
-
|
|
|
|
|
111 |
|
112 |
-
|
113 |
-
|
114 |
-
|
115 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
116 |
});
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
117 |
|
118 |
-
|
119 |
-
|
120 |
-
|
121 |
-
|
122 |
-
|
123 |
-
const formData = new FormData();
|
124 |
-
formData.append('file', file);
|
125 |
-
|
126 |
-
try {
|
127 |
-
const response = await fetch('/upload', {
|
128 |
-
method: 'POST',
|
129 |
-
body: formData
|
130 |
-
});
|
131 |
|
132 |
-
|
133 |
-
|
134 |
-
|
135 |
-
|
136 |
-
|
137 |
-
|
138 |
-
|
139 |
-
|
140 |
-
|
|
|
|
|
|
|
141 |
});
|
142 |
-
|
143 |
-
|
144 |
-
|
145 |
-
|
146 |
-
|
147 |
-
|
148 |
-
} catch (error) {
|
149 |
-
alert(`Erreur: ${error.message}`);
|
150 |
-
}
|
151 |
}
|
152 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
153 |
</body>
|
154 |
</html>
|
|
|
1 |
<!DOCTYPE html>
|
2 |
<html lang="fr">
|
3 |
<head>
|
4 |
+
<meta charset="UTF-8">
|
5 |
+
<meta name="viewport" content="width=device-width, initial-scale=1.0">
|
6 |
+
<title>Mariam AI</title>
|
7 |
+
<!-- Intégration de Tailwind CSS -->
|
8 |
+
<script src="https://cdn.tailwindcss.com"></script>
|
9 |
+
<!-- Intégration d'Animate.css pour les animations -->
|
10 |
+
<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/animate.css/4.1.1/animate.min.css"/>
|
11 |
+
<style>
|
12 |
+
/* Loader personnalisé */
|
13 |
+
.loader {
|
14 |
+
border-top-color: #3498db;
|
15 |
+
animation: spin 1s linear infinite;
|
16 |
+
}
|
17 |
+
@keyframes spin {
|
18 |
+
to { transform: rotate(360deg); }
|
19 |
+
}
|
20 |
+
</style>
|
21 |
</head>
|
22 |
+
<body class="bg-gradient-to-r from-blue-500 to-purple-600 min-h-screen flex items-center justify-center">
|
23 |
+
<div class="bg-white rounded-xl shadow-2xl overflow-hidden w-full max-w-4xl">
|
24 |
+
<!-- En-tête -->
|
25 |
+
<header class="bg-gradient-to-r from-purple-600 to-blue-500 p-6 flex justify-between items-center">
|
26 |
+
<h1 class="text-white text-3xl font-bold">Mariam AI</h1>
|
27 |
+
<div class="flex space-x-4">
|
28 |
+
<label class="flex items-center text-white">
|
29 |
+
<input type="checkbox" id="webSearchToggle" class="mr-2">
|
30 |
+
Activer la recherche web
|
31 |
+
</label>
|
32 |
+
<button onclick="clearChat()" class="bg-red-500 hover:bg-red-600 text-white px-4 py-2 rounded transition duration-200">
|
33 |
+
Effacer le chat
|
34 |
+
</button>
|
35 |
+
</div>
|
36 |
+
</header>
|
|
|
37 |
|
38 |
+
<!-- Contenu principal -->
|
39 |
+
<main class="p-6 flex flex-col h-96">
|
40 |
+
<!-- Upload de fichier -->
|
41 |
+
<div class="mb-4 flex items-center">
|
42 |
+
<input type="file" id="fileUpload" class="hidden" accept=".jpg,.jpeg,.png,.pdf,.txt,.mp3,.mp4">
|
43 |
+
<label for="fileUpload" class="cursor-pointer bg-blue-500 hover:bg-blue-600 text-white px-4 py-2 rounded transition duration-200">
|
44 |
+
Télécharger un fichier
|
45 |
+
</label>
|
46 |
+
<span id="fileName" class="ml-2 text-gray-600"></span>
|
47 |
+
</div>
|
48 |
+
<!-- Zone des messages -->
|
49 |
+
<div id="chatMessages" class="flex-1 overflow-y-auto space-y-4 mb-4">
|
50 |
+
{% for message in messages %}
|
51 |
+
<div class="flex {% if message.role == 'user' %}justify-end{% else %}justify-start{% endif %} animate__animated animate__fadeIn">
|
52 |
+
<div class="max-w-3/4 p-3 rounded-lg {% if message.role == 'user' %}bg-blue-500 text-white{% else %}bg-gray-200 text-gray-800{% endif %}">
|
53 |
+
{{ message.content }}
|
54 |
+
</div>
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
55 |
</div>
|
56 |
+
{% endfor %}
|
57 |
+
</div>
|
58 |
+
<!-- Loader animé -->
|
59 |
+
<div id="loader" class="hidden flex justify-center my-4">
|
60 |
+
<div class="loader border-8 border-t-8 border-gray-200 rounded-full h-12 w-12"></div>
|
61 |
+
</div>
|
62 |
+
<!-- Zone de saisie -->
|
63 |
+
<div class="border-t pt-4">
|
64 |
+
<div class="flex space-x-4">
|
65 |
+
<input type="text" id="messageInput" class="flex-1 border rounded-lg px-4 py-2 focus:outline-none focus:ring-2 focus:ring-blue-500" placeholder="Écrivez votre message...">
|
66 |
+
<button onclick="sendMessage()" class="bg-blue-500 hover:bg-blue-600 text-white px-6 py-2 rounded-lg transition duration-200 transform hover:scale-105">
|
67 |
+
Envoyer
|
68 |
+
</button>
|
69 |
+
</div>
|
70 |
+
</div>
|
71 |
+
</main>
|
72 |
+
</div>
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
73 |
|
74 |
+
<!-- Scripts -->
|
75 |
+
<script src="https://cdnjs.cloudflare.com/ajax/libs/marked/4.0.2/marked.min.js"></script>
|
76 |
+
<script>
|
77 |
+
const messageInput = document.getElementById('messageInput');
|
78 |
+
const chatMessages = document.getElementById('chatMessages');
|
79 |
+
const webSearchToggle = document.getElementById('webSearchToggle');
|
80 |
+
const fileUpload = document.getElementById('fileUpload');
|
81 |
+
const fileName = document.getElementById('fileName');
|
82 |
+
const loader = document.getElementById('loader');
|
|
|
|
|
83 |
|
84 |
+
function addMessage(content, isUser = false) {
|
85 |
+
const messageDiv = document.createElement('div');
|
86 |
+
messageDiv.className = `flex ${isUser ? 'justify-end' : 'justify-start'} animate__animated animate__fadeIn`;
|
87 |
+
|
88 |
+
const innerDiv = document.createElement('div');
|
89 |
+
innerDiv.className = `max-w-3/4 p-3 rounded-lg ${isUser ? 'bg-blue-500 text-white' : 'bg-gray-200 text-gray-800'}`;
|
90 |
+
innerDiv.innerHTML = marked.parse(content);
|
91 |
+
|
92 |
+
messageDiv.appendChild(innerDiv);
|
93 |
+
chatMessages.appendChild(messageDiv);
|
94 |
+
chatMessages.scrollTop = chatMessages.scrollHeight;
|
95 |
+
}
|
96 |
|
97 |
+
async function sendMessage() {
|
98 |
+
const message = messageInput.value.trim();
|
99 |
+
if (!message) return;
|
100 |
+
|
101 |
+
addMessage(message, true);
|
102 |
+
messageInput.value = '';
|
103 |
+
|
104 |
+
loader.classList.remove('hidden'); // Afficher le loader
|
105 |
+
|
106 |
+
try {
|
107 |
+
const response = await fetch('/send_message', {
|
108 |
+
method: 'POST',
|
109 |
+
headers: { 'Content-Type': 'application/json' },
|
110 |
+
body: JSON.stringify({
|
111 |
+
message: message,
|
112 |
+
web_search: webSearchToggle.checked
|
113 |
+
})
|
114 |
});
|
115 |
+
|
116 |
+
const data = await response.json();
|
117 |
+
loader.classList.add('hidden'); // Masquer le loader
|
118 |
+
|
119 |
+
if (data.error) {
|
120 |
+
addMessage(`Erreur: ${data.error}`);
|
121 |
+
} else {
|
122 |
+
addMessage(data.response);
|
123 |
+
}
|
124 |
+
} catch (error) {
|
125 |
+
loader.classList.add('hidden');
|
126 |
+
addMessage(`Erreur: ${error.message}`);
|
127 |
+
}
|
128 |
+
}
|
129 |
|
130 |
+
messageInput.addEventListener('keypress', (e) => {
|
131 |
+
if (e.key === 'Enter') {
|
132 |
+
sendMessage();
|
133 |
+
}
|
134 |
+
});
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
135 |
|
136 |
+
fileUpload.addEventListener('change', async (e) => {
|
137 |
+
const file = e.target.files[0];
|
138 |
+
if (!file) return;
|
139 |
+
|
140 |
+
fileName.textContent = file.name;
|
141 |
+
const formData = new FormData();
|
142 |
+
formData.append('file', file);
|
143 |
+
|
144 |
+
try {
|
145 |
+
const response = await fetch('/upload', {
|
146 |
+
method: 'POST',
|
147 |
+
body: formData
|
148 |
});
|
149 |
+
|
150 |
+
const data = await response.json();
|
151 |
+
if (data.error) {
|
152 |
+
alert(`Erreur: ${data.error}`);
|
153 |
+
} else {
|
154 |
+
addMessage(`Fichier téléchargé: ${file.name}`);
|
|
|
|
|
|
|
155 |
}
|
156 |
+
} catch (error) {
|
157 |
+
alert(`Erreur: ${error.message}`);
|
158 |
+
}
|
159 |
+
});
|
160 |
+
|
161 |
+
async function clearChat() {
|
162 |
+
try {
|
163 |
+
await fetch('/clear_chat', { method: 'POST' });
|
164 |
+
chatMessages.innerHTML = '';
|
165 |
+
location.reload();
|
166 |
+
} catch (error) {
|
167 |
+
alert(`Erreur: ${error.message}`);
|
168 |
+
}
|
169 |
+
}
|
170 |
+
</script>
|
171 |
</body>
|
172 |
</html>
|