const dropArea = document.querySelector(".drag-image"); const dragText = dropArea.querySelector("h6"); const button = dropArea.querySelector("button"); const input = dropArea.querySelector("input"); const form = document.querySelector("form"); const ocrResult = document.getElementById("ocr-result"); const categoryResult = document.getElementById("category-result") const reset = document.getElementById("reset"); const imagePreview = dropArea.querySelector("#image-preview"); let file; button.onclick = () => { input.click(); }; input.addEventListener("change", function () { file = this.files[0]; dropArea.classList.add("active"); viewFile(); }); dropArea.addEventListener("dragover", (event) => { event.preventDefault(); dropArea.classList.add("active"); dragText.textContent = "Release to Upload File"; }); dropArea.addEventListener("dragleave", () => { dropArea.classList.remove("active"); dragText.textContent = "Drag & Drop or Click to Upload File"; }); dropArea.addEventListener("drop", (event) => { event.preventDefault(); file = event.dataTransfer.files[0]; viewFile(); }); form.addEventListener("submit", (event) => { event.preventDefault(); if (!file) { alert("Please select a file!"); return; } const formData = new FormData(); formData.append("file", file); fetch("/upload", { method: "POST", body: formData, }) .then((response) => response.text()) .then((html) => { // Afficher à nouveau le formulaire de téléchargement de fichier const responseDOM = new DOMParser().parseFromString(html, "text/html"); const resultTextArea = responseDOM.getElementById("ocr-result"); const categoryTextArea = responseDOM.getElementById("category-result"); // Récupération de la zone de texte category-result if (resultTextArea && categoryTextArea) { ocrResult.value = resultTextArea.value; categoryResult.value = categoryTextArea.value; // Affichage de la prédiction de classe dans la zone de texte category-result } else { console.error("Error: OCR result textarea not found in response"); } }) .catch((error) => console.error(error)); }); // Define the original HTML structure of the drop area const originalDropAreaHTML = `