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