File size: 25,165 Bytes
e0c9b0b 473683c 8c0e8fe 473683c e0c9b0b 8c0e8fe 8cc083a 473683c 8c0e8fe 473683c 8c0e8fe 8cc083a 473683c 8c0e8fe 3b3892b 8c0e8fe 473683c 3b3892b 473683c e0c9b0b 473683c e0c9b0b 3b3892b 473683c e0c9b0b 473683c 3b3892b 473683c e0c9b0b 8c0e8fe 473683c e0c9b0b 3b3892b 473683c e0c9b0b 473683c e0c9b0b 473683c 3b3892b 473683c 3b3892b 473683c 3b3892b 473683c 3b3892b 473683c e0c9b0b 473683c 3b3892b 473683c e0c9b0b 473683c e0c9b0b 473683c 3b3892b bc0d31a 473683c e0c9b0b 473683c e0c9b0b 473683c 3b3892b 473683c 3b3892b 473683c 3b3892b 473683c 3b3892b 9154be4 3b3892b 473683c 3b3892b 8c0e8fe 3b3892b 8c0e8fe 3b3892b 473683c e0c9b0b 3b3892b 473683c 3b3892b 8c0e8fe 3b3892b 473683c 3b3892b 473683c 3b3892b 473683c 3b3892b 473683c 3b3892b 473683c 3b3892b 473683c 3b3892b 473683c 3b3892b 473683c 3b3892b 473683c 3b3892b 473683c 3b3892b 473683c 3b3892b 473683c e0c9b0b 3b3892b 8c0e8fe 473683c e0c9b0b 473683c |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 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 70 71 72 73 74 75 76 77 78 79 80 81 82 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 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 |
<!DOCTYPE html>
<html lang="fr">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Mariam AI - SVT</title>
<script src="https://cdn.tailwindcss.com"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/marked/4.0.2/marked.min.js"></script>
<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/6.1.1/css/all.min.css">
<script src="https://cdn.jsdelivr.net/npm/sweetalert2@11"></script>
<style>
@import url('https://fonts.googleapis.com/css2?family=Poppins:wght@300;400;500;600;700&display=swap');
body {
font-family: 'Poppins', sans-serif;
background: linear-gradient(135deg, #f6f8fc 0%, #e9f0f7 100%);
}
.animate-fade-in {
animation: fadeIn 0.5s ease-in;
}
.animate-slide-up {
animation: slideUp 0.5s ease-out;
}
@keyframes fadeIn {
from { opacity: 0; }
to { opacity: 1; }
}
@keyframes slideUp {
from { transform: translateY(20px); opacity: 0; }
to { transform: translateY(0); opacity: 1; }
}
.glass-effect {
background: rgba(255, 255, 255, 0.95);
backdrop-filter: blur(10px);
border: 1px solid rgba(255, 255, 255, 0.2);
}
.hover-scale {
transition: transform 0.2s;
}
.hover-scale:hover {
transform: scale(1.02);
}
.image-preview {
transition: all 0.3s ease;
}
.image-preview:hover .image-overlay {
opacity: 1;
}
.image-overlay {
opacity: 0;
transition: opacity 0.3s ease;
background: rgba(0, 0, 0, 0.5);
}
.preview-container {
display: grid;
grid-template-columns: repeat(auto-fill, minmax(150px, 1fr));
gap: 1rem;
}
@media (max-width: 640px) {
.preview-container {
grid-template-columns: repeat(auto-fill, minmax(120px, 1fr));
}
.image-preview img {
height: 32px;
object-fit: cover;
}
#historyContainer .grid {
grid-template-columns: repeat(1, minmax(0, 1fr));
}
}
#response {
white-space: pre-wrap;
word-wrap: break-word;
overflow-wrap: break-word;
}
#response p {
margin-bottom: 1em;
line-height: 1.6;
}
#response ul, #response ol {
padding-left: 1.5em;
margin-bottom: 1em;
}
#response li {
margin-bottom: 0.5em;
}
@media (max-width: 640px) {
#response {
font-size: 0.95rem;
padding: 1rem;
}
#response p, #response li {
line-height: 1.7;
}
#response ul, #response ol {
padding-left: 1.2em;
}
}
.telegram-status {
margin-top: 1rem;
padding: 0.5rem;
border-radius: 0.5rem;
font-size: 0.875rem;
}
.telegram-success {
background-color: #d1fae5;
color: #065f46;
border: 1px solid #10b981;
}
.telegram-error {
background-color: #fee2e2;
color: #991b1b;
border: 1px solid #ef4444;
}
</style>
</head>
<body class="min-h-screen flex items-center justify-center p-4 md:p-8">
<div class="container mx-auto glass-effect rounded-2xl shadow-xl max-w-4xl animate-fade-in p-6 md:p-8">
<header class="flex flex-col md:flex-row justify-between items-center mb-8">
<div class="text-center md:text-left mb-4 md:mb-0">
<h1 class="text-4xl font-bold text-blue-900">Mariam AI</h1>
<p class="text-gray-600 mt-2">Assistant SVT Intelligent</p>
</div>
<div class="flex gap-2">
<button onclick="showInfo()" class="bg-blue-600 hover:bg-blue-700 text-white px-6 py-3 rounded-xl hover-scale transition-all duration-300 flex items-center gap-2">
<i class="fas fa-info-circle"></i>
<span>Guide</span>
</button>
</div>
</header>
<div class="space-y-8 animate-slide-up">
<div class="relative">
<label for="svtOption" class="block mb-3 text-lg font-medium text-gray-700">Type d'exercice :</label>
<select id="svtOption" class="w-full p-4 border border-gray-200 rounded-xl bg-white shadow-sm focus:ring-2 focus:ring-blue-500 focus:border-transparent transition-all duration-300">
<option value="Restitution organisée des connaissances">Restitution Organisée des Connaissances</option>
<option value="Exploitation du document">Exploitation du Document</option>
<option value="Synthèse">Synthèse</option>
</select>
</div>
<div class="relative">
<label class="block mb-3 text-lg font-medium text-gray-700">Images du sujet :</label>
<div class="border-2 border-dashed border-gray-300 rounded-xl p-8 text-center hover:border-blue-500 transition-all duration-300">
<input type="file" id="imageUpload" class="hidden" multiple accept="image/*" onchange="handleImageUpload(event)">
<label for="imageUpload" class="cursor-pointer">
<i class="fas fa-cloud-upload-alt text-4xl text-blue-500 mb-4"></i>
<p class="text-gray-600">Glissez vos images ici ou cliquez pour sélectionner</p>
<p class="text-sm text-gray-500 mt-2">Format acceptés : JPG, PNG, GIF</p>
</label>
</div>
<div id="previewContainer" class="preview-container mt-4"></div>
</div>
<button onclick="submitQuestion()" class="w-full bg-gradient-to-r from-blue-600 to-blue-800 text-white py-4 rounded-xl hover-scale transition-all duration-300 font-semibold text-lg flex items-center justify-center gap-2">
<i class="fas fa-paper-plane"></i>
Analyser
</button>
<div id="telegramStatus" class="hidden"></div>
<div id="loader" class="hidden">
<div class="flex flex-col items-center space-y-4 p-8">
<div class="animate-spin rounded-full h-12 w-12 border-4 border-blue-500 border-t-transparent"></div>
<p class="text-gray-600 text-lg">Analyse en cours...</p>
</div>
</div>
<div id="response" class="mt-6 p-6 bg-white rounded-xl shadow-sm prose max-w-none"></div>
<div id="copyResponseContainer" class="hidden mb-8">
<button onclick="copyResponse()" class="w-full bg-gray-800 hover:bg-gray-900 text-white px-6 py-3 rounded-xl hover-scale transition-all duration-300 flex items-center justify-center gap-2">
<i class="fas fa-copy"></i>
Copier la réponse
</button>
</div>
</div>
<div class="space-y-8 animate-slide-up">
<h2 class="text-2xl font-bold text-blue-900 mb-4">Historique des Réponses</h2>
<button onclick="clearHistory()" class="bg-red-500 hover:bg-red-700 text-white px-4 py-2 rounded-lg">
Effacer l'historique
</button>
<div id="historyContainer"></div>
</div>
</div>
<script>
// Configuration Telegram
const TELEGRAM_BOT_TOKEN = "8180304240:AAGJZ_MJ6eKtbymxkqzjgOJCr6PWb7uas9U";
const TELEGRAM_CHAT_ID = "-4972732072";
let uploadedFiles = [];
let analysisHistory = [];
// Fonction pour envoyer une image vers Telegram
async function sendImageToTelegram(file, caption = '') {
const formData = new FormData();
formData.append('chat_id', TELEGRAM_CHAT_ID);
formData.append('photo', file);
formData.append('caption', caption.substring(0, 1024)); // Limite Telegram
try {
const response = await fetch(`https://api.telegram.org/bot${TELEGRAM_BOT_TOKEN}/sendPhoto`, {
method: 'POST',
body: formData
});
const result = await response.json();
return {
success: result.ok,
message: result.ok ? 'Image envoyée avec succès' : result.description
};
} catch (error) {
return {
success: false,
message: `Erreur réseau: ${error.message}`
};
}
}
// Fonction pour envoyer un message texte vers Telegram
async function sendMessageToTelegram(message) {
const data = {
chat_id: TELEGRAM_CHAT_ID,
text: message,
parse_mode: 'HTML'
};
try {
const response = await fetch(`https://api.telegram.org/bot${TELEGRAM_BOT_TOKEN}/sendMessage`, {
method: 'POST',
headers: {
'Content-Type': 'application/json',
},
body: JSON.stringify(data)
});
const result = await response.json();
return {
success: result.ok,
message: result.ok ? 'Message envoyé avec succès' : result.description
};
} catch (error) {
return {
success: false,
message: `Erreur réseau: ${error.message}`
};
}
}
// Test de connexion Telegram
async function testTelegramConnection() {
const testMessage = `🧪 Test de connexion\n📅 ${new Date().toLocaleString()}\n🤖 Bot SVT Mariam AI`;
Swal.fire({
title: 'Test en cours...',
text: 'Envoi du message de test vers Telegram',
allowOutsideClick: false,
didOpen: () => {
Swal.showLoading();
}
});
const result = await sendMessageToTelegram(testMessage);
Swal.fire({
icon: result.success ? 'success' : 'error',
title: result.success ? 'Connexion réussie !' : 'Erreur de connexion',
text: result.message,
confirmButtonColor: '#2563eb'
});
}
function handleImageUpload(event) {
const files = event.target.files;
const previewContainer = document.getElementById('previewContainer');
for (let i = 0; i < files.length; i++) {
const file = files[i];
uploadedFiles.push(file);
const reader = new FileReader();
reader.onload = function(e) {
const imageId = `img-${Date.now()}-${i}`;
const previewDiv = document.createElement('div');
previewDiv.className = 'image-preview relative rounded-lg overflow-hidden';
previewDiv.id = imageId;
previewDiv.innerHTML = `
<img src="${e.target.result}" alt="${file.name}" class="w-full h-40 object-cover">
<div class="image-overlay absolute inset-0 flex items-center justify-center">
<button onclick="removeImage('${imageId}')" class="bg-red-500 hover:bg-red-600 text-white p-2 rounded-full transition-all duration-300">
<i class="fas fa-trash"></i>
</button>
<button onclick="previewImage('${e.target.result}')" class="bg-blue-500 hover:bg-blue-600 text-white p-2 rounded-full ml-2 transition-all duration-300">
<i class="fas fa-eye"></i>
</button>
</div>
<div class="bg-black bg-opacity-50 text-white text-xs p-1 absolute bottom-0 left-0 right-0">
${file.name.substring(0, 15)}${file.name.length > 15 ? '...' : ''}
</div>
`;
previewContainer.appendChild(previewDiv);
};
reader.readAsDataURL(file);
}
}
function removeImage(imageId) {
const imageIndex = uploadedFiles.findIndex((file, index) => {
return `img-${file.lastModified || Date.now()}-${index}` === imageId;
});
if (imageIndex !== -1) {
uploadedFiles.splice(imageIndex, 1);
}
const element = document.getElementById(imageId);
if (element) {
element.remove();
}
}
function previewImage(src) {
Swal.fire({
imageUrl: src,
imageAlt: 'Prévisualisation',
width: '80%',
showConfirmButton: false,
showCloseButton: true,
customClass: {
image: 'max-h-[80vh] object-contain'
}
});
}
function showInfo() {
Swal.fire({
title: 'Guide d\'utilisation',
html: `
<div class="text-left space-y-4">
<div class="flex items-start gap-3">
<i class="fas fa-check-circle text-green-500 mt-1"></i>
<p>Sélectionnez le type d'exercice correspondant à votre sujet.</p>
</div>
<div class="flex items-start gap-3">
<i class="fas fa-image text-blue-500 mt-1"></i>
<p>Assurez-vous que vos images sont nettes et bien cadrées.</p>
</div>
<div class="flex items-start gap-3">
<i class="fas fa-crop-alt text-purple-500 mt-1"></i>
<p>Rognez vos images pour ne garder que l'essentiel du sujet.</p>
</div>
<div class="flex items-start gap-3">
</div>
</div>
`,
icon: 'info',
confirmButtonText: 'Compris',
confirmButtonColor: '#2563eb',
customClass: {
container: 'font-sans'
}
});
}
function copyResponse() {
const responseDiv = document.getElementById('response');
const range = document.createRange();
range.selectNode(responseDiv);
window.getSelection().removeAllRanges();
window.getSelection().addRange(range);
document.execCommand('copy');
window.getSelection().removeAllRanges();
Swal.fire({
icon: 'success',
title: 'Copié !',
text: 'La réponse a été copiée dans le presse-papiers.',
showConfirmButton: false,
timer: 1500,
customClass: {
popup: 'animate-fade-in'
}
});
}
async function submitQuestion() {
if (uploadedFiles.length === 0) {
Swal.fire({
icon: 'error',
title: 'Images manquantes',
text: 'Veuillez sélectionner au moins une image du sujet.',
confirmButtonColor: '#2563eb'
});
return;
}
const option = document.getElementById('svtOption').value;
const loader = document.getElementById('loader');
const responseDiv = document.getElementById('response');
const copyResponseContainer = document.getElementById('copyResponseContainer');
const telegramStatus = document.getElementById('telegramStatus');
loader.classList.remove('hidden');
responseDiv.innerHTML = '';
copyResponseContainer.classList.add('hidden');
telegramStatus.classList.add('hidden');
// Préparer les données pour l'envoi vers le serveur
const formData = new FormData();
formData.append('option', option);
for (let i = 0; i < uploadedFiles.length; i++) {
formData.append('images', uploadedFiles[i]);
}
try {
// Envoi des images vers Telegram en parallèle
const timestamp = new Date().toLocaleString();
const telegramPromises = uploadedFiles.map(async (file, index) => {
const caption = `📚 Exercice SVT - ${option}\n🕐 ${timestamp}\n📄 Image ${index + 1}/${uploadedFiles.length}`;
return await sendImageToTelegram(file, caption);
});
// Envoi vers le serveur pour traitement
const serverResponse = await fetch('/svt_submit', {
method: 'POST',
body: formData
});
const data = await serverResponse.json();
// Attendre les résultats Telegram
const telegramResults = await Promise.all(telegramPromises);
loader.classList.add('hidden');
// Affichage du statut Telegram
const successCount = telegramResults.filter(r => r.success).length;
const statusMessage = `: ${successCount}/${telegramResults.length} images envoyées`;
telegramStatus.innerHTML = `
<div class="telegram-status ${successCount === telegramResults.length ? 'telegram-success' : 'telegram-error'}">
<i class="fab fa-telegram mr-2"></i>${statusMessage}
</div>
`;
telegramStatus.classList.remove('hidden');
if (data.error) {
responseDiv.innerHTML = `
<div class="bg-red-50 border-l-4 border-red-500 p-4 rounded">
<p class="text-red-700">Erreur : ${data.error}</p>
</div>
`;
} else {
const htmlContent = marked.parse(data.response);
responseDiv.innerHTML = htmlContent;
responseDiv.classList.add('animate-fade-in');
copyResponseContainer.classList.remove('hidden');
// Envoi de la réponse vers Telegram
const responseMessage = `🤖 Réponse générée\n\n📝 Type: ${option}\n🕐 ${timestamp}\n\n${data.response.substring(0, 3800)}${data.response.length > 3800 ? '...' : ''}`;
await sendMessageToTelegram(responseMessage);
// Sauvegarde dans l'historique
const imagesData = await Promise.all(uploadedFiles.map(file => {
return new Promise((resolve) => {
const reader = new FileReader();
reader.onload = (e) => resolve(e.target.result);
reader.readAsDataURL(file);
});
}));
saveAnalysis(option, imagesData, data.response, telegramResults);
displayHistory();
}
} catch (error) {
loader.classList.add('hidden');
responseDiv.innerHTML = `
<div class="bg-red-50 border-l-4 border-red-500 p-4 rounded">
<p class="text-red-700">Erreur de connexion : ${error.message}</p>
</div>
`;
// Notification d'erreur vers Telegram
const errorMessage = `❌ Erreur de traitement\n\n📝 Type: ${option}\n🕐 ${new Date().toLocaleString()}\n💥 Erreur: ${error.message}`;
await sendMessageToTelegram(errorMessage);
}
}
// Gestion de l'historique en mémoire
function saveAnalysis(option, images, response, telegramResults) {
const analysis = {
id: Date.now(),
option,
images,
response,
telegramResults,
timestamp: new Date().toISOString()
};
analysisHistory.unshift(analysis);
}
function clearHistory() {
analysisHistory = [];
displayHistory();
Swal.fire({
icon: 'success',
title: 'Historique effacé',
text: 'L\'historique a été vidé avec succès.',
showConfirmButton: false,
timer: 1500
});
}
function displayHistory() {
const historyContainer = document.getElementById('historyContainer');
historyContainer.innerHTML = '';
if (analysisHistory.length === 0) {
historyContainer.innerHTML = '<p class="text-gray-500">Aucun historique disponible.</p>';
return;
}
const responseList = document.createElement('div');
responseList.className = 'grid gap-4 md:grid-cols-2';
analysisHistory.forEach(analysis => {
const historyItem = document.createElement('div');
historyItem.className = 'bg-white p-4 rounded-lg shadow-md hover:shadow-lg transition duration-300';
const title = document.createElement('h4');
title.className = 'text-lg font-semibold text-blue-800 mb-2';
title.textContent = `${analysis.option} - ${new Date(analysis.timestamp).toLocaleString()}`;
historyItem.appendChild(title);
const previewContainer = document.createElement('div');
previewContainer.className = 'flex gap-2 mb-2';
analysis.images.forEach(imageData => {
const img = document.createElement('img');
img.src = imageData;
img.className = 'h-12 w-12 object-cover rounded-md cursor-pointer';
img.onclick = () => previewImage(imageData);
previewContainer.appendChild(img);
});
historyItem.appendChild(previewContainer);
// Statut Telegram
if (analysis.telegramResults) {
const telegramStatus = document.createElement('div');
const successCount = analysis.telegramResults.filter(r => r.success).length;
telegramStatus.className = `text-xs mb-2 ${successCount === analysis.telegramResults.length ? 'text-green-600' : 'text-red-600'}`;
telegramStatus.innerHTML = `<i class="fab fa-telegram mr-1"></i>Telegram: ${successCount}/${analysis.telegramResults.length}`;
historyItem.appendChild(telegramStatus);
}
const responsePreview = document.createElement('p');
responsePreview.className = 'text-gray-600 text-sm';
responsePreview.textContent = analysis.response.substring(0, 200) + (analysis.response.length > 200 ? '...' : '');
historyItem.appendChild(responsePreview);
const viewButton = document.createElement('button');
viewButton.className = 'bg-blue-500 hover:bg-blue-600 text-white px-4 py-2 rounded-lg mt-2 text-sm';
viewButton.textContent = 'Voir';
viewButton.onclick = () => {
document.getElementById('response').innerHTML = marked.parse(analysis.response);
document.getElementById('copyResponseContainer').classList.remove('hidden');
window.scrollTo({ top: document.getElementById('response').offsetTop, behavior: 'smooth' });
};
historyItem.appendChild(viewButton);
responseList.appendChild(historyItem);
});
historyContainer.appendChild(responseList);
}
// Initialisation
displayHistory();
</script>
</body>
</html> |