sindhoorar commited on
Commit
8e8a833
1 Parent(s): 2040da2

initial commit

Browse files
Files changed (1) hide show
  1. app.py +235 -0
app.py ADDED
@@ -0,0 +1,235 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import streamlit as st
2
+ import cv2
3
+ import numpy as np
4
+ from skimage import feature
5
+ from imutils import paths
6
+ import pickle
7
+ import pandas as pd
8
+
9
+ # Load the trained model
10
+ model_path = "spiralModel.pkl"
11
+ with open(model_path, "rb") as model_file:
12
+ spiralModel = pickle.load(model_file)
13
+
14
+ def quantify_image(image):
15
+ features = feature.hog(image, orientations=9,
16
+ pixels_per_cell=(10, 10), cells_per_block=(2, 2),
17
+ transform_sqrt=True, block_norm="L1")
18
+ return features
19
+
20
+ def predict(image):
21
+ # Preprocess the input image
22
+ image = cv2.cvtColor(image, cv2.COLOR_BGR2GRAY)
23
+ image = cv2.resize(image, (200, 200))
24
+ image = cv2.threshold(image, 0, 255,
25
+ cv2.THRESH_BINARY_INV | cv2.THRESH_OTSU)[1]
26
+ features = quantify_image(image)
27
+
28
+ # Make predictions using the trained model
29
+ prediction = spiralModel["classifier"].predict([features])[0]
30
+ return prediction
31
+
32
+ def home_page():
33
+ st.title("Home - Neurodegenerative Disease Awareness")
34
+
35
+ st.write(
36
+ """
37
+ Neurodegenerative diseases are a group of disorders characterized by the progressive degeneration of the structure and function of the nervous system. These diseases primarily affect neurons, leading to problems with movement, cognition, and various other functions.
38
+ """
39
+ )
40
+
41
+ # Section 1: Introduction
42
+ st.subheader("Introduction")
43
+ st.write(
44
+ """
45
+ Early detection and awareness are crucial for managing these conditions effectively. In this app, we focus on using machine learning to identify potential signs of neurodegenerative diseases from spiral drawings.
46
+ """
47
+ )
48
+
49
+ # Section 2: Common Neurodegenerative Diseases
50
+ st.subheader("Common Neurodegenerative Diseases")
51
+ st.write(
52
+ """
53
+ - Alzheimer's Disease
54
+ - Parkinson's Disease
55
+ - Amyotrophic Lateral Sclerosis (ALS)
56
+ - Huntington's Disease
57
+ """
58
+ )
59
+
60
+ # Section 3: Importance of Early Detection
61
+ st.subheader("Importance of Early Detection")
62
+ st.write(
63
+ """
64
+ Learn more about the importance of early detection and raise awareness about neurodegenerative diseases. Explore the other pages for resources and Parkinson's disease prediction.
65
+ """
66
+ )
67
+
68
+ def resources_page():
69
+ st.title("Resources - Neurodegenerative Disease Resources")
70
+
71
+ st.write(
72
+ """
73
+ Here, you can find resources related to neurodegenerative diseases, including information, support groups, and links to relevant organizations.
74
+ """
75
+ )
76
+
77
+ # Section 1: Educational Resources
78
+ st.subheader("Educational Resources")
79
+ st.write(
80
+ """
81
+ - [Alzheimer's Association](https://www.alz.org/)
82
+ - [Parkinson's Foundation](https://www.parkinson.org/)
83
+ - [ALS Association](https://www.alsa.org/)
84
+ - [Huntington's Disease Society of America](https://hdsa.org/)
85
+ """
86
+ )
87
+
88
+ # Section 2: Support Groups
89
+ st.subheader("Support Groups")
90
+ st.write(
91
+ """
92
+ - [PatientsLikeMe - Neurological Conditions](https://www.patientslikeme.com/)
93
+ - [Smart Patients - Neurological Disorders](https://www.smartpatients.com/)
94
+ """
95
+ )
96
+
97
+ # Section 3: Research and Clinical Trials
98
+ st.subheader("Research and Clinical Trials")
99
+ st.write(
100
+ """
101
+ - [ClinicalTrials.gov - Neurodegenerative Diseases](https://clinicaltrials.gov/ct2/home)
102
+ """
103
+ )
104
+
105
+ def parkinsons_prediction_page():
106
+ st.title("Parkinson's Prediction - Predicting Parkinson's Disease")
107
+
108
+ st.write(
109
+ """
110
+ On this page, you can upload a spiral drawing, and the app will predict whether it shows signs of Parkinson's disease based on the trained machine learning model.
111
+ """
112
+ )
113
+
114
+ template_image_path = "template.jpg"
115
+ template_image = cv2.imread(template_image_path)
116
+ st.image(template_image, caption="Spiral Template", use_column_width=300)
117
+
118
+
119
+ # File Upload
120
+ uploaded_file = st.file_uploader("Choose a spiral drawing...", type=["jpg", "jpeg", "png"])
121
+
122
+ if uploaded_file is not None:
123
+ # Display the uploaded image
124
+ image = cv2.imdecode(np.fromstring(uploaded_file.read(), np.uint8), cv2.IMREAD_UNCHANGED)
125
+ st.image(image, caption="Uploaded Image", use_column_width=300)
126
+
127
+ # Make predictions
128
+ prediction = predict(image)
129
+
130
+ if (prediction==0):
131
+ st.write(f"Prediction Normal: AI model detects no signs of Parkinsons")
132
+ else:
133
+ st.write(f"Prediction Atypical: AI model detects signs of Parkinsons")
134
+
135
+ def voice_analysis_page():
136
+ st.title('Voice-Based Parkinson\'s Disease Analysis')
137
+ st.sidebar.header('User Input Features')
138
+
139
+ data = {
140
+ 'avg_fre': [60.0, 180.0, 300.0], # Add values for other features as needed
141
+ 'max_fre': [80.0, 350.0, 620.0],
142
+ 'min_fre': [40.0, 155.0, 270.0],
143
+
144
+ 'var_fre1': [0.00, 0.020, 0.040],
145
+
146
+ 'var_fre2': [0.00, 0.00, 0.01],
147
+
148
+ 'var_fre3': [0.00, 0.01, 0.02],
149
+
150
+ 'var_fre4': [0.00, 0.035, 0.07],
151
+
152
+ 'var_fre5': [0.00, 0.1, 0.2],
153
+
154
+ 'var_amp1': [0.0, 0.1, 0.2],
155
+ 'var_amp2': [0.0, 0.03, 0.06],
156
+ 'var_amp3': [0.0, 0.4, 0.08],
157
+ 'var_amp4': [0.0, 0.1, 0.2],
158
+ 'var_amp5': [0.0, 0.1, 0.2],
159
+
160
+ 'NHR': [0.0, 0.20, 0.4],
161
+ 'HNR': [6.0, 21, 36.0],
162
+ 'RPDE': [0.2, 0.5, 0.8],
163
+ 'DFA': [0.4, 0.65, 0.9],
164
+ 'spread1': [-9.0, -4.0, -1.0],
165
+ 'spread2': [0.00, 0.25, 0.5],
166
+ 'D2': [1.3, 2.5, 3.8],
167
+ 'PPE': [0.03, 0.31, 0.6],
168
+ 'status': [0, 1, 0] # Assuming 'status' is the target column
169
+ }
170
+
171
+ df = pd.DataFrame(data)
172
+
173
+ # Load the Random Forest model
174
+ model_path = 'modelrf.pkl' # Update with the correct path to your saved Random Forest model
175
+ with open(model_path, 'rb') as model_file:
176
+ rf_model = pickle.load(model_file)
177
+
178
+ # Create sliders for user input features
179
+ avg_fre = st.sidebar.slider('Average Frequency (Hz)', float(df['avg_fre'].min()), float(df['avg_fre'].max()), float(df['avg_fre'].mean()))
180
+ max_fre = st.sidebar.slider('Maximum Frequency (Hz)', float(df['max_fre'].min()), float(df['max_fre'].max()), float(df['max_fre'].mean()))
181
+ min_fre = st.sidebar.slider('Minimum Frequency (Hz)', float(df['min_fre'].min()), float(df['min_fre'].max()), float(df['min_fre'].mean()))
182
+ var_fre1 = st.sidebar.slider('Jitter Percentage', float(df['var_fre1'].min()), float(df['var_fre1'].max()), float(df['var_fre1'].mean()))
183
+ var_fre2 = st.sidebar.slider('Jitter Absolute', float(df['var_fre2'].min()), float(df['var_fre2'].max()), float(df['var_fre2'].mean()))
184
+ var_fre3 = st.sidebar.slider('Jitter RAP', float(df['var_fre3'].min()), float(df['var_fre3'].max()), float(df['var_fre3'].mean()))
185
+ var_fre4 = st.sidebar.slider('Jitter PPQ', float(df['var_fre4'].min()), float(df['var_fre4'].max()), float(df['var_fre4'].mean()))
186
+ var_fre5 = st.sidebar.slider('Jitter DDP', float(df['var_fre5'].min()), float(df['var_fre5'].max()), float(df['var_fre5'].mean()))
187
+ var_amp1 = st.sidebar.slider('Shimmer', float(df['var_amp1'].min()), float(df['var_amp1'].max()), float(df['var_amp1'].mean()))
188
+ var_amp2 = st.sidebar.slider('Shimmer (dB)', float(df['var_amp2'].min()), float(df['var_amp2'].max()), float(df['var_amp2'].mean()))
189
+ var_amp3 = st.sidebar.slider('Shimmer APQ3', float(df['var_amp3'].min()), float(df['var_amp3'].max()), float(df['var_amp3'].mean()))
190
+ var_amp4 = st.sidebar.slider('Shimmer APQ5', float(df['var_amp4'].min()), float(df['var_amp4'].max()), float(df['var_amp4'].mean()))
191
+ var_amp5 = st.sidebar.slider('Shimmer DDA', float(df['var_amp5'].min()), float(df['var_amp5'].max()), float(df['var_amp5'].mean()))
192
+ NHR = st.sidebar.slider('NHR', float(df['NHR'].min()), float(df['NHR'].max()), float(df['NHR'].mean()))
193
+ HNR = st.sidebar.slider('HNR', float(df['HNR'].min()), float(df['HNR'].max()), float(df['HNR'].mean()))
194
+ RPDE = st.sidebar.slider('RPDE', float(df['RPDE'].min()), float(df['RPDE'].max()), float(df['RPDE'].mean()))
195
+ DFA = st.sidebar.slider('DFA', float(df['DFA'].min()), float(df['DFA'].max()), float(df['DFA'].mean()))
196
+ spread1 = st.sidebar.slider('Spread1', float(df['spread1'].min()), float(df['spread1'].max()), float(df['spread1'].mean()))
197
+ spread2 = st.sidebar.slider('Spread2', float(df['spread2'].min()), float(df['spread2'].max()), float(df['spread2'].mean()))
198
+ D2 = st.sidebar.slider('D2', float(df['D2'].min()), float(df['D2'].max()), float(df['D2'].mean()))
199
+ PPE = st.sidebar.slider('PPE', float(df['PPE'].min()), float(df['PPE'].max()), float(df['PPE'].mean()))
200
+
201
+ user_input = [avg_fre, max_fre, min_fre, var_fre1, var_fre2, var_fre3, var_fre4, var_fre5,
202
+ var_amp1, var_amp2, var_amp3, var_amp4, var_amp5, NHR, HNR, RPDE, DFA, spread1, spread2, D2, PPE]
203
+
204
+ # Display user input features
205
+ st.subheader('User Input Features')
206
+ user_input_df = pd.DataFrame(data=[user_input], columns=df.columns[:-1]) # Assuming the last column is the target 'status'
207
+ st.write(user_input_df)
208
+
209
+ # Make prediction with the Random Forest model
210
+ prediction = rf_model.predict(user_input_df)
211
+
212
+ # Display Random Forest model prediction
213
+ st.subheader('Random Forest Model Prediction')
214
+ st.write(f"Random Forest Model: {int(prediction[0])}")
215
+
216
+ def dementia():
217
+ st.write("Hi!")
218
+
219
+ def main():
220
+ st.sidebar.title("Navigation")
221
+ selected_page = st.sidebar.radio("Go to", ["Home", "Resources", "Parkinson's Prediction", "Voice-Based Analysis", "Dementia Detection"])
222
+
223
+ if selected_page == "Home":
224
+ home_page()
225
+ elif selected_page == "Resources":
226
+ resources_page()
227
+ elif selected_page == "Parkinson's Prediction":
228
+ parkinsons_prediction_page()
229
+ elif selected_page == "Voice-Based Analysis":
230
+ voice_analysis_page()
231
+ elif selected_page == "Dementia Detection":
232
+ dementia()
233
+
234
+ if __name__ == "__main__":
235
+ main()