Ram0894's picture
Add model app files
5371cce verified
Raw
History Blame Contribute Delete
30.8 kB
<!DOCTYPE html>
<html lang="en" class="h-full bg-slate-900 text-slate-100">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>AI-Assisted Diagnostic Support Platform</title>
<!-- Tailwind CSS Play CDN -->
<script src="https://cdn.tailwindcss.com"></script>
<script>
tailwind.config = {
theme: {
extend: {
colors: {
clinical: {
50: '#f0f7ff',
100: '#e0effe',
500: '#0284c7',
600: '#0369a1',
700: '#075985',
800: '#0c4a6e',
900: '#0a3a5c',
}
}
}
}
}
</script>
<!-- Google Fonts Outfit & Inter -->
<link href="https://fonts.googleapis.com/css2?family=Inter:wght@300;400;500;600;700&family=Outfit:wght@400;600;700;800&display=swap" rel="stylesheet">
<style>
body {
font-family: 'Inter', sans-serif;
}
h1, h2, h3, .font-display {
font-family: 'Outfit', sans-serif;
}
</style>
</head>
<body class="min-h-full flex flex-col justify-between selection:bg-sky-500/30">
<!-- Header -->
<header class="border-b border-slate-800 bg-slate-950/80 backdrop-blur-md sticky top-0 z-50 px-6 py-4 flex items-center justify-between">
<div class="flex items-center gap-3">
<div class="p-2 bg-sky-500/20 text-sky-400 rounded-lg border border-sky-500/30">
<!-- Pulse diagnostic icon (SVG) -->
<svg xmlns="http://www.w3.org/2000/svg" class="h-6 w-6 animate-pulse" fill="none" viewBox="0 0 24 24" stroke="currentColor" stroke-width="2">
<path stroke-linecap="round" stroke-linejoin="round" d="M9 12l2 2 4-4m6 2a9 9 0 11-18 0 9 9 0 0118 0z" />
</svg>
</div>
<div>
<h1 class="text-xl font-bold tracking-tight bg-gradient-to-r from-sky-400 to-indigo-400 bg-clip-text text-transparent">
AI-Assisted Diagnostic Support Platform
</h1>
<p class="text-xs text-slate-400 font-medium">Biomedical Engineering Graduation Project</p>
</div>
</div>
<!-- Health Status -->
<div class="flex items-center gap-2 bg-slate-900 px-3 py-1.5 rounded-full border border-slate-800 text-xs">
<span id="api-status-dot" class="h-2.5 w-2.5 rounded-full bg-emerald-500 animate-pulse"></span>
<span id="api-status-text" class="text-slate-300">Backend API: Online</span>
</div>
</header>
<!-- Main Container -->
<main class="max-w-7xl mx-auto p-6 w-full flex-grow grid grid-cols-1 lg:grid-cols-12 gap-6">
<!-- Left Column: Module & Upload -->
<section class="lg:col-span-5 flex flex-col gap-6">
<!-- Module Selector -->
<div class="bg-slate-950/40 border border-slate-800 rounded-2xl p-5 backdrop-blur-sm">
<h2 class="text-sm font-semibold text-slate-400 mb-4 uppercase tracking-wider flex items-center gap-2">
<svg class="h-4 w-4 text-sky-400" fill="none" stroke="currentColor" viewBox="0 0 24 24"><path stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="M19 11H5m14 0a2 2 0 012 2v6a2 2 0 01-2 2H5a2 2 0 01-2-2v-6a2 2 0 012-2m14 0V9a2 2 0 00-2-2M5 11V9a2 2 0 012-2m0 0V5a2 2 0 012-2h6a2 2 0 012 2v2M7 7h10"></path></svg>
Select Diagnostic Module
</h2>
<div class="grid grid-cols-2 gap-3">
<button id="btn-module-blood" onclick="switchModule('blood_cell')" class="p-4 rounded-xl border text-left transition-all border-sky-500 bg-sky-500/10 text-white shadow-[0_0_15px_rgba(14,165,233,0.15)]">
<div class="font-bold text-sm">WBC Blood Smear</div>
<div class="text-[10px] text-slate-400 mt-1">ResNet-18 (8 Classes)</div>
<div class="text-[10px] text-sky-400 mt-2 font-medium">98.07% Accuracy</div>
</button>
<button id="btn-module-skin" onclick="switchModule('skin_lesion')" class="p-4 rounded-xl border text-left transition-all border-slate-800 bg-slate-950/60 text-slate-400 hover:border-slate-700">
<div class="font-bold text-sm">Skin Cancer ViT</div>
<div class="text-[10px] text-slate-400 mt-1">Transformer (7 Classes)</div>
<div class="text-[10px] text-sky-400 mt-2 font-medium">96.95% Accuracy</div>
</button>
</div>
<div class="mt-4 p-3 bg-slate-900/60 rounded-lg border border-slate-800 flex gap-2.5 text-xs text-slate-400">
<svg class="h-4 w-4 text-sky-400 shrink-0 mt-0.5" fill="none" stroke="currentColor" viewBox="0 0 24 24"><path stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="M13 16h-1v-4h-1m1-4h.01M21 12a9 9 0 11-18 0 9 9 0 0118 0z"></path></svg>
<div id="module-desc">
Loads standard ResNet-18 network fine-tuned on PBC dataset. Identifies: Basophils, Eosinophils, Erythroblasts, Lymphocytes, Monocytes, Neutrophils, and Platelets.
</div>
</div>
</div>
<!-- Upload Box -->
<div id="drop-zone" class="bg-slate-950/60 border-2 border-dashed border-slate-800 rounded-2xl p-8 text-center backdrop-blur-sm transition-all flex flex-col items-center justify-center min-h-[300px]">
<div id="upload-prompt" class="flex flex-col items-center">
<div class="p-4 bg-slate-900 border border-slate-800 rounded-2xl mb-4 text-slate-400">
<svg class="h-8 w-8" fill="none" stroke="currentColor" viewBox="0 0 24 24"><path stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="M4 16v1a3 3 0 003 3h10a3 3 0 003-3v-1m-4-8l-4-4m0 0L8 8m4-4v12"></path></svg>
</div>
<h3 class="font-bold text-sm mb-1 text-slate-200">Upload diagnostic image</h3>
<p class="text-xs text-slate-400 mb-6 max-w-[280px]">
Drag and drop your clinical image here, or browse local files
</p>
<label class="px-5 py-2.5 bg-slate-900 hover:bg-slate-800 border border-slate-700 rounded-xl text-xs font-semibold text-slate-200 cursor-pointer transition-colors shadow-md">
Browse Files
<input type="file" id="file-input" onchange="handleFileSelect(event)" accept="image/*" class="hidden">
</label>
</div>
<div id="upload-preview" class="hidden relative w-full flex flex-col items-center gap-4">
<img id="img-preview" src="#" alt="Preview" class="max-h-[220px] rounded-lg object-contain border border-slate-800 shadow-lg">
<div class="flex gap-2">
<button onclick="clearUpload()" class="px-4 py-2 border border-slate-700 rounded-lg text-xs hover:bg-slate-800 transition-colors">
Remove
</button>
<button id="btn-run" onclick="submitInference()" class="px-6 py-2 bg-sky-500 hover:bg-sky-600 text-white text-xs font-semibold rounded-lg shadow-lg hover:shadow-sky-500/20 transition-all flex items-center gap-2">
<svg class="h-3 w-3" fill="none" stroke="currentColor" viewBox="0 0 24 24"><path stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="M13 10V3L4 14h7v7l9-11h-7z"></path></svg>
Run Diagnostic Inference
</button>
</div>
</div>
</div>
<!-- Quick Demo Images -->
<div class="bg-slate-950/40 border border-slate-800 rounded-2xl p-5 backdrop-blur-sm">
<h2 class="text-sm font-semibold text-slate-400 mb-3 uppercase tracking-wider flex items-center gap-2">
<svg class="h-4 w-4 text-indigo-400" fill="none" stroke="currentColor" viewBox="0 0 24 24"><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"></path></svg>
Demo Sample Images
</h2>
<p class="text-[11px] text-slate-400 mb-4">
Click a sample below to load and run instant diagnosis without file uploads.
</p>
<div class="grid grid-cols-2 gap-3">
<button onclick="loadDemoSample('blood_cell')" class="flex items-center gap-2.5 p-3 rounded-xl bg-slate-950/80 hover:bg-slate-900 border border-slate-800 text-left transition-colors">
<div class="w-8 h-8 rounded bg-sky-500/20 text-sky-400 flex items-center justify-center shrink-0 text-xs font-bold">WBC</div>
<div class="truncate">
<div class="text-xs font-bold text-slate-200 truncate">Blood Cell Smear</div>
<div class="text-[10px] text-slate-500">Run WBC ResNet</div>
</div>
</button>
<button onclick="loadDemoSample('skin_lesion')" class="flex items-center gap-2.5 p-3 rounded-xl bg-slate-950/80 hover:bg-slate-900 border border-slate-800 text-left transition-colors">
<div class="w-8 h-8 rounded bg-indigo-500/20 text-indigo-400 flex items-center justify-center shrink-0 text-xs font-bold">SKIN</div>
<div class="truncate">
<div class="text-xs font-bold text-slate-200 truncate">Skin Lesion</div>
<div class="text-[10px] text-slate-500">Run Cancer ViT</div>
</div>
</button>
</div>
</div>
</section>
<!-- Right Column: Diagnostic Results -->
<section class="lg:col-span-7 flex flex-col gap-6">
<div class="bg-slate-950/40 border border-slate-800 rounded-2xl p-6 backdrop-blur-sm flex-grow flex flex-col">
<h2 class="text-sm font-semibold text-slate-400 mb-6 uppercase tracking-wider flex items-center justify-between">
<span class="flex items-center gap-2">
<svg class="h-4 w-4 text-sky-400" fill="none" stroke="currentColor" viewBox="0 0 24 24"><path stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="M9 19v-6a2 2 0 00-2-2H5a2 2 0 00-2 2v6a2 2 0 002 2h2a2 2 0 002-2zm0 0V9a2 2 0 012-2h2a2 2 0 012 2v10m-6 0a2 2 0 002 2h2a2 2 0 002-2m0 0V5a2 2 0 012-2h2a2 2 0 012 2v14a2 2 0 01-2 2h-2a2 2 0 01-2-2z"></path></svg>
Diagnostic Results
</span>
<span id="inf-time-tag" class="text-xs text-slate-500 flex items-center gap-1.5 font-normal normal-case hidden">
<svg class="h-3 w-3" fill="none" stroke="currentColor" viewBox="0 0 24 24"><path stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="M12 8v4l3 3m6-3a9 9 0 11-18 0 9 9 0 0118 0z"></path></svg>
Inference Time: <span id="inf-time-value">0.0</span> ms
</span>
</h2>
<!-- Loading State -->
<div id="results-loading" class="hidden flex-grow flex flex-col items-center justify-center p-12 text-center">
<svg class="h-10 w-10 text-sky-500 animate-spin mb-4" fill="none" viewBox="0 0 24 24">
<circle class="opacity-25" cx="12" cy="12" r="10" stroke="currentColor" stroke-width="4"></circle>
<path class="opacity-75" fill="currentColor" d="M4 12a8 8 0 018-8V0C5.373 0 0 5.373 0 12h4zm2 5.291A7.962 7.962 0 014 12H0c0 3.042 1.135 5.824 3 7.938l3-2.647z"></path>
</svg>
<h3 class="font-bold text-base mb-1 text-slate-200">Analyzing Medical Image...</h3>
<p class="text-xs text-slate-400 max-w-[280px]">
Extracting high-level features and running pre-trained neural networks. Please wait...
</p>
</div>
<!-- Initial Blank State -->
<div id="results-blank" class="flex-grow flex flex-col items-center justify-center p-12 text-center text-slate-400 border border-dashed border-slate-800 rounded-2xl bg-slate-950/20">
<svg class="h-10 w-10 text-slate-600 mb-4" fill="none" stroke="currentColor" viewBox="0 0 24 24"><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"></path></svg>
<h3 class="font-bold text-sm text-slate-300 mb-1">No scan evaluated</h3>
<p class="text-xs text-slate-500 max-w-[280px]">
Please choose a module, upload an image or click a sample, and press "Run Inference" to load diagnostic data.
</p>
</div>
<!-- Filled Results -->
<div id="results-filled" class="hidden flex-grow flex flex-col gap-6">
<!-- Summary card -->
<div class="grid grid-cols-1 md:grid-cols-2 gap-6 bg-slate-900/60 p-5 rounded-2xl border border-slate-800">
<div>
<span class="text-xs text-slate-400 uppercase tracking-wider font-semibold">Predicted Class</span>
<div class="text-2xl font-black text-white mt-1 flex items-center gap-2">
<span id="predicted-label">Label</span>
<span class="text-emerald-500">
<svg class="h-5 w-5" fill="none" stroke="currentColor" viewBox="0 0 24 24"><path stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="M9 12l2 2 4-4m6 2a9 9 0 11-18 0 9 9 0 0118 0z"></path></svg>
</span>
</div>
</div>
<div>
<span class="text-xs text-slate-400 uppercase tracking-wider font-semibold">Confidence Rating</span>
<div class="mt-1 flex items-center gap-3">
<div id="confidence-percentage" class="text-2xl font-black text-sky-400">0.00%</div>
<div class="flex-grow bg-slate-800 h-2.5 rounded-full overflow-hidden">
<div id="confidence-bar" class="bg-sky-500 h-full rounded-full" style="width: 0%"></div>
</div>
</div>
</div>
</div>
<!-- Interactive views -->
<div class="grid grid-cols-1 md:grid-cols-2 gap-6 flex-grow">
<!-- Images Panel -->
<div class="flex flex-col gap-3">
<div class="flex items-center justify-between">
<span class="text-xs font-bold text-slate-400 uppercase">Image View</span>
<button id="btn-toggle-heatmap" onclick="toggleHeatmapView()" class="px-3 py-1 rounded text-[10px] font-bold border bg-sky-500/20 text-sky-300 border-sky-500/40 transition-colors">
Heatmap Overlay
</button>
</div>
<div class="bg-slate-900 border border-slate-800 rounded-xl p-3 flex items-center justify-center min-h-[220px] shadow-inner relative overflow-hidden">
<img id="img-display" src="" alt="Diagnostic Output" class="max-h-[220px] rounded object-contain">
</div>
<p id="image-caption" class="text-[10px] text-slate-400 text-center italic">
Heatmap highlights diagnostic regions of interest.
</p>
</div>
<!-- Probability breakdown -->
<div class="flex flex-col gap-3">
<span class="text-xs font-bold text-slate-400 uppercase">Probability Distribution</span>
<div id="prob-container" class="space-y-3 bg-slate-900/40 p-4 rounded-xl border border-slate-800 flex-grow overflow-y-auto max-h-[260px]">
<!-- Bars dynamically created here -->
</div>
</div>
</div>
</div>
</div>
</section>
</main>
<!-- Database History Log -->
<section class="max-w-7xl mx-auto px-6 pb-6 w-full">
<div class="bg-slate-950/40 border border-slate-800 rounded-2xl p-6 backdrop-blur-sm">
<div class="flex items-center justify-between mb-4">
<h2 class="text-sm font-semibold text-slate-400 uppercase tracking-wider flex items-center gap-2">
<svg class="h-4 w-4 text-sky-400" fill="none" stroke="currentColor" viewBox="0 0 24 24"><path stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="M4 7v10c0 2.21 3.582 4 8 4s8-1.79 8-4V7M4 7c0 2.21 3.582 4 8 4s8-1.79 8-4M4 7c0-2.21 3.582-4 8-4s8 1.79 8 4m0 5c0 2.21-3.582 4-8 4s-8-1.79-8-4"></path></svg>
Database History Logs
</h2>
<button onclick="fetchHistory()" class="p-2 bg-slate-900 border border-slate-800 hover:bg-slate-800 hover:border-slate-700 rounded-lg text-slate-400 hover:text-white transition-all">
<svg class="h-4 w-4" fill="none" stroke="currentColor" viewBox="0 0 24 24"><path stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="M4 4v5h.582m15.356 2A8.001 8.001 0 1121.21 15H19"></path></svg>
</button>
</div>
<div class="overflow-x-auto border border-slate-800 rounded-xl">
<table class="w-full text-left text-xs border-collapse">
<thead>
<tr class="bg-slate-900 text-slate-400 border-b border-slate-800 uppercase tracking-wider font-semibold">
<th class="p-3">Time Stamp</th>
<th class="p-3">Diagnostic Module</th>
<th class="p-3">Uploaded Filename</th>
<th class="p-3">Diagnostic Outcome</th>
<th class="p-3 text-right">Confidence</th>
</tr>
</thead>
<tbody id="history-table-body" class="divide-y divide-slate-800 bg-slate-950/20">
<!-- Table rows populated dynamically -->
</tbody>
</table>
</div>
</div>
</section>
<!-- Legal & Disclaimers -->
<footer class="bg-slate-950 border-t border-slate-800 px-6 py-6 text-center text-slate-400 text-xs">
<div class="max-w-4xl mx-auto flex flex-col gap-4">
<div class="flex items-center justify-center gap-2 text-rose-400 font-bold bg-rose-500/10 border border-rose-500/20 rounded-xl px-4 py-3 max-w-2xl mx-auto shadow-md">
<svg class="h-5 w-5 shrink-0" fill="none" stroke="currentColor" viewBox="0 0 24 24"><path stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="M12 9v2m0 4h.01m-6.938 4h13.856c1.54 0 2.502-1.667 1.732-3L13.732 4c-.77-1.333-2.694-1.333-3.464 0L3.34 16c-.77 1.333.192 3 1.732 3z"></path></svg>
<span>
ACADEMIC DISCLAIMER: For laboratory evaluation and demonstration only. This system is not cleared by FDA/CDSCO and must not be used for clinical decision-making or diagnosis of human subjects.
</span>
</div>
<div class="text-[10px] text-slate-500 leading-relaxed">
<p class="font-semibold text-slate-400 mb-1">DATASET LIMITATIONS & BIAS STATEMENT</p>
<p>
The models integrated are trained on public datasets (PBC & HAM10000) which contain inherent demographic and technical biases. For instance, the skin lesion classifier exhibits higher accuracy on fair skin types due to underrepresentation of dark skin phototypes in HAM10000. The WBC classifier was trained on high-quality microscopy slides, which may result in degraded accuracy when processing images captured under varying illumination, magnification levels, or camera parameters.
</p>
</div>
<p class="text-[10px] text-slate-600 mt-2">
© 2026 AI-Assisted Diagnostic Platform. Built for Graduation Project Evaluation.
</p>
</div>
</footer>
<script>
// Configuration: Set to your public backend URL when hosting online (e.g., "https://username-space.hf.space")
const API_BASE = "https://ram0894-diagnostic-platform-api.hf.space";
let activeModule = 'blood_cell';
let currentPrediction = null;
let originalImageURL = null;
let showingHeatmap = true;
let selectedFileObject = null;
// Switch between WBC and Skin modules
function switchModule(module) {
activeModule = module;
const btnBlood = document.getElementById('btn-module-blood');
const btnSkin = document.getElementById('btn-module-skin');
const desc = document.getElementById('module-desc');
if (module === 'blood_cell') {
btnBlood.className = "p-4 rounded-xl border text-left transition-all border-sky-500 bg-sky-500/10 text-white shadow-[0_0_15px_rgba(14,165,233,0.15)]";
btnSkin.className = "p-4 rounded-xl border text-left transition-all border-slate-800 bg-slate-950/60 text-slate-400 hover:border-slate-700";
desc.innerText = "Loads standard ResNet-18 network fine-tuned on PBC dataset. Identifies: Basophils, Eosinophils, Erythroblasts, Lymphocytes, Monocytes, Neutrophils, and Platelets.";
} else {
btnBlood.className = "p-4 rounded-xl border text-left transition-all border-slate-800 bg-slate-950/60 text-slate-400 hover:border-slate-700";
btnSkin.className = "p-4 rounded-xl border text-left transition-all border-sky-500 bg-sky-500/10 text-white shadow-[0_0_15px_rgba(14,165,233,0.15)]";
desc.innerText = "Loads Vision Transformer (ViT) model trained on the HAM10000 skin dataset. Identifies: Melanocytic Nevi, Melanoma, Carcinoma, and other lesion types.";
}
clearUpload();
}
// Handle Drag & Drop
const dropZone = document.getElementById('drop-zone');
dropZone.addEventListener('dragover', (e) => {
e.preventDefault();
dropZone.classList.add('border-sky-500', 'bg-sky-500/5');
});
dropZone.addEventListener('dragleave', () => {
dropZone.classList.remove('border-sky-500', 'bg-sky-500/5');
});
dropZone.addEventListener('drop', (e) => {
e.preventDefault();
dropZone.classList.remove('border-sky-500', 'bg-sky-500/5');
if (e.dataTransfer.files && e.dataTransfer.files[0]) {
loadImageFile(e.dataTransfer.files[0]);
}
});
function handleFileSelect(e) {
if (e.target.files && e.target.files[0]) {
loadImageFile(e.target.files[0]);
}
}
function loadImageFile(file) {
selectedFileObject = file;
originalImageURL = URL.createObjectURL(file);
document.getElementById('upload-prompt').classList.add('hidden');
document.getElementById('upload-preview').classList.remove('hidden');
document.getElementById('img-preview').src = originalImageURL;
// Hide previous results
document.getElementById('results-filled').classList.add('hidden');
document.getElementById('results-blank').classList.remove('hidden');
document.getElementById('inf-time-tag').classList.add('hidden');
}
function clearUpload() {
selectedFileObject = null;
if (originalImageURL) {
URL.revokeObjectURL(originalImageURL);
originalImageURL = null;
}
document.getElementById('file-input').value = '';
document.getElementById('upload-preview').classList.add('hidden');
document.getElementById('upload-prompt').classList.remove('hidden');
document.getElementById('results-filled').classList.add('hidden');
document.getElementById('results-blank').classList.remove('hidden');
document.getElementById('inf-time-tag').classList.add('hidden');
currentPrediction = null;
}
// Submit for prediction
async function submitInference() {
if (!selectedFileObject) return;
document.getElementById('results-blank').classList.add('hidden');
document.getElementById('results-filled').classList.add('hidden');
document.getElementById('results-loading').classList.remove('hidden');
const formData = new FormData();
formData.append("file", selectedFileObject);
formData.append("module_type", activeModule);
try {
const response = await fetch(API_BASE + "/predict", {
method: "POST",
body: formData
});
if (!response.ok) {
const err = await response.json();
throw new Error(err.detail || "Diagnosis failed");
}
currentPrediction = await response.json();
renderResults();
fetchHistory();
} catch (err) {
alert(err.message);
document.getElementById('results-blank').classList.remove('hidden');
} finally {
document.getElementById('results-loading').classList.add('hidden');
}
}
// Render prediction response
function renderResults() {
if (!currentPrediction) return;
document.getElementById('results-filled').classList.remove('hidden');
// Labels & Confidence
document.getElementById('predicted-label').innerText = currentPrediction.prediction;
document.getElementById('confidence-percentage').innerText = (currentPrediction.confidence * 100).toFixed(2) + "%";
document.getElementById('confidence-bar').style.width = (currentPrediction.confidence * 100) + "%";
// Inf speed
document.getElementById('inf-time-tag').classList.remove('hidden');
document.getElementById('inf-time-value').innerText = (currentPrediction.inference_time_sec * 1000).toFixed(1);
// Setup image views
showingHeatmap = true;
const btnToggle = document.getElementById('btn-toggle-heatmap');
if (currentPrediction.heatmap_base64) {
btnToggle.style.display = 'inline-block';
btnToggle.className = "px-3 py-1 rounded text-[10px] font-bold border bg-sky-500/20 text-sky-300 border-sky-500/40 transition-colors";
btnToggle.innerText = activeModule === 'blood_cell' ? 'Grad-CAM Overlay' : 'Attention Heatmap';
document.getElementById('img-display').src = "data:image/jpeg;base64," + currentPrediction.heatmap_base64;
document.getElementById('image-caption').innerText = activeModule === 'blood_cell'
? "Grad-CAM highlights regions influencing the decision."
: "Attention rollout shows the ViT's self-attention patterns.";
} else {
btnToggle.style.display = 'none';
document.getElementById('img-display').src = originalImageURL;
document.getElementById('image-caption').innerText = "Original input image resized to 224x224.";
}
// Probability bar charts
const container = document.getElementById('prob-container');
container.innerHTML = '';
const sortedProbs = Object.entries(currentPrediction.class_probabilities)
.sort((a, b) => b[1] - a[1]);
sortedProbs.forEach(([className, prob]) => {
const isPred = className.toLowerCase() === currentPrediction.prediction.toLowerCase();
const barColor = isPred ? 'bg-sky-500' : 'bg-slate-700';
const itemHtml = `
<div class="text-xs">
<div class="flex justify-between text-slate-300 mb-1">
<span class="font-medium truncate max-w-[170px]">${className}</span>
<span class="text-slate-400">${(prob * 100).toFixed(2)}%</span>
</div>
<div class="w-full bg-slate-800 h-1.5 rounded-full overflow-hidden">
<div class="h-full rounded-full ${barColor}" style="width: ${prob * 100}%"></div>
</div>
</div>
`;
container.insertAdjacentHTML('beforeend', itemHtml);
});
}
// Toggle overlay view
function toggleHeatmapView() {
if (!currentPrediction || !currentPrediction.heatmap_base64) return;
showingHeatmap = !showingHeatmap;
const btnToggle = document.getElementById('btn-toggle-heatmap');
const imgDisp = document.getElementById('img-display');
const caption = document.getElementById('image-caption');
if (showingHeatmap) {
btnToggle.className = "px-3 py-1 rounded text-[10px] font-bold border bg-sky-500/20 text-sky-300 border-sky-500/40 transition-colors";
imgDisp.src = "data:image/jpeg;base64," + currentPrediction.heatmap_base64;
caption.innerText = activeModule === 'blood_cell'
? "Grad-CAM highlights regions influencing the decision."
: "Attention rollout shows the ViT's self-attention patterns.";
} else {
btnToggle.className = "px-3 py-1 rounded text-[10px] font-bold border bg-slate-900 text-slate-400 border-slate-800 hover:border-slate-700 transition-colors";
imgDisp.src = originalImageURL;
caption.innerText = "Original input image resized to 224x224.";
}
}
// Load Demo Image
async function loadDemoSample(sampleType) {
if (sampleType !== activeModule) {
switchModule(sampleType);
}
const filename = sampleType === 'blood_cell' ? 'sample_wbc_test.jpg' : 'sample_skin_test.jpg';
document.getElementById('results-blank').classList.add('hidden');
document.getElementById('results-filled').classList.add('hidden');
document.getElementById('results-loading').classList.remove('hidden');
try {
const response = await fetch(API_BASE + "/static/" + filename);
if (!response.ok) throw new Error("Demo sample file missing");
const blob = await response.blob();
const file = new File([blob], filename, { type: "image/jpeg" });
loadImageFile(file);
// Auto run diagnosis
await submitInference();
} catch (err) {
alert("Could not fetch demo sample image: " + err.message);
document.getElementById('results-loading').classList.add('hidden');
document.getElementById('results-blank').classList.remove('hidden');
}
}
// Fetch Database Logs
async function fetchHistory() {
try {
const response = await fetch(API_BASE + "/history");
if (!response.ok) throw new Error("Failed to load logs");
const historyList = await response.json();
const tbody = document.getElementById('history-table-body');
tbody.innerHTML = '';
if (historyList.length === 0) {
tbody.innerHTML = `
<tr>
<td colspan="5" class="p-8 text-center text-slate-500">
No records saved in database. Run inference to log items.
</td>
</tr>
`;
return;
}
historyList.slice(0, 8).forEach(log => {
const rowHtml = `
<tr class="hover:bg-slate-900/40 text-slate-300 transition-colors">
<td class="p-3 text-slate-400">
${new Date(log.timestamp).toLocaleString()}
</td>
<td class="p-3 font-semibold text-sky-400">${log.module}</td>
<td class="p-3 truncate max-w-[180px]" title="${log.filename}">${log.filename}</td>
<td class="p-3 text-slate-100 font-bold">${log.prediction}</td>
<td class="p-3 text-right font-semibold text-slate-300">
${(log.confidence * 100).toFixed(1)}%
</td>
</tr>
`;
tbody.insertAdjacentHTML('beforeend', rowHtml);
});
} catch (err) {
console.error(err.message);
}
}
// Initialize on load
window.onload = function() {
fetchHistory();
};
</script>
</body>
</html>