Spaces:
Sleeping
Sleeping
| <html lang="en"> | |
| <head> | |
| <meta charset="UTF-8"> | |
| <meta name="viewport" content="width=device-width, initial-scale=1.0"> | |
| <title>Breast Cancer Classification - AI Diagnostic Tool</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; | |
| } | |
| .container { | |
| max-width: 900px; | |
| margin: 0 auto; | |
| background: white; | |
| 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: 30px; | |
| text-align: center; | |
| } | |
| .header h1 { | |
| font-size: 2.5em; | |
| margin-bottom: 10px; | |
| } | |
| .header p { | |
| font-size: 1.1em; | |
| opacity: 0.9; | |
| } | |
| .content { | |
| padding: 40px; | |
| } | |
| .info-box { | |
| background: #f8f9fa; | |
| border-left: 4px solid #667eea; | |
| padding: 20px; | |
| margin-bottom: 30px; | |
| border-radius: 8px; | |
| } | |
| .info-box h3 { | |
| color: #667eea; | |
| margin-bottom: 10px; | |
| } | |
| .info-box ul { | |
| margin-left: 20px; | |
| line-height: 1.8; | |
| } | |
| .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: 2px solid #667eea; | |
| border-radius: 8px; | |
| transition: all 0.3s; | |
| margin: 20px 0; | |
| } | |
| .github-link:hover { | |
| transform: translateY(-2px); | |
| box-shadow: 0 4px 12px rgba(102, 126, 234, 0.3); | |
| background: #667eea; | |
| color: white; | |
| } | |
| .test-button { | |
| background: #6c757d; | |
| color: white; | |
| padding: 12px 30px; | |
| border: none; | |
| border-radius: 25px; | |
| font-size: 1.1em; | |
| cursor: pointer; | |
| transition: transform 0.2s; | |
| margin-left: 10px; | |
| } | |
| .test-button:hover { | |
| background: #5a6268; | |
| transform: scale(1.05); | |
| } | |
| .result-image-container { | |
| position: relative; | |
| margin-bottom: 20px; | |
| } | |
| .result-image { | |
| max-width: 100%; | |
| max-height: 300px; | |
| border-radius: 10px; | |
| box-shadow: 0 5px 15px rgba(0,0,0,0.2); | |
| } | |
| .result-overlay { | |
| position: absolute; | |
| top: 10px; | |
| left: 50%; | |
| transform: translateX(-50%); | |
| background: rgba(0, 0, 0, 0.8); | |
| color: white; | |
| padding: 10px 20px; | |
| border-radius: 8px; | |
| font-size: 1.2em; | |
| font-weight: bold; | |
| } | |
| .upload-section { | |
| text-align: center; | |
| padding: 40px; | |
| border: 3px dashed #667eea; | |
| border-radius: 15px; | |
| margin-bottom: 30px; | |
| transition: all 0.3s; | |
| cursor: pointer; | |
| } | |
| .upload-section:hover { | |
| border-color: #764ba2; | |
| background: #f8f9fa; | |
| } | |
| .upload-section.drag-over { | |
| background: #e3f2fd; | |
| border-color: #2196F3; | |
| } | |
| .upload-icon { | |
| font-size: 4em; | |
| color: #667eea; | |
| margin-bottom: 20px; | |
| } | |
| .upload-text { | |
| font-size: 1.2em; | |
| color: #666; | |
| margin-bottom: 15px; | |
| } | |
| .file-input { | |
| display: none; | |
| } | |
| .upload-button { | |
| background: linear-gradient(135deg, #667eea 0%, #764ba2 100%); | |
| color: white; | |
| padding: 12px 30px; | |
| border: none; | |
| border-radius: 25px; | |
| font-size: 1.1em; | |
| cursor: pointer; | |
| transition: transform 0.2s; | |
| } | |
| .upload-button:hover { | |
| transform: scale(1.05); | |
| } | |
| .preview-section { | |
| display: none; | |
| margin-bottom: 30px; | |
| } | |
| .preview-image { | |
| max-width: 100%; | |
| max-height: 400px; | |
| border-radius: 10px; | |
| box-shadow: 0 5px 15px rgba(0,0,0,0.2); | |
| display: block; | |
| margin: 0 auto; | |
| } | |
| .result-section { | |
| display: none; | |
| padding: 30px; | |
| border-radius: 15px; | |
| text-align: center; | |
| } | |
| .result-benign { | |
| background: linear-gradient(135deg, #11998e 0%, #38ef7d 100%); | |
| color: white; | |
| } | |
| .result-malignant { | |
| background: linear-gradient(135deg, #ee0979 0%, #ff6a00 100%); | |
| color: white; | |
| } | |
| .result-title { | |
| font-size: 2em; | |
| margin-bottom: 20px; | |
| } | |
| .confidence-bar { | |
| background: rgba(255,255,255,0.3); | |
| border-radius: 10px; | |
| height: 30px; | |
| margin: 20px 0; | |
| position: relative; | |
| overflow: hidden; | |
| } | |
| .confidence-fill { | |
| height: 100%; | |
| background: white; | |
| border-radius: 10px; | |
| transition: width 1s ease; | |
| display: flex; | |
| align-items: center; | |
| justify-content: center; | |
| color: #667eea; | |
| font-weight: bold; | |
| } | |
| .probabilities { | |
| display: flex; | |
| justify-content: space-around; | |
| margin-top: 20px; | |
| } | |
| .prob-item { | |
| flex: 1; | |
| padding: 15px; | |
| background: rgba(255,255,255,0.2); | |
| border-radius: 10px; | |
| margin: 0 10px; | |
| } | |
| .prob-label { | |
| font-size: 0.9em; | |
| margin-bottom: 5px; | |
| } | |
| .prob-value { | |
| font-size: 1.8em; | |
| font-weight: bold; | |
| } | |
| .loading { | |
| display: none; | |
| text-align: center; | |
| padding: 30px; | |
| } | |
| .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); } | |
| } | |
| .error { | |
| display: none; | |
| background: #ff5252; | |
| color: white; | |
| padding: 15px; | |
| border-radius: 10px; | |
| margin-bottom: 20px; | |
| } | |
| .try-again-button { | |
| background: white; | |
| color: #667eea; | |
| padding: 12px 30px; | |
| border: none; | |
| border-radius: 25px; | |
| font-size: 1.1em; | |
| cursor: pointer; | |
| margin-top: 20px; | |
| transition: transform 0.2s; | |
| } | |
| .try-again-button:hover { | |
| transform: scale(1.05); | |
| } | |
| .note { | |
| background: #fff3cd; | |
| border-left: 4px solid #ffc107; | |
| padding: 15px; | |
| margin-top: 30px; | |
| border-radius: 8px; | |
| font-size: 0.9em; | |
| } | |
| .footer { | |
| background: #f8f9fa; | |
| padding: 20px; | |
| text-align: center; | |
| color: #666; | |
| font-size: 0.9em; | |
| } | |
| </style> | |
| </head> | |
| <body> | |
| <div class="container"> | |
| <div class="header"> | |
| <h1>🔬 Breast Cancer Classification</h1> | |
| <p>AI-Powered Mammogram Analysis</p> | |
| </div> | |
| <div class="content"> | |
| <div class="info-box"> | |
| <h3>📋 How to Use This Tool</h3> | |
| <ul> | |
| <li><strong>Upload Image:</strong> Click the upload area or drag & drop a mammogram image</li> | |
| <li><strong>Supported Formats:</strong> JPG, JPEG, PNG</li> | |
| <li><strong>Image Requirements:</strong> Clear mammogram image, preferably full breast view</li> | |
| <li><strong>Classification:</strong> The AI will classify the image as Benign (non-cancerous) or Malignant (cancerous)</li> | |
| <li><strong>Confidence Score:</strong> Shows the model's confidence in its prediction</li> | |
| </ul> | |
| </div> | |
| <div class="info-box"> | |
| <h3>🤖 About the Model</h3> | |
| <p>This tool uses an integrated ensemble of VGG16 and ResNet50V2 deep learning models trained on the CBIS-DDSM dataset. The model combines transfer learning with custom classification layers to analyze mammogram images and predict breast cancer classification.</p> | |
| <div style="margin-top: 15px;"> | |
| <a href="https://github.com/koesan/Breast_Cancer_Classification" 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> | |
| <div class="error" id="errorMessage"></div> | |
| <div class="upload-section" id="uploadSection"> | |
| <div class="upload-icon">📤</div> | |
| <div class="upload-text">Drag & Drop your mammogram image here</div> | |
| <div style="margin: 20px 0;">or</div> | |
| <input type="file" id="fileInput" class="file-input" accept="image/*"> | |
| <button class="upload-button" onclick="document.getElementById('fileInput').click()"> | |
| Choose File | |
| </button> | |
| <button class="test-button" onclick="testExample()"> | |
| 🧪 Test Example | |
| </button> | |
| </div> | |
| <div class="preview-section" id="previewSection"> | |
| <h3 style="margin-bottom: 15px;">Uploaded Image:</h3> | |
| <img id="previewImage" class="preview-image" alt="Preview"> | |
| <div style="text-align: center; margin-top: 20px;"> | |
| <button class="upload-button" onclick="analyzeImage()"> | |
| 🔍 Analyze Image | |
| </button> | |
| </div> | |
| </div> | |
| <div class="loading" id="loading"> | |
| <div class="spinner"></div> | |
| <p>Analyzing mammogram image...</p> | |
| </div> | |
| <div class="result-section" id="resultSection"> | |
| <div class="result-image-container" id="resultImageContainer" style="display: none;"> | |
| <img id="resultImage" class="result-image" alt="Result"> | |
| <div class="result-overlay" id="resultOverlay"></div> | |
| </div> | |
| <div class="result-title" id="resultTitle"></div> | |
| <div class="confidence-bar"> | |
| <div class="confidence-fill" id="confidenceFill"></div> | |
| </div> | |
| <div class="probabilities"> | |
| <div class="prob-item"> | |
| <div class="prob-label">Benign Probability</div> | |
| <div class="prob-value" id="benignProb">-</div> | |
| </div> | |
| <div class="prob-item"> | |
| <div class="prob-label">Malignant Probability</div> | |
| <div class="prob-value" id="malignantProb">-</div> | |
| </div> | |
| </div> | |
| <button class="try-again-button" onclick="resetAnalysis()"> | |
| 🔄 Analyze Another Image | |
| </button> | |
| </div> | |
| <div class="note"> | |
| <strong>⚠️ Important Notice:</strong> This is an AI diagnostic assistance tool for educational and research purposes. It should NOT be used as a substitute for professional medical diagnosis. Always consult with qualified healthcare professionals for medical advice and diagnosis. | |
| </div> | |
| </div> | |
| <div class="footer"> | |
| <p>Powered by VGG16 + ResNet50V2 Ensemble Model | CBIS-DDSM Dataset</p> | |
| <p>© 2025 Breast Cancer Classification Project</p> | |
| </div> | |
| </div> | |
| <script> | |
| let selectedFile = null; | |
| // File input change handler | |
| document.getElementById('fileInput').addEventListener('change', function(e) { | |
| handleFile(e.target.files[0]); | |
| }); | |
| // Drag and drop handlers | |
| const uploadSection = document.getElementById('uploadSection'); | |
| uploadSection.addEventListener('dragover', function(e) { | |
| e.preventDefault(); | |
| uploadSection.classList.add('drag-over'); | |
| }); | |
| uploadSection.addEventListener('dragleave', function(e) { | |
| e.preventDefault(); | |
| uploadSection.classList.remove('drag-over'); | |
| }); | |
| uploadSection.addEventListener('drop', function(e) { | |
| e.preventDefault(); | |
| uploadSection.classList.remove('drag-over'); | |
| handleFile(e.dataTransfer.files[0]); | |
| }); | |
| function handleFile(file) { | |
| if (!file) return; | |
| // Check if file is an image | |
| if (!file.type.startsWith('image/')) { | |
| showError('Please upload a valid image file (JPG, JPEG, PNG)'); | |
| return; | |
| } | |
| selectedFile = file; | |
| // Show preview | |
| const reader = new FileReader(); | |
| reader.onload = function(e) { | |
| document.getElementById('previewImage').src = e.target.result; | |
| document.getElementById('uploadSection').style.display = 'none'; | |
| document.getElementById('previewSection').style.display = 'block'; | |
| document.getElementById('errorMessage').style.display = 'none'; | |
| }; | |
| reader.readAsDataURL(file); | |
| } | |
| async function analyzeImage() { | |
| if (!selectedFile) return; | |
| // Show loading | |
| document.getElementById('previewSection').style.display = 'none'; | |
| document.getElementById('loading').style.display = 'block'; | |
| // Create FormData | |
| const formData = new FormData(); | |
| formData.append('file', selectedFile); | |
| try { | |
| const response = await fetch('/predict', { | |
| method: 'POST', | |
| body: formData | |
| }); | |
| const data = await response.json(); | |
| if (response.ok) { | |
| showResult(data); | |
| } else { | |
| showError(data.error || 'An error occurred during analysis'); | |
| } | |
| } catch (error) { | |
| showError('Failed to connect to the server. Please try again.'); | |
| } finally { | |
| document.getElementById('loading').style.display = 'none'; | |
| } | |
| } | |
| function testExample() { | |
| // Show loading | |
| document.getElementById('loading').style.display = 'block'; | |
| document.getElementById('uploadSection').style.display = 'none'; | |
| document.getElementById('previewSection').style.display = 'none'; | |
| document.getElementById('resultSection').style.display = 'none'; | |
| document.getElementById('errorMessage').style.display = 'none'; | |
| fetch('/test-example', { | |
| method: 'POST' | |
| }) | |
| .then(response => response.json()) | |
| .then(data => { | |
| document.getElementById('loading').style.display = 'none'; | |
| if (data.error) { | |
| showError(data.error); | |
| } else { | |
| showResult(data, true); | |
| } | |
| }) | |
| .catch(error => { | |
| document.getElementById('loading').style.display = 'none'; | |
| showError('Failed to analyze example: ' + error.message); | |
| }); | |
| } | |
| function showResult(data, showImage = false) { | |
| const resultSection = document.getElementById('resultSection'); | |
| const resultTitle = document.getElementById('resultTitle'); | |
| const confidenceFill = document.getElementById('confidenceFill'); | |
| const benignProb = document.getElementById('benignProb'); | |
| const malignantProb = document.getElementById('malignantProb'); | |
| const resultImageContainer = document.getElementById('resultImageContainer'); | |
| const resultImage = document.getElementById('resultImage'); | |
| const resultOverlay = document.getElementById('resultOverlay'); | |
| // Show image if available | |
| if (showImage && data.image) { | |
| resultImage.src = data.image; | |
| resultOverlay.textContent = data.class; | |
| resultImageContainer.style.display = 'block'; | |
| } else { | |
| resultImageContainer.style.display = 'none'; | |
| } | |
| // Update content | |
| resultTitle.textContent = `Classification: ${data.class}`; | |
| confidenceFill.style.width = data.confidence.toFixed(2) + '%'; | |
| confidenceFill.textContent = data.confidence.toFixed(2) + '%'; | |
| benignProb.textContent = data.benign_prob.toFixed(2) + '%'; | |
| malignantProb.textContent = data.malignant_prob.toFixed(2) + '%'; | |
| // Update styling based on classification | |
| if (data.class === 'Benign') { | |
| resultSection.className = 'result-section result-benign'; | |
| } else { | |
| resultSection.className = 'result-section result-malignant'; | |
| } | |
| resultSection.style.display = 'block'; | |
| } | |
| function showError(message) { | |
| const errorElement = document.getElementById('errorMessage'); | |
| errorElement.textContent = '❌ Error: ' + message; | |
| errorElement.style.display = 'block'; | |
| document.getElementById('uploadSection').style.display = 'block'; | |
| document.getElementById('loading').style.display = 'none'; | |
| } | |
| function resetAnalysis() { | |
| selectedFile = null; | |
| document.getElementById('fileInput').value = ''; | |
| document.getElementById('uploadSection').style.display = 'block'; | |
| document.getElementById('previewSection').style.display = 'none'; | |
| document.getElementById('resultSection').style.display = 'none'; | |
| document.getElementById('errorMessage').style.display = 'none'; | |
| } | |
| </script> | |
| </body> | |
| </html> | |