Spaces:
Sleeping
Sleeping
| <html lang="en"> | |
| <head> | |
| <meta charset="UTF-8"> | |
| <meta name="viewport" content="width=device-width, initial-scale=1.0"> | |
| <title>Brain Tumor Segmentation</title> | |
| <style> | |
| * { | |
| margin: 0; | |
| padding: 0; | |
| box-sizing: border-box; | |
| } | |
| body { | |
| font-family: 'Segoe UI', Tahoma, Geneva, Verdana, sans-serif; | |
| background: linear-gradient(135deg, #667eea 0%, #764ba2 100%); | |
| min-height: 100vh; | |
| padding: 20px; | |
| display: flex; | |
| flex-direction: column; | |
| align-items: center; | |
| } | |
| .container { | |
| max-width: 1400px; | |
| width: 100%; | |
| background: rgba(255, 255, 255, 0.95); | |
| border-radius: 20px; | |
| box-shadow: 0 20px 60px rgba(0, 0, 0, 0.3); | |
| overflow: hidden; | |
| } | |
| .header { | |
| background: linear-gradient(135deg, #667eea 0%, #764ba2 100%); | |
| color: white; | |
| padding: 40px; | |
| text-align: center; | |
| } | |
| .header h1 { | |
| font-size: 2.5em; | |
| margin-bottom: 10px; | |
| display: flex; | |
| align-items: center; | |
| justify-content: center; | |
| gap: 15px; | |
| } | |
| .header p { | |
| font-size: 1.1em; | |
| opacity: 0.95; | |
| } | |
| .content { | |
| padding: 40px; | |
| } | |
| .info-section { | |
| background: linear-gradient(135deg, #f8f9fa 0%, #e9ecef 100%); | |
| border-radius: 15px; | |
| padding: 30px; | |
| margin-bottom: 30px; | |
| border-left: 5px solid #667eea; | |
| } | |
| .info-section h2 { | |
| color: #667eea; | |
| margin-bottom: 20px; | |
| font-size: 1.8em; | |
| } | |
| .info-grid { | |
| display: grid; | |
| grid-template-columns: repeat(auto-fit, minmax(300px, 1fr)); | |
| gap: 20px; | |
| margin-top: 20px; | |
| } | |
| .info-card { | |
| background: white; | |
| padding: 20px; | |
| border-radius: 10px; | |
| box-shadow: 0 2px 10px rgba(0, 0, 0, 0.1); | |
| } | |
| .info-card h3 { | |
| color: #764ba2; | |
| margin-bottom: 10px; | |
| font-size: 1.2em; | |
| display: flex; | |
| align-items: center; | |
| gap: 10px; | |
| } | |
| .info-card p { | |
| color: #495057; | |
| line-height: 1.6; | |
| } | |
| .info-card ul { | |
| margin-top: 10px; | |
| margin-left: 20px; | |
| color: #495057; | |
| } | |
| .info-card li { | |
| margin: 5px 0; | |
| } | |
| .github-link { | |
| display: inline-flex; | |
| align-items: center; | |
| gap: 8px; | |
| color: #667eea; | |
| text-decoration: none; | |
| font-weight: 600; | |
| font-size: 1.1em; | |
| padding: 10px 20px; | |
| background: white; | |
| border-radius: 8px; | |
| box-shadow: 0 2px 8px rgba(0,0,0,0.1); | |
| transition: all 0.3s; | |
| } | |
| .github-link:hover { | |
| transform: translateY(-2px); | |
| box-shadow: 0 4px 12px rgba(102, 126, 234, 0.3); | |
| color: #764ba2; | |
| } | |
| .upload-section { | |
| background: #f8f9fa; | |
| border-radius: 15px; | |
| padding: 40px; | |
| text-align: center; | |
| margin-bottom: 30px; | |
| border: 3px dashed #667eea; | |
| transition: all 0.3s; | |
| } | |
| .upload-section:hover { | |
| border-color: #764ba2; | |
| background: #f0f1f5; | |
| } | |
| .upload-section.dragover { | |
| background: #e3e8ff; | |
| border-color: #764ba2; | |
| } | |
| .upload-icon { | |
| font-size: 4em; | |
| margin-bottom: 20px; | |
| color: #667eea; | |
| } | |
| .file-input-wrapper { | |
| position: relative; | |
| display: inline-block; | |
| margin: 20px 0; | |
| } | |
| input[type="file"] { | |
| display: none; | |
| } | |
| .file-input-label { | |
| background: linear-gradient(135deg, #667eea 0%, #764ba2 100%); | |
| color: white; | |
| padding: 15px 40px; | |
| border-radius: 50px; | |
| cursor: pointer; | |
| font-size: 1.1em; | |
| font-weight: 600; | |
| transition: all 0.3s; | |
| display: inline-block; | |
| box-shadow: 0 4px 15px rgba(102, 126, 234, 0.4); | |
| } | |
| .file-input-label:hover { | |
| transform: translateY(-2px); | |
| box-shadow: 0 6px 20px rgba(102, 126, 234, 0.6); | |
| } | |
| .example-btn { | |
| background: #6c757d; | |
| color: white; | |
| padding: 12px 30px; | |
| border: none; | |
| border-radius: 50px; | |
| cursor: pointer; | |
| font-size: 1em; | |
| margin-left: 15px; | |
| transition: all 0.3s; | |
| } | |
| .example-btn:hover { | |
| background: #5a6268; | |
| transform: translateY(-2px); | |
| } | |
| .selected-file { | |
| margin-top: 20px; | |
| color: #667eea; | |
| font-weight: 600; | |
| font-size: 1.1em; | |
| } | |
| .analyze-btn { | |
| background: linear-gradient(135deg, #11998e 0%, #38ef7d 100%); | |
| color: white; | |
| padding: 15px 50px; | |
| border: none; | |
| border-radius: 50px; | |
| cursor: pointer; | |
| font-size: 1.2em; | |
| font-weight: 600; | |
| margin-top: 20px; | |
| transition: all 0.3s; | |
| box-shadow: 0 4px 15px rgba(17, 153, 142, 0.4); | |
| } | |
| .analyze-btn:hover:not(:disabled) { | |
| transform: translateY(-2px); | |
| box-shadow: 0 6px 20px rgba(17, 153, 142, 0.6); | |
| } | |
| .analyze-btn:disabled { | |
| background: #ccc; | |
| cursor: not-allowed; | |
| box-shadow: none; | |
| } | |
| .loading { | |
| display: none; | |
| margin: 30px 0; | |
| text-align: center; | |
| } | |
| .spinner { | |
| border: 4px solid #f3f3f3; | |
| border-top: 4px solid #667eea; | |
| border-radius: 50%; | |
| width: 50px; | |
| height: 50px; | |
| animation: spin 1s linear infinite; | |
| margin: 0 auto 20px; | |
| } | |
| @keyframes spin { | |
| 0% { transform: rotate(0deg); } | |
| 100% { transform: rotate(360deg); } | |
| } | |
| .results { | |
| display: none; | |
| margin-top: 40px; | |
| } | |
| .results-grid { | |
| display: grid; | |
| grid-template-columns: repeat(auto-fit, minmax(350px, 1fr)); | |
| gap: 25px; | |
| margin-top: 25px; | |
| } | |
| .result-card { | |
| background: white; | |
| border-radius: 15px; | |
| padding: 20px; | |
| box-shadow: 0 4px 20px rgba(0, 0, 0, 0.1); | |
| transition: all 0.3s; | |
| } | |
| .result-card:hover { | |
| transform: translateY(-5px); | |
| box-shadow: 0 6px 30px rgba(0, 0, 0, 0.15); | |
| } | |
| .result-card h3 { | |
| color: #667eea; | |
| margin-bottom: 15px; | |
| font-size: 1.3em; | |
| } | |
| .result-card img { | |
| width: 100%; | |
| border-radius: 10px; | |
| margin-bottom: 15px; | |
| } | |
| .stats { | |
| background: linear-gradient(135deg, #667eea 0%, #764ba2 100%); | |
| color: white; | |
| border-radius: 15px; | |
| padding: 30px; | |
| margin-top: 25px; | |
| text-align: center; | |
| } | |
| .stats h3 { | |
| font-size: 1.5em; | |
| margin-bottom: 20px; | |
| } | |
| .stats-grid { | |
| display: grid; | |
| grid-template-columns: repeat(auto-fit, minmax(200px, 1fr)); | |
| gap: 20px; | |
| } | |
| .stat-item { | |
| background: rgba(255, 255, 255, 0.2); | |
| padding: 20px; | |
| border-radius: 10px; | |
| } | |
| .stat-value { | |
| font-size: 2em; | |
| font-weight: bold; | |
| margin: 10px 0; | |
| } | |
| .stat-label { | |
| font-size: 0.9em; | |
| opacity: 0.9; | |
| } | |
| .error { | |
| background: #f8d7da; | |
| color: #721c24; | |
| padding: 20px; | |
| border-radius: 10px; | |
| margin: 20px 0; | |
| display: none; | |
| } | |
| .footer { | |
| background: #f8f9fa; | |
| padding: 30px; | |
| text-align: center; | |
| color: #6c757d; | |
| margin-top: 40px; | |
| } | |
| @media (max-width: 768px) { | |
| .header h1 { | |
| font-size: 1.8em; | |
| } | |
| .results-grid { | |
| grid-template-columns: 1fr; | |
| } | |
| .content { | |
| padding: 20px; | |
| } | |
| } | |
| </style> | |
| </head> | |
| <body> | |
| <div class="container"> | |
| <div class="header"> | |
| <h1> | |
| <span>🧠</span> | |
| Brain Tumor Segmentation | |
| <span>🔬</span> | |
| </h1> | |
| <p>AI-Powered Medical Image Analysis for Brain MRI Scans</p> | |
| </div> | |
| <div class="content"> | |
| <!-- Info Section --> | |
| <div class="info-section"> | |
| <p style="color: #495057; font-size: 1.05em; line-height: 1.6; margin-bottom: 15px;"> | |
| <strong>🧠 This app performs automatic brain tumor segmentation</strong> using a U-Net deep learning model trained on BraTS dataset. | |
| Upload a <strong>.mha brain MRI file</strong> (FLAIR modality) and get pixel-level tumor detection with visualization. | |
| </p> | |
| <a href="https://github.com/koesan/Brain_Segmentation" target="_blank" class="github-link"> | |
| <svg width="24" height="24" viewBox="0 0 24 24" fill="currentColor"> | |
| <path d="M12 0c-6.626 0-12 5.373-12 12 0 5.302 3.438 9.8 8.207 11.387.599.111.793-.261.793-.577v-2.234c-3.338.726-4.033-1.416-4.033-1.416-.546-1.387-1.333-1.756-1.333-1.756-1.089-.745.083-.729.083-.729 1.205.084 1.839 1.237 1.839 1.237 1.07 1.834 2.807 1.304 3.492.997.107-.775.418-1.305.762-1.604-2.665-.305-5.467-1.334-5.467-5.931 0-1.311.469-2.381 1.236-3.221-.124-.303-.535-1.524.117-3.176 0 0 1.008-.322 3.301 1.23.957-.266 1.983-.399 3.003-.404 1.02.005 2.047.138 3.006.404 2.291-1.552 3.297-1.23 3.297-1.23.653 1.653.242 2.874.118 3.176.77.84 1.235 1.911 1.235 3.221 0 4.609-2.807 5.624-5.479 5.921.43.372.823 1.102.823 2.222v3.293c0 .319.192.694.801.576 4.765-1.589 8.199-6.086 8.199-11.386 0-6.627-5.373-12-12-12z"/> | |
| </svg> | |
| View on GitHub | |
| </a> | |
| </div> | |
| <div class="upload-section" id="dropZone"> | |
| <div class="upload-icon">📤</div> | |
| <h2 style="color: #667eea; margin-bottom: 15px;">Upload Brain MRI Scan (.mha)</h2> | |
| <p style="color: #6c757d; margin-bottom: 20px;"> | |
| Drag and drop your .mha MRI file here or click to browse | |
| </p> | |
| <div class="file-input-wrapper"> | |
| <input type="file" id="fileInput" accept=".mha"> | |
| <label for="fileInput" class="file-input-label"> | |
| Choose .mha File | |
| </label> | |
| <button class="example-btn" onclick="testExample()"> | |
| 🧪 Test Example | |
| </button> | |
| </div> | |
| <div class="selected-file" id="selectedFile"></div> | |
| <button class="analyze-btn" id="analyzeBtn" onclick="analyzeBrain()" disabled> | |
| Analyze Brain Scan | |
| </button> | |
| </div> | |
| <div class="loading" id="loading"> | |
| <div class="spinner"></div> | |
| <p style="color: #667eea; font-size: 1.2em;">Analyzing brain scan...</p> | |
| </div> | |
| <div class="error" id="error"></div> | |
| <div class="results" id="results"> | |
| <h2 style="color: #667eea; margin-bottom: 20px;">Segmentation Results</h2> | |
| <div class="results-grid"> | |
| <div class="result-card"> | |
| <h3>🖼️ Original MRI</h3> | |
| <img id="originalImg" src="" alt="Original"> | |
| </div> | |
| <div class="result-card"> | |
| <h3>🎯 Tumor Mask</h3> | |
| <img id="maskImg" src="" alt="Mask"> | |
| </div> | |
| <div class="result-card"> | |
| <h3>🔍 Overlay</h3> | |
| <img id="overlayImg" src="" alt="Overlay"> | |
| </div> | |
| </div> | |
| <div class="stats"> | |
| <h3>📊 Analysis Statistics</h3> | |
| <div class="stats-grid"> | |
| <div class="stat-item"> | |
| <div class="stat-label">Tumor Coverage</div> | |
| <div class="stat-value" id="tumorPercentage">-</div> | |
| <div class="stat-label">of brain area</div> | |
| </div> | |
| <div class="stat-item"> | |
| <div class="stat-label">Image Resolution</div> | |
| <div class="stat-value" id="imageSize">-</div> | |
| <div class="stat-label">pixels</div> | |
| </div> | |
| </div> | |
| </div> | |
| </div> | |
| </div> | |
| <div class="footer"> | |
| <p>⚠️ For research and educational purposes only. Not for clinical diagnosis.</p> | |
| <p style="margin-top: 10px;">Powered by Deep Learning | TensorFlow & Keras</p> | |
| </div> | |
| </div> | |
| <script> | |
| let selectedFile = null; | |
| // File input change handler | |
| document.getElementById('fileInput').addEventListener('change', function(e) { | |
| if (e.target.files.length > 0) { | |
| selectedFile = e.target.files[0]; | |
| document.getElementById('selectedFile').textContent = '✓ ' + selectedFile.name; | |
| document.getElementById('analyzeBtn').disabled = false; | |
| hideResults(); | |
| } | |
| }); | |
| // Drag and drop handlers | |
| const dropZone = document.getElementById('dropZone'); | |
| dropZone.addEventListener('dragover', (e) => { | |
| e.preventDefault(); | |
| dropZone.classList.add('dragover'); | |
| }); | |
| dropZone.addEventListener('dragleave', () => { | |
| dropZone.classList.remove('dragover'); | |
| }); | |
| dropZone.addEventListener('drop', (e) => { | |
| e.preventDefault(); | |
| dropZone.classList.remove('dragover'); | |
| const files = e.dataTransfer.files; | |
| if (files.length > 0) { | |
| selectedFile = files[0]; | |
| document.getElementById('fileInput').files = files; | |
| document.getElementById('selectedFile').textContent = '✓ ' + selectedFile.name; | |
| document.getElementById('analyzeBtn').disabled = false; | |
| hideResults(); | |
| } | |
| }); | |
| // Test with example MHA file | |
| function testExample() { | |
| // Show loading | |
| document.getElementById('loading').style.display = 'block'; | |
| document.getElementById('results').style.display = 'none'; | |
| document.getElementById('error').style.display = 'none'; | |
| document.getElementById('selectedFile').textContent = '🧪 Testing with example MRI...'; | |
| fetch('/test-example', { | |
| method: 'POST' | |
| }) | |
| .then(response => response.json()) | |
| .then(data => { | |
| if (data.error) { | |
| showError(data.error); | |
| } else { | |
| document.getElementById('selectedFile').textContent = '✓ Example: VSD.Brain.XX.O.MR_Flair.35796.mha'; | |
| showResults(data); | |
| } | |
| }) | |
| .catch(error => { | |
| showError('Example test failed: ' + error.message); | |
| }) | |
| .finally(() => { | |
| document.getElementById('loading').style.display = 'none'; | |
| }); | |
| } | |
| // Analyze brain scan | |
| function analyzeBrain() { | |
| if (!selectedFile) { | |
| showError('Please select a file first'); | |
| return; | |
| } | |
| const formData = new FormData(); | |
| formData.append('file', selectedFile); | |
| // Show loading | |
| document.getElementById('loading').style.display = 'block'; | |
| document.getElementById('results').style.display = 'none'; | |
| document.getElementById('error').style.display = 'none'; | |
| document.getElementById('analyzeBtn').disabled = true; | |
| fetch('/predict', { | |
| method: 'POST', | |
| body: formData | |
| }) | |
| .then(response => response.json()) | |
| .then(data => { | |
| if (data.error) { | |
| showError(data.error); | |
| } else { | |
| showResults(data); | |
| } | |
| }) | |
| .catch(error => { | |
| showError('Analysis failed: ' + error.message); | |
| }) | |
| .finally(() => { | |
| document.getElementById('loading').style.display = 'none'; | |
| document.getElementById('analyzeBtn').disabled = false; | |
| }); | |
| } | |
| // Show results | |
| function showResults(data) { | |
| document.getElementById('originalImg').src = data.original; | |
| document.getElementById('maskImg').src = data.mask; | |
| document.getElementById('overlayImg').src = data.overlay; | |
| document.getElementById('tumorPercentage').textContent = data.tumor_percentage.toFixed(2) + '%'; | |
| document.getElementById('imageSize').textContent = data.image_size; | |
| document.getElementById('results').style.display = 'block'; | |
| // Scroll to results | |
| document.getElementById('results').scrollIntoView({ behavior: 'smooth' }); | |
| } | |
| // Show error | |
| function showError(message) { | |
| document.getElementById('error').textContent = '❌ ' + message; | |
| document.getElementById('error').style.display = 'block'; | |
| setTimeout(() => { | |
| document.getElementById('error').style.display = 'none'; | |
| }, 5000); | |
| } | |
| // Hide results | |
| function hideResults() { | |
| document.getElementById('results').style.display = 'none'; | |
| document.getElementById('error').style.display = 'none'; | |
| } | |
| </script> | |
| </body> | |
| </html> | |