diff --git a/api/detect.php b/api/detect.php new file mode 100644 index 0000000..b2430ea --- /dev/null +++ b/api/detect.php @@ -0,0 +1,72 @@ + true, + 'prediction' => $ml_response['label'], + 'confidence' => $ml_response['confidence'], + 'filename' => htmlspecialchars($safeName) + ]; + } else { + $response = ['success' => false, 'error' => 'ML script returned invalid data.']; + } + } else { + $response = ['success' => false, 'error' => 'Failed to execute the ML model script. Check server logs for details.']; + } + } else { + $response = ['success' => false, 'error' => 'Failed to save the uploaded file. Check directory permissions.']; + } +} else { + // Handle various upload errors + $uploadErrors = [ + UPLOAD_ERR_INI_SIZE => 'File is too large (server limit).', + UPLOAD_ERR_FORM_SIZE => 'File is too large (form limit).', + UPLOAD_ERR_PARTIAL => 'File was only partially uploaded.', + UPLOAD_ERR_NO_FILE => 'No file was uploaded.', + UPLOAD_ERR_NO_TMP_DIR => 'Missing a temporary folder.', + UPLOAD_ERR_CANT_WRITE => 'Failed to write file to disk.', + UPLOAD_ERR_EXTENSION => 'A PHP extension stopped the file upload.', + ]; + $errorCode = $_FILES['mri_image']['error'] ?? UPLOAD_ERR_NO_FILE; + $errorMsg = $uploadErrors[$errorCode] ?? 'An unknown upload error occurred.'; + $response = ['success' => false, 'error' => $errorMsg]; +} + +echo json_encode($response); diff --git a/assets/css/custom.css b/assets/css/custom.css new file mode 100644 index 0000000..ae38a62 --- /dev/null +++ b/assets/css/custom.css @@ -0,0 +1,113 @@ +/* Custom Styles for NeuroDetect */ +body { + font-family: 'Inter', sans-serif; + display: flex; + flex-direction: column; + min-height: 100vh; +} + +.navbar-brand { + letter-spacing: -0.5px; +} + +.hero-section { + padding: 6rem 0; + background-color: #ffffff; + background-image: linear-gradient(to bottom, rgba(233, 242, 255, 0.5), #ffffff); +} + +.hero-section .display-4 { + font-weight: 700; + color: #0d244f; +} + +.hero-section .lead { + max-width: 600px; + margin-left: auto; + margin-right: auto; + color: #495057; +} + +.btn-primary { + background-color: #0D6EFD; + border-color: #0D6EFD; + padding: 0.75rem 1.5rem; + font-weight: 500; + transition: background-color 0.2s ease-in-out, border-color 0.2s ease-in-out; +} + +.btn-primary:hover { + background-color: #0b5ed7; + border-color: #0a58ca; +} + +.section-title { + font-weight: 600; + color: #0d244f; + margin-bottom: 2rem; +} + +.intro-text { + line-height: 1.8; +} + +.image-gallery .card { + border: none; + box-shadow: 0 4px 12px rgba(0,0,0,0.08); + transition: transform 0.2s ease-in-out, box-shadow 0.2s ease-in-out; +} + +.image-gallery .card:hover { + transform: translateY(-5px); + box-shadow: 0 8px 20px rgba(0,0,0,0.12); +} + +.image-gallery .card-img-top { + height: 220px; + object-fit: cover; +} + +footer { + background-color: #ffffff; +} + +/* Detection Page Styles */ +.upload-card, .result-card { + height: 100%; +} + +.upload-box { + border: 2px dashed #dee2e6; + border-radius: 0.5rem; + padding: 2rem; + text-align: center; + cursor: pointer; + transition: background-color 0.2s ease-in-out, border-color 0.2s ease-in-out; +} + +.upload-box:hover, .upload-box.dragover { + background-color: #f8f9fa; + border-color: #0D6EFD; +} + +.upload-icon { + font-size: 3rem; + color: #0D6EFD; +} + +.upload-text { + margin-top: 1rem; + color: #6c757d; +} + +#analyze-btn:disabled { + cursor: not-allowed; +} + +#result-display .progress-bar { + transition: width 0.5s ease-in-out; +} + +.result-card .section-title { + margin-bottom: 1.5rem; +} diff --git a/assets/js/main.js b/assets/js/main.js new file mode 100644 index 0000000..b2ece75 --- /dev/null +++ b/assets/js/main.js @@ -0,0 +1,122 @@ +console.log("NeuroDetect main.js loaded."); + +document.addEventListener('DOMContentLoaded', function () { + const uploadBox = document.getElementById('upload-box'); + const mriImageInput = document.getElementById('mri_image'); + const selectFileBtn = document.getElementById('select-file-btn'); + const analyzeBtn = document.getElementById('analyze-btn'); + const imagePreviewContainer = document.getElementById('image-preview-container'); + const imagePreview = document.getElementById('image-preview'); + const removeImageBtn = document.getElementById('remove-image-btn'); + const uploadForm = document.getElementById('upload-form'); + const resultPlaceholder = document.getElementById('result-placeholder'); + const resultDisplay = document.getElementById('result-display'); + const predictionResult = document.getElementById('prediction-result'); + const confidenceBar = document.getElementById('confidence-bar'); + + function handleFileSelect(file) { + if (file && file.type.startsWith('image/')) { + const reader = new FileReader(); + reader.onload = function (e) { + imagePreview.src = e.target.result; + imagePreviewContainer.style.display = 'block'; + uploadBox.style.display = 'none'; + analyzeBtn.disabled = false; + }; + reader.readAsDataURL(file); + } + } + + if (uploadBox) { + uploadBox.addEventListener('click', () => mriImageInput.click()); + selectFileBtn.addEventListener('click', () => mriImageInput.click()); + + mriImageInput.addEventListener('change', (e) => { + handleFileSelect(e.target.files[0]); + }); + + uploadBox.addEventListener('dragover', (e) => { + e.preventDefault(); + e.stopPropagation(); + uploadBox.classList.add('dragover'); + }); + + uploadBox.addEventListener('dragleave', (e) => { + e.preventDefault(); + e.stopPropagation(); + uploadBox.classList.remove('dragover'); + }); + + uploadBox.addEventListener('drop', (e) => { + e.preventDefault(); + e.stopPropagation(); + uploadBox.classList.remove('dragover'); + const file = e.dataTransfer.files[0]; + mriImageInput.files = e.dataTransfer.files; + handleFileSelect(file); + }); + + removeImageBtn.addEventListener('click', () => { + mriImageInput.value = ''; + imagePreview.src = '#'; + imagePreviewContainer.style.display = 'none'; + uploadBox.style.display = 'block'; + analyzeBtn.disabled = true; + resultDisplay.style.display = 'none'; + resultPlaceholder.style.display = 'block'; + }); + + uploadForm.addEventListener('submit', function(e) { + e.preventDefault(); + analyzeBtn.disabled = true; + analyzeBtn.innerHTML = ' Analyzing...'; + + resultPlaceholder.style.display = 'block'; + resultDisplay.style.display = 'none'; + + const formData = new FormData(this); + + fetch('api/detect.php', { + method: 'POST', + body: formData + }) + .then(response => response.json()) + .then(data => { + if (data.success) { + predictionResult.textContent = data.prediction; + if (data.prediction === 'Alzheimer Detected') { + predictionResult.className = 'fw-bold text-danger'; + } else { + predictionResult.className = 'fw-bold text-success'; + } + + const confidencePercent = Math.round(data.confidence * 100); + confidenceBar.style.width = confidencePercent + '%'; + confidenceBar.textContent = confidencePercent + '%'; + confidenceBar.setAttribute('aria-valuenow', confidencePercent); + + if (confidencePercent > 85) { + confidenceBar.classList.remove('bg-warning'); + confidenceBar.classList.add('bg-primary'); + } else { + confidenceBar.classList.remove('bg-primary'); + confidenceBar.classList.add('bg-warning'); + } + + resultPlaceholder.style.display = 'none'; + resultDisplay.style.display = 'block'; + } else { + alert('Error: ' + data.error); + } + }) + .catch(error => { + console.error('Error:', error); + alert('An unexpected error occurred. Please try again.'); + }) + .finally(() => { + analyzeBtn.disabled = false; + analyzeBtn.innerHTML = 'Analyze Scan'; + }); + }); + } +}); \ No newline at end of file diff --git a/assets/pasted-20251104-131846-2dcc8857.png b/assets/pasted-20251104-131846-2dcc8857.png new file mode 100644 index 0000000..670bef2 Binary files /dev/null and b/assets/pasted-20251104-131846-2dcc8857.png differ diff --git a/detection.php b/detection.php new file mode 100644 index 0000000..07e268e --- /dev/null +++ b/detection.php @@ -0,0 +1,61 @@ + + +
+
+
+

MRI Scan Analysis

+

Upload a brain MRI scan to get a prediction for Alzheimer's disease. Our model will analyze the image and provide a result.

+
+
+ +
+
+
+
+
1. Upload Image
+
+
+ +

Drag & drop your MRI scan here, or click to select a file.

+ +
+
+ + +
+
+ +
+
+
+
+
+
+
2. Analysis Result
+
+ +

Your analysis results will appear here.

+
+ +
+
+
+
+
+ + \ No newline at end of file diff --git a/includes/footer.php b/includes/footer.php new file mode 100644 index 0000000..3dd48fc --- /dev/null +++ b/includes/footer.php @@ -0,0 +1,11 @@ + + + + + + \ No newline at end of file diff --git a/includes/header.php b/includes/header.php new file mode 100644 index 0000000..06d31e0 --- /dev/null +++ b/includes/header.php @@ -0,0 +1,44 @@ + + + + + + NeuroDetect - Alzheimer's Disease Detection + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/includes/pexels.php b/includes/pexels.php new file mode 100644 index 0000000..d2a75f8 --- /dev/null +++ b/includes/pexels.php @@ -0,0 +1,48 @@ + 0 ? $k : 'Vc99rnmOhHhJAbgGQoKLZtsaIVfkeownoQNbTj78VemUjKh08ZYRbf18'; +} + +function pexels_get($url) { + $ch = curl_init(); + curl_setopt_array($ch, [ + CURLOPT_URL => $url, + CURLOPT_RETURNTRANSFER => true, + CURLOPT_HTTPHEADER => [ 'Authorization: '. pexels_key() ], + CURLOPT_TIMEOUT => 20, + CURLOPT_USERAGENT => 'Flatlogic-Gemini-Agent/1.0' + ]); + $resp = curl_exec($ch); + $code = curl_getinfo($ch, CURLINFO_HTTP_CODE); + curl_close($ch); + if ($code >= 200 && $code < 300 && $resp) { + return json_decode($resp, true); + } + error_log("Pexels API request failed with code $code for URL: $url"); + return null; +} + +function download_to($srcUrl, $destPath) { + $dir = dirname($destPath); + if (!is_dir($dir)) { + if (!mkdir($dir, 0775, true)) { + error_log("Failed to create directory: $dir"); + return false; + } + } + + $data = @file_get_contents($srcUrl); + if ($data === false) { + error_log("Failed to download image from: $srcUrl"); + return false; + } + + if (file_put_contents($destPath, $data) === false) { + error_log("Failed to save image to: $destPath"); + return false; + } + return true; +} \ No newline at end of file diff --git a/index.php b/index.php index 7205f3d..9158d96 100644 --- a/index.php +++ b/index.php @@ -1,150 +1,100 @@ 'https://images.pexels.com/photos/40568/medical-instrument-brain-magnifying-glass-search-40568.jpeg?auto=compress&cs=tinysrgb&w=1260&h=750&dpr=1', + 'photographer' => 'Public Domain Pictures', + 'photographer_url' => 'https://www.pexels.com/@public-domain-pictures', + 'alt' => 'Brain MRI', + ], + [ + 'src' => 'https://images.pexels.com/photos/3825586/pexels-photo-3825586.jpeg?auto=compress&cs=tinysrgb&w=1260&h=750&dpr=1', + 'photographer' => 'ThisIsEngineering', + 'photographer_url' => 'https://www.pexels.com/@thisisengineering/', + 'alt' => 'Neurology Research', + ], + [ + 'src' => 'https://images.pexels.com/photos/6120403/pexels-photo-6120403.jpeg?auto=compress&cs=tinysrgb&w=1260&h=750&dpr=1', + 'photographer' => 'Kampus Production', + 'photographer_url' => 'https://www.pexels.com/@kampus-production/', + 'alt' => 'Senior Patient Care', + ], +]; + +include 'includes/header.php'; ?> - - - - - - New Style - - - - - - - - - - - - - - - - - - - - - -
-
-

Analyzing your requirements and generating your website…

-
- Loading… -
-

AI is collecting your requirements and applying the first changes.

-

This page will update automatically as the plan is implemented.

-

Runtime: PHP — UTC

-
-
- - - + +
+ +
+
+

Alzheimer’s Disease Detection

+

Utilizing machine learning for early detection of Alzheimer's disease, offering hope for better management and care.

+ Get Started +
+
+ + +
+
+
+
+

What is Alzheimer's Disease?

+

+ Alzheimer's disease is a progressive brain disorder that slowly destroys memory and thinking skills, and eventually, the ability to carry out the simplest tasks. In most people with the disease — those with the late-onset type — symptoms first appear in their mid-60s. +

+

+ Early detection is crucial as it allows for timely intervention, which can help manage symptoms and improve quality of life. Our project leverages the power of machine learning to analyze brain MRI scans, aiming to identify signs of Alzheimer's at an earlier stage. +

+
+
+ + <?php echo htmlspecialchars($images[0]['alt']); ?> + +
+
+
+
+ + +
+
+

Relevant Illustrations

+ +
+
+
+ + \ No newline at end of file diff --git a/ml/predict.py b/ml/predict.py new file mode 100644 index 0000000..7d0f284 --- /dev/null +++ b/ml/predict.py @@ -0,0 +1,38 @@ + +import json +import random +import sys +import time + +def main(): + """ + This is a placeholder Python script for ML model inference. + It simulates a model prediction by returning a random result. + + In a real-world application, this script would: + 1. Load a pre-trained machine learning model (e.g., from an .h5 or .pkl file). + 2. Pre-process the input image received from the command-line argument. + 3. Run the image through the model to get a prediction. + 4. Return the prediction results as a JSON string. + """ + # Simulate processing time + time.sleep(1.5) + + # Get image path from command line arguments (for context, not used in this placeholder) + image_path = sys.argv[1] if len(sys.argv) > 1 else "no_image_provided.jpg" + + # Possible outcomes + predictions = [ + {"label": "Alzheimer Detected", "confidence": round(random.uniform(0.75, 0.98), 2)}, + {"label": "Healthy", "confidence": round(random.uniform(0.80, 0.99), 2)} + ] + + # Choose a random result to simulate a real prediction + result = random.choice(predictions) + + # Output the result as a JSON string to be captured by the PHP script + print(json.dumps(result)) + +if __name__ == "__main__": + # This check ensures the main function runs only when the script is executed directly + main()