Spaces:
Sleeping
Sleeping
| <html lang="fr"> | |
| <head> | |
| <meta charset="UTF-8"> | |
| <meta name="viewport" content="width=device-width, initial-scale=1.0"> | |
| <title>Mariam | Solution Mathématique</title> | |
| <!-- Tailwind CSS --> | |
| <link href="https://cdn.jsdelivr.net/npm/[email protected]/dist/tailwind.min.css" rel="stylesheet"> | |
| <!-- Configuration MathJax --> | |
| <script> | |
| window.MathJax = { | |
| tex: { | |
| inlineMath: [['$', '$']], | |
| displayMath: [['$$', '$$']], | |
| processEscapes: true, | |
| packages: {'[+]': ['autoload','ams']} | |
| }, | |
| options: { | |
| enableMenu: false, | |
| messageStyle: 'none' | |
| }, | |
| startup: { | |
| pageReady: () => { | |
| console.log('MathJax est complètement chargé.'); | |
| window.mathJaxReady = true; | |
| } | |
| } | |
| }; | |
| </script> | |
| <script src="https://cdn.jsdelivr.net/npm/mathjax@3/es5/tex-mml-chtml.js" id="MathJax-script" async></script> | |
| <!-- Marked.js - Toujours inclus au cas où il serait utilisé pour thoughtsContent --> | |
| <script src="https://cdn.jsdelivr.net/npm/marked/lib/marked.umd.min.js"></script> | |
| <style> | |
| @import url('https://fonts.googleapis.com/css2?family=Space+Grotesk:wght@400;700&display=swap'); | |
| body { | |
| font-family: 'Space Grotesk', sans-serif; | |
| } | |
| .uploadArea { | |
| background: #f3f4f6; | |
| border: 2px dashed #d1d5db; | |
| transition: border-color 0.2s ease; | |
| } | |
| .uploadArea:hover { | |
| border-color: #3b82f6; | |
| } | |
| .blue-button { | |
| background: #3b82f6; | |
| transition: background-color 0.2s ease; | |
| } | |
| .blue-button:hover { | |
| background: #2563eb; | |
| } | |
| /* Suppression du style du bouton de téléchargement */ | |
| .loader { | |
| width: 48px; | |
| height: 48px; | |
| border: 3px solid #3b82f6; | |
| border-bottom-color: transparent; | |
| border-radius: 50%; | |
| display: inline-block; | |
| animation: rotation 1s linear infinite; | |
| } | |
| @keyframes rotation { | |
| 0% { transform: rotate(0deg); } | |
| 100% { transform: rotate(360deg); } | |
| } | |
| .thought-box { | |
| transition: max-height 0.3s ease-out; | |
| max-height: 0; | |
| overflow: hidden; | |
| } | |
| .thought-box.open { | |
| max-height: 500px; /* Ajusté si nécessaire */ | |
| } | |
| #thoughtsContent, #answerContent { | |
| max-height: 500px; | |
| overflow-y: auto; | |
| scroll-behavior: smooth; | |
| white-space: pre-wrap; /* Important pour préserver les espaces/retours ligne du LaTeX brut */ | |
| } | |
| .preview-image { | |
| max-width: 300px; | |
| max-height: 300px; | |
| object-fit: contain; | |
| } | |
| .timestamp { | |
| color: #3b82f6; | |
| font-size: 0.9em; | |
| margin-left: 8px; | |
| } | |
| /* Styles pour les tables générées par MathJax/Markdown si nécessaire */ | |
| table { | |
| border-collapse: collapse; | |
| width: 100%; | |
| margin-bottom: 1rem; | |
| border: 1px solid #d1d5db; /* Ajout bordure table */ | |
| } | |
| th, td { | |
| border: 1px solid #d1d5db; | |
| padding: 0.5rem; | |
| text-align: left; | |
| } | |
| th { | |
| background-color: #f3f4f6; | |
| font-weight: 600; | |
| } | |
| .table-responsive { | |
| overflow-x: auto; | |
| } | |
| /* Suppression du style pour l'impression */ | |
| .performance-warning { | |
| color: red; | |
| font-weight: bold; | |
| font-size: 1.2em; | |
| margin-top: 10px; | |
| margin-bottom: 25px; | |
| text-align: center; | |
| } | |
| </style> | |
| </head> | |
| <body class="p-4"> | |
| <div class="max-w-4xl mx-auto"> | |
| <header class="p-6 text-center mb-8"> | |
| <h1 class="text-4xl font-bold text-blue-600">Mariam - M-0</h1> | |
| <p class="text-gray-600">Solution Mathématique/Physique/Chimie Intelligente</p> | |
| <p class="performance-warning"> | |
| Vous utilisez actuellement les modèles/performances moyens. Accédez à des performances supérieures avec un abonnement premium ! | |
| </p> | |
| </header> | |
| <main> | |
| <form id="problemForm" class="space-y-6" novalidate> | |
| <div class="uploadArea p-8 text-center relative" aria-label="Zone de dépôt d'image"> | |
| <input type="file" id="imageInput" accept="image/*" class="absolute inset-0 w-full h-full opacity-0 cursor-pointer" aria-label="Choisir une image"> | |
| <div class="space-y-3"> | |
| <div class="w-16 h-16 mx-auto border-2 border-blue-400 rounded-full flex items-center justify-center"> | |
| <svg class="w-8 h-8 text-blue-400" fill="none" stroke="currentColor" viewBox="0 0 24 24" aria-hidden="true"> | |
| <path stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="M4 16l4.586-4.586a2 2 0 012.828 0L16 16m-2-2l1.586-1.586a2 2 0 012.828 0L20 14m-6-6h.01M6 20h12a2 2 0 002-2V6a2 2 0 00-2-2H6a2 2 0 00-2 2v12a2 2 0 002 2z" /> | |
| </svg> | |
| </div> | |
| <p class="text-gray-700 font-medium">Déposez votre image ici</p> | |
| <p class="text-gray-500 text-sm">ou cliquez pour sélectionner</p> | |
| </div> | |
| </div> | |
| <div id="imagePreview" class="hidden text-center"> | |
| <img id="previewImage" class="preview-image mx-auto" alt="Prévisualisation de l'image sélectionnée"> | |
| </div> | |
| <button type="submit" class="blue-button w-full py-3 text-white font-medium rounded-lg"> | |
| Résoudre le problème | |
| </button> | |
| </form> | |
| <div id="loader" class="hidden mt-8 text-center"> | |
| <span class="loader"></span> | |
| <p class="mt-4 text-gray-600">Analyse en cours...</p> | |
| </div> | |
| <section id="solution" class="hidden mt-8 space-y-6"> | |
| <div class="border-t pt-4"> | |
| <button id="thoughtsToggle" type="button" class="w-full flex justify-between items-center p-2"> | |
| <span class="font-medium text-gray-700">Processus de Réflexion</span> | |
| <span id="timestamp" class="timestamp"></span> | |
| </button> | |
| <div id="thoughtsBox" class="thought-box"> | |
| <div id="thoughtsContent" class="p-4 text-gray-600"></div> | |
| </div> | |
| </div> | |
| <div class="border-t pt-6"> | |
| <div class="flex justify-between items-center mb-4"> | |
| <h3 class="text-xl font-bold text-gray-800">Solution</h3> | |
| <!-- Suppression du bouton de téléchargement --> | |
| </div> | |
| <div id="answerContent" class="text-gray-700 table-responsive"></div> | |
| </div> | |
| </section> | |
| </main> | |
| </div> | |
| <script> | |
| document.addEventListener('DOMContentLoaded', () => { | |
| const form = document.getElementById('problemForm'); | |
| const imageInput = document.getElementById('imageInput'); | |
| const loader = document.getElementById('loader'); | |
| const solutionSection = document.getElementById('solution'); | |
| const thoughtsContent = document.getElementById('thoughtsContent'); | |
| const answerContent = document.getElementById('answerContent'); | |
| const thoughtsToggle = document.getElementById('thoughtsToggle'); | |
| const thoughtsBox = document.getElementById('thoughtsBox'); | |
| const imagePreview = document.getElementById('imagePreview'); | |
| const previewImage = document.getElementById('previewImage'); | |
| const timestamp = document.getElementById('timestamp'); | |
| let startTime = null; | |
| let timerInterval = null; | |
| let thoughtsBuffer = ''; | |
| let answerBuffer = ''; | |
| let currentMode = null; | |
| let updateTimeout = null; | |
| // Suppression de la fonction generatePDF et de son appel | |
| const updateTimestamp = () => { | |
| if (startTime) { | |
| const seconds = Math.floor((Date.now() - startTime) / 1000); | |
| timestamp.textContent = `${seconds}s`; | |
| } | |
| }; | |
| const startTimer = () => { | |
| startTime = Date.now(); | |
| timerInterval = setInterval(updateTimestamp, 1000); | |
| updateTimestamp(); | |
| }; | |
| const stopTimer = () => { | |
| clearInterval(timerInterval); | |
| startTime = null; | |
| // Ne pas effacer le timestamp final | |
| // timestamp.textContent = ''; | |
| }; | |
| const handleFileSelect = file => { | |
| if (!file) return; | |
| const reader = new FileReader(); | |
| reader.onload = e => { | |
| previewImage.src = e.target.result; | |
| imagePreview.classList.remove('hidden'); | |
| }; | |
| reader.readAsDataURL(file); | |
| }; | |
| thoughtsToggle.addEventListener('click', () => { | |
| thoughtsBox.classList.toggle('open'); | |
| }); | |
| imageInput.addEventListener('change', e => handleFileSelect(e.target.files[0])); | |
| const dropZone = document.querySelector('.uploadArea'); | |
| dropZone.addEventListener('dragover', e => { | |
| e.preventDefault(); | |
| dropZone.classList.add('border-blue-400'); | |
| }); | |
| dropZone.addEventListener('dragleave', e => { | |
| e.preventDefault(); | |
| dropZone.classList.remove('border-blue-400'); | |
| }); | |
| dropZone.addEventListener('drop', e => { | |
| e.preventDefault(); | |
| dropZone.classList.remove('border-blue-400'); | |
| handleFileSelect(e.dataTransfer.files[0]); | |
| }); | |
| // --- Déclaration de typesetContentIfReady --- | |
| const typesetContentIfReady = async () => { | |
| if (window.mathJaxReady && typeof MathJax !== 'undefined' && MathJax.typesetPromise) { | |
| // Cible les deux conteneurs si nécessaire, ou juste answerContent si seul lui contient du LaTeX | |
| // Pour être sûr, on peut cibler la section solution entière ou des éléments spécifiques. | |
| // Ici, on cible explicitement answerContent comme dans le code original. | |
| // Si thoughtsContent peut aussi avoir du MathJax, ajoutez-le au tableau. | |
| // MathJax.startup.document.elements = [answerContent, thoughtsContent]; | |
| MathJax.startup.document.elements = [answerContent]; // Cible uniquement answerContent | |
| try { | |
| await MathJax.typesetPromise(); | |
| // Fait défiler vers le bas après le rendu MathJax | |
| answerContent.scrollTop = answerContent.scrollHeight; | |
| // Si thoughtsContent est aussi traité: | |
| // thoughtsContent.scrollTop = thoughtsContent.scrollHeight; | |
| } catch (error) { | |
| console.error("Erreur pendant MathJax typesetPromise:", error); | |
| } | |
| } else { | |
| console.log('MathJax pas prêt, report du rendu...'); | |
| setTimeout(typesetContentIfReady, 200); // Réessayer | |
| } | |
| }; | |
| // --- Déclaration de updateDisplay --- | |
| const updateDisplay = async () => { | |
| // Utilise Marked pour thoughtsContent (supposant qu'il contient du Markdown) | |
| if (typeof marked !== 'undefined') { | |
| thoughtsContent.innerHTML = marked.parse(thoughtsBuffer); | |
| } else { | |
| thoughtsContent.textContent = thoughtsBuffer; // Fallback si Marked n'est pas chargé | |
| } | |
| // **CORRECTION:** Insère le contenu brut dans answerContent, sans passer par Marked | |
| answerContent.innerHTML = answerBuffer; | |
| // Déclenche le rendu MathJax sur le contenu mis à jour | |
| await typesetContentIfReady(); | |
| // Scrolling (peut être redondant si fait dans typesetContentIfReady) | |
| thoughtsContent.scrollTop = thoughtsContent.scrollHeight; | |
| // answerContent.scrollTop = answerContent.scrollHeight; // Déplacé dans typesetContentIfReady | |
| updateTimeout = null; | |
| }; | |
| const scheduleUpdate = () => { | |
| if (updateTimeout) return; | |
| // Délai légèrement augmenté pour laisser le temps au DOM de se mettre à jour avant MathJax | |
| updateTimeout = setTimeout(updateDisplay, 250); | |
| }; | |
| // Configure Marked (si utilisé pour thoughtsContent) | |
| if (typeof marked !== 'undefined') { | |
| marked.setOptions({ | |
| gfm: true, | |
| breaks: true | |
| }); | |
| } | |
| form.addEventListener('submit', async e => { | |
| e.preventDefault(); | |
| const file = imageInput.files[0]; | |
| if (!file) { | |
| alert('Veuillez sélectionner une image.'); | |
| return; | |
| } | |
| startTimer(); | |
| loader.classList.remove('hidden'); | |
| solutionSection.classList.add('hidden'); | |
| thoughtsContent.innerHTML = ''; | |
| answerContent.innerHTML = ''; | |
| thoughtsBuffer = ''; | |
| answerBuffer = ''; | |
| currentMode = null; | |
| thoughtsBox.classList.add('open'); // Ouvre par défaut | |
| const formData = new FormData(); | |
| formData.append('image', file); | |
| try { | |
| const response = await fetch('/solved', { | |
| method: 'POST', | |
| body: formData | |
| }); | |
| if (!response.ok) { | |
| throw new Error(`Erreur HTTP: ${response.status} ${response.statusText}`); | |
| } | |
| if (!response.body) { | |
| throw new Error("La réponse ne contient pas de corps."); | |
| } | |
| const reader = response.body.getReader(); | |
| const decoder = new TextDecoder(); | |
| let buffer = ''; | |
| let firstChunkReceived = false; // Pour afficher la section dès réception | |
| const processChunk = async ({ done, value }) => { | |
| if (done) { | |
| // Traiter le reste du buffer s'il y en a | |
| if (buffer && buffer.startsWith('data:')) { | |
| try { | |
| const data = JSON.parse(buffer.slice(5)); | |
| if (data.content) { | |
| if (currentMode === 'thinking') { | |
| thoughtsBuffer += data.content; | |
| } else if (currentMode === 'answering') { | |
| answerBuffer += data.content; | |
| } | |
| } | |
| } catch(jsonError){ | |
| console.error("Erreur JSON dans le buffer final:", jsonError, "Buffer:", buffer); | |
| } | |
| } | |
| // Assurer une dernière mise à jour après la fin du stream | |
| await updateDisplay(); | |
| stopTimer(); // Arrêter le timer à la fin | |
| console.log("Stream terminé."); | |
| return true; // Indique que le stream est terminé | |
| } | |
| buffer += decoder.decode(value, { stream: true }); | |
| const lines = buffer.split('\n\n'); | |
| buffer = lines.pop() || ''; // Garde la partie incomplète pour le prochain chunk | |
| for (const line of lines) { | |
| if (!line.startsWith('data:')) continue; | |
| try { | |
| const data = JSON.parse(line.slice(5)); | |
| if (data.mode) { | |
| currentMode = data.mode; | |
| // Afficher la section dès la première donnée reçue après le début du mode | |
| if (!firstChunkReceived) { | |
| loader.classList.add('hidden'); | |
| solutionSection.classList.remove('hidden'); | |
| firstChunkReceived = true; | |
| } | |
| } | |
| if (data.content) { | |
| if (currentMode === 'thinking') { | |
| thoughtsBuffer += data.content; | |
| } else if (currentMode === 'answering') { | |
| answerBuffer += data.content; | |
| } | |
| // Mise à jour programmée pour éviter trop d'appels DOM/MathJax | |
| scheduleUpdate(); | |
| } | |
| } catch(jsonError) { | |
| console.error("Erreur JSON dans le stream:", jsonError, "Ligne:", line); | |
| // Continuer avec les lignes suivantes si possible | |
| } | |
| } | |
| return false; // Indique que le stream n'est pas terminé | |
| }; | |
| // Boucle de lecture du stream | |
| let streamFinished = false; | |
| while (!streamFinished) { | |
| const { done, value } = await reader.read(); | |
| streamFinished = await processChunk({ done, value }); | |
| } | |
| } catch (error) { | |
| console.error('Erreur lors de la récupération ou du traitement:', error); | |
| alert(`Une erreur est survenue: ${error.message}`); | |
| loader.classList.add('hidden'); | |
| solutionSection.classList.add('hidden'); // Cacher si erreur | |
| stopTimer(); | |
| } | |
| }); | |
| }); | |
| </script> | |
| </body> | |
| </html> |