const dropZone = document.getElementById('drop-zone'); const fileInput = document.getElementById('file-input'); const preview = document.getElementById('image-preview'); const predictBtn = document.getElementById('predict-btn'); const grid = document.getElementById('comparison-grid'); dropZone.onclick = () => fileInput.click(); fileInput.onchange = (e) => { const file = e.target.files[0]; if (file) { const reader = new FileReader(); reader.onload = (ev) => { preview.src = ev.target.result; preview.classList.remove('hidden'); // Si tienes un placeholder de "subir imagen", ocúltalo aquí const placeholder = document.getElementById('upload-placeholder'); if(placeholder) placeholder.classList.add('hidden'); predictBtn.disabled = false; }; reader.readAsDataURL(file); } }; predictBtn.onclick = async () => { const formData = new FormData(); formData.append('file', fileInput.files[0]); document.getElementById('loader').classList.remove('hidden'); try { const response = await fetch('/predict_all', { method: 'POST', body: formData }); const results = await response.json(); emptyState.classList.add('hidden'); resultsSection.classList.remove('hidden'); grid.innerHTML = ''; results.forEach(res => { // CAMBIO CLAVE: Usamos el status de la API, no buscamos texto manualmente const isHealthy = res.status === "Sana"; const color = isHealthy ? 'green' : 'amber'; const icon = isHealthy ? 'check-circle' : 'alert-triangle'; grid.innerHTML += `

${res.name}

Predicción de la IA

${res.prediction}
${res.confidence}% Confianza
`; }); lucide.createIcons(); resultsSection.scrollIntoView({ behavior: 'smooth', block: 'start' }); } catch (e) { alert("Error conectando con el servidor Python."); } document.getElementById('loader').classList.add('hidden'); };