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|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
<!DOCTYPE html>
|
| 2 |
+
<html lang="en">
|
| 3 |
+
<head>
|
| 4 |
+
<meta charset="UTF-8">
|
| 5 |
+
<meta name="viewport" content="width=device-width, initial-scale=1.0">
|
| 6 |
+
<title>Brain Tumor Detection</title>
|
| 7 |
+
<style>
|
| 8 |
+
* {
|
| 9 |
+
margin: 0;
|
| 10 |
+
padding: 0;
|
| 11 |
+
box-sizing: border-box;
|
| 12 |
+
}
|
| 13 |
+
|
| 14 |
+
body {
|
| 15 |
+
font-family: 'Segoe UI', Tahoma, Geneva, Verdana, sans-serif;
|
| 16 |
+
background: linear-gradient(135deg, #1a1a2e 0%, #16213e 100%);
|
| 17 |
+
min-height: 100vh;
|
| 18 |
+
display: flex;
|
| 19 |
+
justify-content: center;
|
| 20 |
+
align-items: center;
|
| 21 |
+
padding: 20px;
|
| 22 |
+
}
|
| 23 |
+
|
| 24 |
+
.container {
|
| 25 |
+
background: white;
|
| 26 |
+
border-radius: 20px;
|
| 27 |
+
box-shadow: 0 20px 60px rgba(0, 0, 0, 0.3);
|
| 28 |
+
padding: 40px;
|
| 29 |
+
max-width: 500px;
|
| 30 |
+
width: 100%;
|
| 31 |
+
}
|
| 32 |
+
|
| 33 |
+
h1 {
|
| 34 |
+
text-align: center;
|
| 35 |
+
color: #1a1a2e;
|
| 36 |
+
margin-bottom: 10px;
|
| 37 |
+
font-size: 28px;
|
| 38 |
+
}
|
| 39 |
+
|
| 40 |
+
.subtitle {
|
| 41 |
+
text-align: center;
|
| 42 |
+
color: #666;
|
| 43 |
+
margin-bottom: 30px;
|
| 44 |
+
font-size: 14px;
|
| 45 |
+
}
|
| 46 |
+
|
| 47 |
+
.upload-area {
|
| 48 |
+
border: 3px dashed #ddd;
|
| 49 |
+
border-radius: 15px;
|
| 50 |
+
padding: 40px 20px;
|
| 51 |
+
text-align: center;
|
| 52 |
+
cursor: pointer;
|
| 53 |
+
transition: all 0.3s ease;
|
| 54 |
+
margin-bottom: 20px;
|
| 55 |
+
}
|
| 56 |
+
|
| 57 |
+
.upload-area:hover {
|
| 58 |
+
border-color: #4a90a4;
|
| 59 |
+
background: #f8f9fa;
|
| 60 |
+
}
|
| 61 |
+
|
| 62 |
+
.upload-area.dragover {
|
| 63 |
+
border-color: #4a90a4;
|
| 64 |
+
background: #e8f4f8;
|
| 65 |
+
}
|
| 66 |
+
|
| 67 |
+
.upload-icon {
|
| 68 |
+
font-size: 50px;
|
| 69 |
+
margin-bottom: 15px;
|
| 70 |
+
}
|
| 71 |
+
|
| 72 |
+
.upload-text {
|
| 73 |
+
color: #666;
|
| 74 |
+
font-size: 16px;
|
| 75 |
+
}
|
| 76 |
+
|
| 77 |
+
.upload-text span {
|
| 78 |
+
color: #4a90a4;
|
| 79 |
+
font-weight: bold;
|
| 80 |
+
}
|
| 81 |
+
|
| 82 |
+
#fileInput {
|
| 83 |
+
display: none;
|
| 84 |
+
}
|
| 85 |
+
|
| 86 |
+
.preview-container {
|
| 87 |
+
display: none;
|
| 88 |
+
margin-bottom: 20px;
|
| 89 |
+
}
|
| 90 |
+
|
| 91 |
+
.preview-container img {
|
| 92 |
+
width: 100%;
|
| 93 |
+
max-height: 300px;
|
| 94 |
+
object-fit: contain;
|
| 95 |
+
border-radius: 10px;
|
| 96 |
+
border: 2px solid #eee;
|
| 97 |
+
}
|
| 98 |
+
|
| 99 |
+
.file-name {
|
| 100 |
+
text-align: center;
|
| 101 |
+
color: #666;
|
| 102 |
+
font-size: 14px;
|
| 103 |
+
margin-top: 10px;
|
| 104 |
+
}
|
| 105 |
+
|
| 106 |
+
.btn {
|
| 107 |
+
width: 100%;
|
| 108 |
+
padding: 15px;
|
| 109 |
+
border: none;
|
| 110 |
+
border-radius: 10px;
|
| 111 |
+
font-size: 18px;
|
| 112 |
+
font-weight: bold;
|
| 113 |
+
cursor: pointer;
|
| 114 |
+
transition: all 0.3s ease;
|
| 115 |
+
}
|
| 116 |
+
|
| 117 |
+
.btn-predict {
|
| 118 |
+
background: linear-gradient(135deg, #4a90a4 0%, #357a8c 100%);
|
| 119 |
+
color: white;
|
| 120 |
+
}
|
| 121 |
+
|
| 122 |
+
.btn-predict:hover {
|
| 123 |
+
transform: translateY(-2px);
|
| 124 |
+
box-shadow: 0 5px 20px rgba(74, 144, 164, 0.4);
|
| 125 |
+
}
|
| 126 |
+
|
| 127 |
+
.btn-predict:disabled {
|
| 128 |
+
background: #ccc;
|
| 129 |
+
cursor: not-allowed;
|
| 130 |
+
transform: none;
|
| 131 |
+
box-shadow: none;
|
| 132 |
+
}
|
| 133 |
+
|
| 134 |
+
.result-container {
|
| 135 |
+
display: none;
|
| 136 |
+
margin-top: 25px;
|
| 137 |
+
padding: 25px;
|
| 138 |
+
border-radius: 15px;
|
| 139 |
+
text-align: center;
|
| 140 |
+
}
|
| 141 |
+
|
| 142 |
+
.result-tumor {
|
| 143 |
+
background: linear-gradient(135deg, #ff6b6b 0%, #ee5a5a 100%);
|
| 144 |
+
color: white;
|
| 145 |
+
}
|
| 146 |
+
|
| 147 |
+
.result-no-tumor {
|
| 148 |
+
background: linear-gradient(135deg, #51cf66 0%, #40c057 100%);
|
| 149 |
+
color: white;
|
| 150 |
+
}
|
| 151 |
+
|
| 152 |
+
.result-title {
|
| 153 |
+
font-size: 24px;
|
| 154 |
+
font-weight: bold;
|
| 155 |
+
margin-bottom: 10px;
|
| 156 |
+
}
|
| 157 |
+
|
| 158 |
+
.result-confidence {
|
| 159 |
+
font-size: 16px;
|
| 160 |
+
opacity: 0.9;
|
| 161 |
+
}
|
| 162 |
+
|
| 163 |
+
.loading {
|
| 164 |
+
display: none;
|
| 165 |
+
text-align: center;
|
| 166 |
+
margin-top: 20px;
|
| 167 |
+
}
|
| 168 |
+
|
| 169 |
+
.spinner {
|
| 170 |
+
border: 4px solid #f3f3f3;
|
| 171 |
+
border-top: 4px solid #4a90a4;
|
| 172 |
+
border-radius: 50%;
|
| 173 |
+
width: 40px;
|
| 174 |
+
height: 40px;
|
| 175 |
+
animation: spin 1s linear infinite;
|
| 176 |
+
margin: 0 auto 15px;
|
| 177 |
+
}
|
| 178 |
+
|
| 179 |
+
@keyframes spin {
|
| 180 |
+
0% { transform: rotate(0deg); }
|
| 181 |
+
100% { transform: rotate(360deg); }
|
| 182 |
+
}
|
| 183 |
+
|
| 184 |
+
.error-message {
|
| 185 |
+
display: none;
|
| 186 |
+
background: #fff3f3;
|
| 187 |
+
border: 1px solid #ff6b6b;
|
| 188 |
+
color: #d63031;
|
| 189 |
+
padding: 15px;
|
| 190 |
+
border-radius: 10px;
|
| 191 |
+
margin-top: 20px;
|
| 192 |
+
text-align: center;
|
| 193 |
+
}
|
| 194 |
+
|
| 195 |
+
.reset-btn {
|
| 196 |
+
display: none;
|
| 197 |
+
margin-top: 15px;
|
| 198 |
+
background: #6c757d;
|
| 199 |
+
color: white;
|
| 200 |
+
}
|
| 201 |
+
|
| 202 |
+
.reset-btn:hover {
|
| 203 |
+
background: #5a6268;
|
| 204 |
+
}
|
| 205 |
+
</style>
|
| 206 |
+
</head>
|
| 207 |
+
<body>
|
| 208 |
+
<div class="container">
|
| 209 |
+
<h1>🧠 Brain Tumor Detection</h1>
|
| 210 |
+
<p class="subtitle">Upload an MRI scan image for AI-powered analysis</p>
|
| 211 |
+
|
| 212 |
+
<div class="upload-area" id="uploadArea">
|
| 213 |
+
<div class="upload-icon">📤</div>
|
| 214 |
+
<p class="upload-text">Drag & drop your image here<br>or <span>click to browse</span></p>
|
| 215 |
+
<input type="file" id="fileInput" accept="image/*">
|
| 216 |
+
</div>
|
| 217 |
+
|
| 218 |
+
<div class="preview-container" id="previewContainer">
|
| 219 |
+
<img id="previewImage" src="" alt="Preview">
|
| 220 |
+
<p class="file-name" id="fileName"></p>
|
| 221 |
+
</div>
|
| 222 |
+
|
| 223 |
+
<button class="btn btn-predict" id="predictBtn" disabled>Analyze Image</button>
|
| 224 |
+
|
| 225 |
+
<div class="loading" id="loading">
|
| 226 |
+
<div class="spinner"></div>
|
| 227 |
+
<p>Analyzing image...</p>
|
| 228 |
+
</div>
|
| 229 |
+
|
| 230 |
+
<div class="error-message" id="errorMessage"></div>
|
| 231 |
+
|
| 232 |
+
<div class="result-container" id="resultContainer">
|
| 233 |
+
<p class="result-title" id="resultTitle"></p>
|
| 234 |
+
<p class="result-confidence" id="resultConfidence"></p>
|
| 235 |
+
</div>
|
| 236 |
+
|
| 237 |
+
<button class="btn reset-btn" id="resetBtn">Upload New Image</button>
|
| 238 |
+
</div>
|
| 239 |
+
|
| 240 |
+
<script>
|
| 241 |
+
const uploadArea = document.getElementById('uploadArea');
|
| 242 |
+
const fileInput = document.getElementById('fileInput');
|
| 243 |
+
const previewContainer = document.getElementById('previewContainer');
|
| 244 |
+
const previewImage = document.getElementById('previewImage');
|
| 245 |
+
const fileName = document.getElementById('fileName');
|
| 246 |
+
const predictBtn = document.getElementById('predictBtn');
|
| 247 |
+
const loading = document.getElementById('loading');
|
| 248 |
+
const resultContainer = document.getElementById('resultContainer');
|
| 249 |
+
const resultTitle = document.getElementById('resultTitle');
|
| 250 |
+
const resultConfidence = document.getElementById('resultConfidence');
|
| 251 |
+
const errorMessage = document.getElementById('errorMessage');
|
| 252 |
+
const resetBtn = document.getElementById('resetBtn');
|
| 253 |
+
|
| 254 |
+
let selectedFile = null;
|
| 255 |
+
|
| 256 |
+
// Click to upload
|
| 257 |
+
uploadArea.addEventListener('click', () => fileInput.click());
|
| 258 |
+
|
| 259 |
+
// Drag and drop
|
| 260 |
+
uploadArea.addEventListener('dragover', (e) => {
|
| 261 |
+
e.preventDefault();
|
| 262 |
+
uploadArea.classList.add('dragover');
|
| 263 |
+
});
|
| 264 |
+
|
| 265 |
+
uploadArea.addEventListener('dragleave', () => {
|
| 266 |
+
uploadArea.classList.remove('dragover');
|
| 267 |
+
});
|
| 268 |
+
|
| 269 |
+
uploadArea.addEventListener('drop', (e) => {
|
| 270 |
+
e.preventDefault();
|
| 271 |
+
uploadArea.classList.remove('dragover');
|
| 272 |
+
const files = e.dataTransfer.files;
|
| 273 |
+
if (files.length) handleFile(files[0]);
|
| 274 |
+
});
|
| 275 |
+
|
| 276 |
+
// File input change
|
| 277 |
+
fileInput.addEventListener('change', (e) => {
|
| 278 |
+
if (e.target.files.length) handleFile(e.target.files[0]);
|
| 279 |
+
});
|
| 280 |
+
|
| 281 |
+
function handleFile(file) {
|
| 282 |
+
if (!file.type.startsWith('image/')) {
|
| 283 |
+
showError('Please upload an image file (PNG, JPG, JPEG)');
|
| 284 |
+
return;
|
| 285 |
+
}
|
| 286 |
+
|
| 287 |
+
selectedFile = file;
|
| 288 |
+
fileName.textContent = file.name;
|
| 289 |
+
|
| 290 |
+
const reader = new FileReader();
|
| 291 |
+
reader.onload = (e) => {
|
| 292 |
+
previewImage.src = e.target.result;
|
| 293 |
+
previewContainer.style.display = 'block';
|
| 294 |
+
uploadArea.style.display = 'none';
|
| 295 |
+
predictBtn.disabled = false;
|
| 296 |
+
hideError();
|
| 297 |
+
resultContainer.style.display = 'none';
|
| 298 |
+
resetBtn.style.display = 'none';
|
| 299 |
+
};
|
| 300 |
+
reader.readAsDataURL(file);
|
| 301 |
+
}
|
| 302 |
+
|
| 303 |
+
// Predict button click
|
| 304 |
+
predictBtn.addEventListener('click', async () => {
|
| 305 |
+
if (!selectedFile) return;
|
| 306 |
+
|
| 307 |
+
const formData = new FormData();
|
| 308 |
+
formData.append('file', selectedFile);
|
| 309 |
+
|
| 310 |
+
predictBtn.disabled = true;
|
| 311 |
+
loading.style.display = 'block';
|
| 312 |
+
resultContainer.style.display = 'none';
|
| 313 |
+
hideError();
|
| 314 |
+
|
| 315 |
+
try {
|
| 316 |
+
const response = await fetch('/predict', {
|
| 317 |
+
method: 'POST',
|
| 318 |
+
body: formData
|
| 319 |
+
});
|
| 320 |
+
|
| 321 |
+
const data = await response.json();
|
| 322 |
+
|
| 323 |
+
if (data.success) {
|
| 324 |
+
resultTitle.textContent = data.prediction;
|
| 325 |
+
resultConfidence.textContent = `Confidence: ${data.confidence}`;
|
| 326 |
+
|
| 327 |
+
resultContainer.className = 'result-container';
|
| 328 |
+
if (data.prediction.includes('Tumor Detected') && !data.prediction.includes('No')) {
|
| 329 |
+
resultContainer.classList.add('result-tumor');
|
| 330 |
+
} else {
|
| 331 |
+
resultContainer.classList.add('result-no-tumor');
|
| 332 |
+
}
|
| 333 |
+
resultContainer.style.display = 'block';
|
| 334 |
+
resetBtn.style.display = 'block';
|
| 335 |
+
} else {
|
| 336 |
+
showError(data.error || 'Prediction failed');
|
| 337 |
+
}
|
| 338 |
+
} catch (error) {
|
| 339 |
+
showError('Server error. Please try again.');
|
| 340 |
+
} finally {
|
| 341 |
+
loading.style.display = 'none';
|
| 342 |
+
predictBtn.disabled = false;
|
| 343 |
+
}
|
| 344 |
+
});
|
| 345 |
+
|
| 346 |
+
// Reset button
|
| 347 |
+
resetBtn.addEventListener('click', () => {
|
| 348 |
+
selectedFile = null;
|
| 349 |
+
fileInput.value = '';
|
| 350 |
+
previewContainer.style.display = 'none';
|
| 351 |
+
uploadArea.style.display = 'block';
|
| 352 |
+
resultContainer.style.display = 'none';
|
| 353 |
+
resetBtn.style.display = 'none';
|
| 354 |
+
predictBtn.disabled = true;
|
| 355 |
+
hideError();
|
| 356 |
+
});
|
| 357 |
+
|
| 358 |
+
function showError(message) {
|
| 359 |
+
errorMessage.textContent = message;
|
| 360 |
+
errorMessage.style.display = 'block';
|
| 361 |
+
}
|
| 362 |
+
|
| 363 |
+
function hideError() {
|
| 364 |
+
errorMessage.style.display = 'none';
|
| 365 |
+
}
|
| 366 |
+
</script>
|
| 367 |
+
</body>
|
| 368 |
+
</html>
|