Spaces:
Sleeping
Sleeping
shamimjony1000
commited on
Update app.py
Browse files
app.py
CHANGED
@@ -1,187 +1,41 @@
|
|
1 |
import streamlit as st
|
2 |
-
import cv2
|
3 |
-
from PIL import Image, ImageEnhance
|
4 |
import numpy as np
|
5 |
-
import os
|
6 |
from tensorflow.keras.preprocessing import image
|
7 |
from tensorflow.keras.applications.efficientnet import preprocess_input
|
8 |
-
import numpy as np
|
9 |
import tensorflow as tf
|
10 |
-
import
|
11 |
-
|
12 |
|
13 |
def main():
|
14 |
st.set_page_config(
|
15 |
-
page_title="Alzheimer's
|
16 |
-
|
17 |
-
|
18 |
-
|
19 |
-
video_file = 'tech.mp4'
|
20 |
-
video_bytes = open(video_file, 'rb').read()
|
21 |
-
encoded_video = base64.b64encode(video_bytes).decode()
|
22 |
-
|
23 |
-
video_html = f"""
|
24 |
-
<style>
|
25 |
-
#myVideo {{
|
26 |
-
position: fixed;
|
27 |
-
right: 0;
|
28 |
-
bottom: 0;
|
29 |
-
min-width: 100%;
|
30 |
-
min-height: 100%;
|
31 |
-
}}
|
32 |
-
|
33 |
-
.content {{
|
34 |
-
position: fixed;
|
35 |
-
bottom: 0;
|
36 |
-
background: rgba(0, 0, 0, 0.5);
|
37 |
-
color: #f1f1f1;
|
38 |
-
width: 100%;
|
39 |
-
padding: 20px;
|
40 |
-
}}
|
41 |
-
</style>
|
42 |
-
<video autoplay muted loop id="myVideo">
|
43 |
-
<source src="data:video/mp4;base64,{encoded_video}" type="video/mp4">
|
44 |
-
Your browser does not support HTML5 video.
|
45 |
-
</video>
|
46 |
-
"""
|
47 |
-
st.markdown(video_html, unsafe_allow_html=True)
|
48 |
-
|
49 |
-
|
50 |
-
tasks = ['Detection', 'About']
|
51 |
-
choice = st.sidebar.selectbox('Select Task', tasks)
|
52 |
-
|
53 |
-
root_dir = os.path.dirname(os.path.abspath(__file__))
|
54 |
-
img_pth = os.path.join(root_dir, "333.jpg")
|
55 |
-
img = Image.open(img_pth)
|
56 |
-
|
57 |
-
if choice == 'Detection':
|
58 |
-
st.markdown("<h1 style='text-align: center; color: white;'><i>Alzheimer's Detection Tool🧠</i></h1>", unsafe_allow_html=True)
|
59 |
-
st.markdown("<h6 style='text-align: center; color: white;'><i>A stitch in time saves a nine!</i></h6>", unsafe_allow_html=True)
|
60 |
-
tasks = ["Alzheimer's"]
|
61 |
-
if tasks[0] == "Alzheimer's":
|
62 |
-
# Load the saved model
|
63 |
-
loaded_model = tf.keras.models.load_model("model.h5",compile=False)
|
64 |
-
|
65 |
-
def predict_image_class(img_path):
|
66 |
-
img = image.load_img(img_path, target_size=(224, 224))
|
67 |
-
img_array = image.img_to_array(img)
|
68 |
-
img_array = np.expand_dims(img_array, axis=0)
|
69 |
-
img_array = preprocess_input(img_array)
|
70 |
-
|
71 |
-
predictions = loaded_model.predict(img_array)
|
72 |
-
predicted_class = np.argmax(predictions, axis=1)[0]
|
73 |
-
|
74 |
-
return predicted_class
|
75 |
-
|
76 |
|
77 |
-
|
78 |
|
79 |
-
|
80 |
-
|
81 |
-
predicted_class = predict_image_class(uploaded_file)
|
82 |
|
83 |
-
|
84 |
-
|
85 |
-
|
|
|
|
|
86 |
|
87 |
-
|
|
|
88 |
|
89 |
-
|
90 |
-
st.markdown(f"<div style='text-align: center; font-weight: thin;font-size: 30px;'>Predicted Alzheimer's stage is : <b>{class_names[predicted_class]}</b></div>", unsafe_allow_html=True)
|
91 |
-
left_co, cent_co,last_co = st.columns(3)
|
92 |
-
with cent_co:
|
93 |
-
st.image(uploaded_file, use_column_width=False, width=300)
|
94 |
-
else:
|
95 |
-
st.image(img)
|
96 |
|
97 |
-
|
98 |
-
|
99 |
-
|
100 |
-
st.image("333.jpg")
|
101 |
-
st.header("📊 Early Stage Alzheimer's prediction ")
|
102 |
-
st.subheader("🧠What is Alzheimer's?")
|
103 |
-
st.write("Alzheimer's disease is a progressive neurodegenerative disorder that primarily affects the brain. It is the most common form of dementia, characterized by the gradual loss of cognitive functions, including memory, thinking, and language. The disease is caused by the buildup of abnormal proteins, such as amyloid-beta and tau, which form plaques and tangles in the brain, leading to the death of nerve cells and the deterioration of brain tissue. As the disease progresses, individuals experience difficulty with daily activities, mood changes, and ultimately, a severe decline in their overall cognitive and functional abilities. Currently, there is no cure for Alzheimer's, but researchers are working to develop new treatments and therapies to slow the progression of the disease and improve the quality of life for those affected.")
|
104 |
-
|
105 |
-
st.subheader("���️Deep Learning and Alzheimer's")
|
106 |
-
st.write("Deep learning, a branch of artificial intelligence, has shown promising results in the early diagnosis of Alzheimer's disease. Researchers have developed deep learning algorithms that can analyze medical imaging data, such as MRI or PET scans, to detect subtle changes in the brain structure and function that are associated with the onset of Alzheimer's. These algorithms can identify patterns and features in the data that are not easily discernible to the human eye, allowing for earlier detection of the disease before significant cognitive decline occurs. By leveraging the power of deep learning, clinicians can potentially diagnose Alzheimer's at earlier stages, enabling timely interventions and potentially improving patient outcomes.")
|
107 |
-
|
108 |
-
st.subheader("🗄️ Datasets")
|
109 |
-
|
110 |
-
aptos_image = Image.open("istock.jpg")
|
111 |
-
|
112 |
-
dr1 = Image.open("11.png")
|
113 |
-
dr2 = Image.open("22.png")
|
114 |
-
dr3 = Image.open("33.png")
|
115 |
-
|
116 |
-
|
117 |
-
st.image(aptos_image)
|
118 |
-
st.write("""The Kaggle Alzheimer's Dataset is a publicly available dataset that has been widely used in research on the early detection and diagnosis of Alzheimer's disease. The dataset consists of brain MRI scans from several hundred participants, along with associated clinical data, such as the participant's age, gender, and cognitive test scores. The MRI scans are labeled according to the participant's clinical diagnosis, including healthy controls, as well as individuals with mild cognitive impairment and Alzheimer's disease.
|
119 |
-
Researchers and data scientists have leveraged this dataset to develop and test various machine learning and deep learning algorithms for the automated analysis of brain MRI scans. The goal is to identify specific patterns or features in the brain images that can distinguish between healthy individuals and those with Alzheimer's or other related cognitive disorders. By training and validating models on this dataset, researchers aim to improve the accuracy and efficiency of Alzheimer's diagnosis, which could lead to earlier interventions and better patient outcomes.
|
120 |
-
The Kaggle Alzheimer's Dataset has been instrumental in advancing the field of Alzheimer's research, as it provides a standardized and well-curated resource for the scientific community to collaborate, share ideas, and push the boundaries of what's possible in the early detection and diagnosis of this debilitating disease.
|
121 |
-
"""
|
122 |
-
)
|
123 |
-
st.subheader("🎚️ Alzheimer's Stages")
|
124 |
-
|
125 |
-
data_col1, data_col2, data_col3, data_col4 = st.columns([1, 1, 1, 1])
|
126 |
-
|
127 |
-
with data_col1:
|
128 |
-
st.markdown('<div style="text-align:center">Healthy brain</div>', unsafe_allow_html=True)
|
129 |
-
st.image(dr1)
|
130 |
-
|
131 |
-
with data_col2:
|
132 |
-
st.markdown('<div style="text-align:center">Moderate</div>', unsafe_allow_html=True)
|
133 |
-
st.image(dr2)
|
134 |
-
|
135 |
-
with data_col3:
|
136 |
-
st.markdown('<div style="text-align:center">Severe</div>', unsafe_allow_html=True)
|
137 |
-
st.image(dr3)
|
138 |
-
|
139 |
-
|
140 |
-
st.subheader("📈 Data Preprocessing")
|
141 |
-
st.image('ss2.png')
|
142 |
-
st.write("""
|
143 |
-
In the application of deep learning for Alzheimer's disease diagnosis using brain MRI images, image preprocessing is a crucial step to ensure the quality and consistency of the data fed into the neural networks.
|
144 |
-
One common preprocessing technique is image normalization, which scales the pixel intensities to a common range, typically between 0 and 1 or -1 and 1. This helps to standardize the input data and reduce the impact of variations in image acquisition parameters or scanner differences.
|
145 |
-
Skull stripping is another important preprocessing step, where the non-brain tissues such as the skull, scalp, and dura mater are removed from the MRI images. This can be done using specialized algorithms that segment the brain tissue from the surrounding structures, allowing the deep learning models to focus solely on the relevant brain regions.
|
146 |
-
Image registration is also commonly applied, which aligns the MRI scans to a common reference space, such as a standard brain template. This ensures that corresponding anatomical structures are spatially aligned across different patient scans, enabling more accurate comparison and feature extraction.
|
147 |
-
Additionally, data augmentation techniques, such as random rotations, flips, or intensity variations, can be applied to the preprocessed MRI images. This can help to increase the size and diversity of the training dataset, improving the generalization capabilities of the deep learning models and reducing the risk of overfitting.
|
148 |
-
By carefully applying these preprocessing steps, the input MRI data can be optimized for deep learning analysis, enhancing the performance and robustness of the models in detecting and classifying Alzheimer's disease patterns from brain imaging data.
|
149 |
-
"""
|
150 |
-
)
|
151 |
|
|
|
|
|
152 |
|
153 |
-
|
154 |
-
st.subheader("👨💻 Model Training")
|
155 |
-
st.write("""To train a deep learning model using EfficientNetB3 for predicting Alzheimer's disease from MRI scans, the following steps can be followed:
|
156 |
-
1. **Data Preprocessing**:
|
157 |
-
- Normalize the MRI scans to a common range (e.g., 0-1 or -1 to 1) to standardize the input data.
|
158 |
-
- Perform skull stripping to remove non-brain tissues and focus the model on the relevant brain regions.
|
159 |
-
- Apply image registration to align the MRI scans to a common reference space for accurate comparison.
|
160 |
-
- Optionally, use data augmentation techniques like random rotations, flips, or intensity variations to increase the size and diversity of the training dataset.
|
161 |
-
2. **Dataset Preparation**:
|
162 |
-
- Split the preprocessed MRI scans into training, validation, and test sets.
|
163 |
-
- Label the scans based on the patient's clinical diagnosis (e.g., healthy, mild cognitive impairment, Alzheimer's).
|
164 |
-
3. **Model Architecture**:
|
165 |
-
- Use the EfficientNetB3 model as the base architecture.
|
166 |
-
- Modify the final layers of the model to fit the specific task of Alzheimer's disease classification.
|
167 |
-
4. **Transfer Learning**:
|
168 |
-
- Initialize the model with weights pre-trained on a large-scale dataset like ImageNet.
|
169 |
-
- Fine-tune the model on the Alzheimer's MRI dataset to adapt the learned features to the specific task.
|
170 |
-
5. **Training and Optimization**:
|
171 |
-
- Train the model on the preprocessed MRI scans, minimizing the classification loss and maximizing the accuracy.
|
172 |
-
- Monitor the model's performance on the validation set and apply techniques like early stopping to prevent overfitting.
|
173 |
-
6. **Evaluation**:
|
174 |
-
- Assess the trained model's performance on the held-out test set.
|
175 |
-
- Analyze the model's ability to accurately classify different stages of Alzheimer's disease.
|
176 |
-
By following these steps, you can leverage the power of the EfficientNetB3 model to develop a deep learning-based system for early and accurate Alzheimer's disease prediction using MRI scans. The model's high accuracy and efficient inference make it a valuable tool in the field of Alzheimer's research and clinical practice.
|
177 |
-
""")
|
178 |
|
179 |
-
st.
|
180 |
-
st.image(
|
181 |
-
with st.sidebar:
|
182 |
-
st.title("Early stage Alzeimer's prediction tool")
|
183 |
-
|
184 |
-
st.markdown('Made with ❤️ by YASH SARNAIK')
|
185 |
|
186 |
if __name__ == '__main__':
|
187 |
-
main()
|
|
|
1 |
import streamlit as st
|
|
|
|
|
2 |
import numpy as np
|
|
|
3 |
from tensorflow.keras.preprocessing import image
|
4 |
from tensorflow.keras.applications.efficientnet import preprocess_input
|
|
|
5 |
import tensorflow as tf
|
6 |
+
from PIL import Image
|
|
|
7 |
|
8 |
def main():
|
9 |
st.set_page_config(
|
10 |
+
page_title="Alzheimer's Detection",
|
11 |
+
layout="centered"
|
12 |
+
)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
13 |
|
14 |
+
st.markdown("<h1 style='text-align: center;'>Alzheimer's Detection Tool🧠</h1>", unsafe_allow_html=True)
|
15 |
|
16 |
+
# Load the saved model
|
17 |
+
loaded_model = tf.keras.models.load_model("model.h5", compile=False)
|
|
|
18 |
|
19 |
+
def predict_image_class(img_path):
|
20 |
+
img = image.load_img(img_path, target_size=(224, 224))
|
21 |
+
img_array = image.img_to_array(img)
|
22 |
+
img_array = np.expand_dims(img_array, axis=0)
|
23 |
+
img_array = preprocess_input(img_array)
|
24 |
|
25 |
+
predictions = loaded_model.predict(img_array)
|
26 |
+
predicted_class = np.argmax(predictions, axis=1)[0]
|
27 |
|
28 |
+
return predicted_class
|
|
|
|
|
|
|
|
|
|
|
|
|
29 |
|
30 |
+
uploaded_file = st.file_uploader('Upload an MRI image...', type=['jpg', 'png', 'jpeg'])
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
31 |
|
32 |
+
if uploaded_file is not None:
|
33 |
+
predicted_class = predict_image_class(uploaded_file)
|
34 |
|
35 |
+
class_names = ["MILD DEMENTED", "MODERATE DEMENTED", "NON DEMENTED", "VERY MILD DEMENTED"]
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
36 |
|
37 |
+
st.markdown(f"<div style='text-align: center; font-size: 30px;'>Predicted Alzheimer's stage is: <b>{class_names[predicted_class]}</b></div>", unsafe_allow_html=True)
|
38 |
+
st.image(uploaded_file, use_column_width=False, width=300)
|
|
|
|
|
|
|
|
|
39 |
|
40 |
if __name__ == '__main__':
|
41 |
+
main()
|