Update templates/index.html
Browse files- templates/index.html +138 -156
templates/index.html
CHANGED
|
@@ -1,172 +1,154 @@
|
|
| 1 |
<!DOCTYPE html>
|
| 2 |
<html lang="fr">
|
| 3 |
<head>
|
| 4 |
-
|
| 5 |
-
|
| 6 |
-
|
| 7 |
-
|
| 8 |
-
|
| 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-
|
| 23 |
-
|
| 24 |
-
|
| 25 |
-
|
| 26 |
-
|
| 27 |
-
|
| 28 |
-
|
| 29 |
-
|
| 30 |
-
|
| 31 |
-
|
| 32 |
-
|
| 33 |
-
|
| 34 |
-
|
| 35 |
-
|
| 36 |
-
|
|
|
|
| 37 |
|
| 38 |
-
|
| 39 |
-
|
| 40 |
-
|
| 41 |
-
|
| 42 |
-
|
| 43 |
-
|
| 44 |
-
|
| 45 |
-
|
| 46 |
-
|
| 47 |
-
|
| 48 |
-
|
| 49 |
-
|
| 50 |
-
|
| 51 |
-
|
| 52 |
-
|
| 53 |
-
|
| 54 |
-
|
| 55 |
-
|
| 56 |
-
|
| 57 |
-
|
| 58 |
-
|
| 59 |
-
|
| 60 |
-
|
| 61 |
-
|
| 62 |
-
|
| 63 |
-
|
| 64 |
-
|
| 65 |
-
|
| 66 |
-
|
| 67 |
-
|
| 68 |
-
|
|
|
|
| 69 |
</div>
|
| 70 |
-
|
| 71 |
-
</main>
|
| 72 |
-
</div>
|
| 73 |
|
| 74 |
-
|
| 75 |
-
|
| 76 |
-
|
| 77 |
-
|
| 78 |
-
|
| 79 |
-
|
| 80 |
-
const fileUpload = document.getElementById('fileUpload');
|
| 81 |
-
const fileName = document.getElementById('fileName');
|
| 82 |
-
const loader = document.getElementById('loader');
|
| 83 |
|
| 84 |
-
|
| 85 |
-
|
| 86 |
-
|
| 87 |
-
|
| 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 |
}
|
| 124 |
-
} catch (error) {
|
| 125 |
-
loader.classList.add('hidden');
|
| 126 |
-
addMessage(`Erreur: ${error.message}`);
|
| 127 |
-
}
|
| 128 |
-
}
|
| 129 |
|
| 130 |
-
|
| 131 |
-
|
| 132 |
-
|
| 133 |
-
|
| 134 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 135 |
|
| 136 |
-
|
| 137 |
-
|
| 138 |
-
|
| 139 |
-
|
| 140 |
-
|
| 141 |
-
|
| 142 |
-
|
| 143 |
-
|
| 144 |
-
|
| 145 |
-
|
| 146 |
-
|
| 147 |
-
|
|
|
|
|
|
|
|
|
|
| 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 |
-
|
| 162 |
-
|
| 163 |
-
|
| 164 |
-
|
| 165 |
-
|
| 166 |
-
|
| 167 |
-
|
| 168 |
-
|
| 169 |
-
|
| 170 |
-
|
| 171 |
</body>
|
| 172 |
</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 |
+
<link href="https://cdnjs.cloudflare.com/ajax/libs/tailwindcss/2.2.19/tailwind.min.css" rel="stylesheet">
|
| 8 |
+
<script src="https://cdnjs.cloudflare.com/ajax/libs/marked/4.0.2/marked.min.js"></script>
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 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');
|
| 71 |
+
messageDiv.className = `flex ${isUser ? 'justify-end' : ''}`;
|
| 72 |
+
|
| 73 |
+
const innerDiv = document.createElement('div');
|
| 74 |
+
innerDiv.className = `max-w-3/4 p-3 rounded-lg ${isUser ? 'bg-blue-500 text-white' : 'bg-gray-200'}`;
|
| 75 |
+
innerDiv.innerHTML = marked.parse(content);
|
| 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 |
+
try {
|
| 90 |
+
const response = await fetch('/send_message', {
|
| 91 |
+
method: 'POST',
|
| 92 |
+
headers: {
|
| 93 |
+
'Content-Type': 'application/json'
|
| 94 |
+
},
|
| 95 |
+
body: JSON.stringify({
|
| 96 |
+
message: message,
|
| 97 |
+
web_search: webSearchToggle.checked
|
| 98 |
+
})
|
| 99 |
+
});
|
| 100 |
+
|
| 101 |
+
const data = await response.json();
|
| 102 |
+
if (data.error) {
|
| 103 |
+
addMessage(`Erreur: ${data.error}`);
|
| 104 |
+
} else {
|
| 105 |
+
addMessage(data.response);
|
| 106 |
+
}
|
| 107 |
+
} catch (error) {
|
| 108 |
+
addMessage(`Erreur: ${error.message}`);
|
| 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;
|
| 121 |
+
|
| 122 |
+
fileName.textContent = file.name;
|
| 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 |
+
const data = await response.json();
|
| 133 |
+
if (data.error) {
|
| 134 |
+
alert(`Erreur: ${data.error}`);
|
| 135 |
+
} else {
|
| 136 |
+
addMessage(`Fichier téléchargé: ${file.name}`);
|
| 137 |
+
}
|
| 138 |
+
} catch (error) {
|
| 139 |
+
alert(`Erreur: ${error.message}`);
|
| 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>
|