|
<!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: 32 object-cover; |
|
} |
|
#historyContainer .grid { |
|
grid-template-columns: repeat(1, minmax(0, 1fr)); |
|
} |
|
} |
|
|
|
</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> |
|
<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 d'utilisation</span> |
|
</button> |
|
</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="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="clearLocalStorage()" 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> |
|
let uploadedFiles = []; |
|
|
|
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 => { |
|
const fileId = `img-${file.lastModified}-${uploadedFiles.indexOf(file)}`; |
|
return fileId === 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> |
|
`, |
|
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'); |
|
|
|
loader.classList.remove('hidden'); |
|
responseDiv.innerHTML = ''; |
|
copyResponseContainer.classList.add('hidden'); |
|
|
|
const formData = new FormData(); |
|
formData.append('option', option); |
|
|
|
for (let i = 0; i < uploadedFiles.length; i++) { |
|
formData.append('images', uploadedFiles[i]); |
|
} |
|
|
|
const response = await fetch('/svt_submit', { |
|
method: 'POST', |
|
body: formData |
|
}); |
|
|
|
const data = await response.json(); |
|
loader.classList.add('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'); |
|
|
|
|
|
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); |
|
}); |
|
})); |
|
|
|
saveResponseToLocalStorage(option, imagesData, data.response); |
|
displayHistory(); |
|
} |
|
} |
|
|
|
|
|
function saveResponseToLocalStorage(option, images, response) { |
|
const timestamp = new Date().toISOString(); |
|
const data = { option, images, response, timestamp }; |
|
localStorage.setItem('svt_response_' + timestamp, JSON.stringify(data)); |
|
} |
|
|
|
function loadResponsesFromLocalStorage() { |
|
const responses = []; |
|
for (let i = 0; i < localStorage.length; i++) { |
|
const key = localStorage.key(i); |
|
if (key.startsWith('svt_response_')) { |
|
const data = JSON.parse(localStorage.getItem(key)); |
|
responses.push(data); |
|
} |
|
} |
|
return responses.sort((a, b) => new Date(b.timestamp) - new Date(a.timestamp)); |
|
} |
|
|
|
function clearLocalStorage() { |
|
const keysToRemove = []; |
|
for (let i = 0; i < localStorage.length; i++) { |
|
const key = localStorage.key(i); |
|
if (key.startsWith('svt_response_')) { |
|
keysToRemove.push(key); |
|
} |
|
} |
|
for (const key of keysToRemove) { |
|
localStorage.removeItem(key); |
|
} |
|
displayHistory(); |
|
} |
|
|
|
function displayHistory() { |
|
const responses = loadResponsesFromLocalStorage(); |
|
const historyContainer = document.getElementById('historyContainer'); |
|
historyContainer.innerHTML = ''; |
|
|
|
if (responses.length === 0) { |
|
historyContainer.innerHTML = '<p class="text-gray-500">Aucun historique disponible.</p>'; |
|
return; |
|
} |
|
|
|
const responseList = document.createElement('ul'); |
|
responseList.className = 'grid gap-4 md:grid-cols-2'; |
|
|
|
responses.forEach(response => { |
|
const listItem = document.createElement('li'); |
|
listItem.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 = `${response.option} - ${new Date(response.timestamp).toLocaleString()}`; |
|
listItem.appendChild(title); |
|
|
|
const previewContainer = document.createElement('div'); |
|
previewContainer.className = 'flex gap-2 mb-2'; |
|
response.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); |
|
}); |
|
listItem.appendChild(previewContainer); |
|
|
|
const responsePreview = document.createElement('p'); |
|
responsePreview.className = 'text-gray-600 text-sm'; |
|
responsePreview.textContent = response.response.substring(0, 200) + (response.response.length > 200 ? '...' : ''); |
|
listItem.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(response.response); |
|
document.getElementById('copyResponseContainer').classList.remove('hidden'); |
|
window.scrollTo({ top: document.getElementById('response').offsetTop, behavior: 'smooth' }); |
|
}; |
|
listItem.appendChild(viewButton); |
|
|
|
responseList.appendChild(listItem); |
|
}); |
|
|
|
historyContainer.appendChild(responseList); |
|
} |
|
|
|
displayHistory(); |
|
</script> |
|
</body> |
|
</html> |