Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Web Application for Alzheimers Detection #561

Merged
merged 18 commits into from
May 16, 2024
Merged
Binary file added Alzheimers Detection/Images/image.jpg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added Alzheimers Detection/Model/model.h5
Binary file not shown.
69 changes: 69 additions & 0 deletions Alzheimers Detection/Web-App/app.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,69 @@
import streamlit as st
from PIL import Image
import numpy as np
import os
import tempfile
import tensorflow as tf

# Function to load the model
@st.cache_resource
def load_model():
script_dir = os.path.dirname(__file__)
rel_path = 'model.h5'
abs_model_path = os.path.join(script_dir, rel_path)
model = tf.keras.models.load_model(abs_model_path)
return model


model = load_model()

st.title("Alzheimer's Detection")

st.header("About Alzheimer's Disease")
st.write("""
Alzheimer's disease is a progressive neurologic disorder that causes the brain to shrink (atrophy) and brain cells to die.
Alzheimer's disease is the most common cause of dementia — a continuous decline in thinking, behavioral and social skills
that affects a person's ability to function independently.
The disease is classified into different stages based on the severity of symptoms: Mild Demented, Moderate Demented,
Non Demented, and Very Mild Demented.
""")

st.header("Sample Image")
script_dir = os.path.dirname(__file__)
rel_path = "../Images/image.jpg"
abs_file_path = os.path.join(script_dir, rel_path)
try:
image = Image.open(abs_file_path)
st.image(image, caption='Sample Brain Scan Image')
except Exception as e:
st.write(f"Error loading image: {e}")

st.header("Upload Your MRI Scan")
scan = st.file_uploader("Choose an image...", type=["jpg", "jpeg", "png"])

def preprocess_image(image, target_size):
image = image.convert("RGB")
image = image.resize(target_size)
image_array = tf.keras.preprocessing.image.img_to_array(image)
image_array = np.expand_dims(image_array, axis=0)
return image_array

if scan is not None:
if st.button('Upload'):
try:
with tempfile.NamedTemporaryFile(delete=False) as tmp_file:
tmp_file.write(scan.read())
tmp_path = tmp_file.name

img = Image.open(tmp_path)
st.image(img, caption='Uploaded Brain Scan Image')
img_array = preprocess_image(img, target_size=(176, 176))
predictions = model.predict(img_array)
predicted_class = np.argmax(predictions, axis=1)
class_labels = ['MildDemented', 'ModerateDemented', 'NonDemented', 'VeryMildDemented']
result = class_labels[predicted_class[0]]
st.markdown(f'<h3 style="color: red;">Prediction: {result}</h3>', unsafe_allow_html=True)

os.remove(tmp_path)
except Exception as e:
st.write(f"Error processing uploaded image: {e}")
Binary file added Alzheimers Detection/Web-App/demo.mp4
Binary file not shown.
Binary file added Alzheimers Detection/Web-App/model.h5
Binary file not shown.
18 changes: 18 additions & 0 deletions Alzheimers Detection/Web-App/readme.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
# Alzheimer's Detection Web Application

## Goal 🎯
The main goal of this project is to provide a user-friendly web application for the detection of Alzheimer's disease using deep learning models. The application aims to assist healthcare professionals in accurately diagnosing Alzheimer's disease in patients based on brain scan images.

## Model Used for the Web App 🧮
The web application utilizes a deep learning model trained for Alzheimer's detection. The model architecture includes convolutional, separable convolutional, batch normalization, max pooling, dropout, and dense layers. It is trained on a dataset of brain MRI images representing different stages of Alzheimer's disease.


## Features of the Web App 🌐
- **Sample Image Display**: Displays a sample brain scan image for reference.
- **Upload MRI Scan**: Allows users to upload their MRI scan images for Alzheimer's detection.
- **Prediction Display**: Provides predictions for Alzheimer's disease based on the uploaded MRI scan images.
- **About Alzheimer's Disease**: Offers information about Alzheimer's disease, including its causes, symptoms, and stages.
<video controls src="demo.mp4" title="Title"></video>

## Signature ✒️
Aindree
Loading