wissemkarous commited on
Commit
fdac493
1 Parent(s): 5a84a6b
Anxiety_ANN_model.h5 ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:877aaee1a85db2a238287a434fb5242e11d32cb0d0c41943c7d7d88e5aa43217
3
+ size 73880
anxiety-test-c3553-firebase-adminsdk-5urg9-2928954445.json ADDED
@@ -0,0 +1,13 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ {
2
+ "type": "service_account",
3
+ "project_id": "anxiety-test-c3553",
4
+ "private_key_id": "29289544456d5fa39048fdd4bb242c9adb39c164",
5
+ "private_key": "-----BEGIN PRIVATE KEY-----\nMIIEvQIBADANBgkqhkiG9w0BAQEFAASCBKcwggSjAgEAAoIBAQCqZfaGN/D5xLYq\nevUPHQ8bbYT0NbMhyB9Z2XXjkHq2POHkK0UUrOQN+FBkyf1FzmqGfO8RXKRrZXaM\nzDARf5QPDXYRiKAOMi/3/XSSGylBy0078HEhw2GXjUZwdRHaXeiuIaehsYXzjpRH\n9zhf9kxwz/58/90frDmu3qovBKL9+XOPRHV+ZCHHSyb3EsQsFpIwVcMkAvxLn5To\ntSs0eiuFNt+SH09n9WrwMxDCmvabjM5hQOTFyQbtjseaYUQkAp6H/QpkxdVxZj8Q\n8lKkq6/sXF3u359TecPATO2Tass7Net9u498o5a2NrJ4JjTNge9qHHPe9dHjAAW2\nsV+zZlRDAgMBAAECggEAAWH5vX5jt6FMg2+A1rrTrNNXV0blqX8D4wkcNg7yu6mc\nvGrpAixdcndrfW8eBPx+jEKabZGGE5NVZL8sMmAnYhLPUEUv+XYhpIR8qGeg3YA8\no/AlIGkgqVaXaYuC4icrUMV/X3d8gfka3wHb/A9dUzNWHJmixUw3v3UtBfl/PAWB\ngyjRb5SRiEzojTOKwAgyf0WV6PA9AnRbV56utdgaAoLOqNAO4GNuALb6z3aJztgE\n9iNfooE3IbOwj1BeWla0VRB9GBVxytcX5NdOy3DDWXZdsOXs978KU2mK5yuv2Gjw\nryvmuJzbWwDF9MMqgS6AmUEgTdXiRL8kHBWi27zqPQKBgQDibcwOkpqurh2ISrWq\npb3N/BwW+VXAsmUzCs4WY1wki6EpHZ7XbC1B7870p8457HHyr7XQu0dvK94bn2JK\n+Nx6wPoBQCEjaNhJKqMHfbVUptWMRIElLQ00fuDwlL+mhHh/sOiHnMvRFnzvgXzS\nsFbNXv7Bg7e/p06+tL1/cwjLfQKBgQDApuSz+MNzwQDsSe69V62yaG7xnx35XzZe\nsYxsaif3PS0+9dT9JaTU0hOBCUinW0MEbHPXPhEzHVSQ1iGNWfaMm0+u+szuec6m\nConAp8IneHen5jURuDjLnfvOJJ30ERB4BX47ATSZuC1GU0SXZd8gKTR1vWiRRbvc\n3dLWKoQqvwKBgF8LAW1Ygk8yTLkpyumPWoV8/nlyPVl+SFZNgcYJ/OJmLcapZUQ9\nZx3XQEKXsUvFAOuCb8nm4ow6mKd1lner0DhCim498esAFlFX8UiyrouS3+5Zzu/A\n4lsXqumxNmT6E+5dXq2V1kO0scqCytdRJ45bAopN9LIg0z/fc+9sZNOtAoGAO0zk\nBxXiq+XT7+fOChBMEiedRtiwtEr/hGRokhKXHL6DB+dJ2WZV94B2qnh+Ga240krD\n2ZRsXOyBVFflWgpAHwXLoFPo8tshpfCGeHvrApVNV6w/16V6LgsCMHELAc6i4B7o\nvSbg1xRfM098RJIB/XdRg5B6+ISbkB/jvzK1HicCgYEAsIF1KkB2335W93kTn94U\nwVAs5mOwJnow/VhYcKxCsxfxCuxYPAneFG91nYNgSTYBfJUu0IT9HVht3J0Sv4mh\nmjBvNjHPfLf8wLpCOpwxWsnt5G5n7j+rKtVZePMX6GqaKFj5RrXbi5VFslz8NvMF\nFvE2J61J1KaoriBX7xc7g2Q=\n-----END PRIVATE KEY-----\n",
6
+ "client_email": "firebase-adminsdk-5urg9@anxiety-test-c3553.iam.gserviceaccount.com",
7
+ "client_id": "114282250147198274627",
8
+ "auth_uri": "https://accounts.google.com/o/oauth2/auth",
9
+ "token_uri": "https://oauth2.googleapis.com/token",
10
+ "auth_provider_x509_cert_url": "https://www.googleapis.com/oauth2/v1/certs",
11
+ "client_x509_cert_url": "https://www.googleapis.com/robot/v1/metadata/x509/firebase-adminsdk-5urg9%40anxiety-test-c3553.iam.gserviceaccount.com",
12
+ "universe_domain": "googleapis.com"
13
+ }
app.py ADDED
@@ -0,0 +1,254 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import streamlit as st
2
+ import pandas as pd
3
+ import os
4
+ import random
5
+ import pickle
6
+ import tensorflow as tf
7
+ import firebase_admin
8
+ from tensorflow.keras.models import Sequential
9
+ from tensorflow.keras.layers import Dense
10
+ from sklearn.preprocessing import StandardScaler
11
+ from tensorflow.keras.models import load_model
12
+ from firebase_admin import credentials, firestore
13
+
14
+
15
+ current_directory = os.path.dirname(__file__)
16
+ firebase_config = os.path.join(current_directory,"anxiety-test-c3553-firebase-adminsdk-5urg9-2928954445.json")
17
+ cred = credentials.Certificate(firebase_config)
18
+ if not firebase_admin._apps:
19
+ firebase_admin.initialize_app(cred)
20
+
21
+ fs = firestore.client()
22
+
23
+ def main():
24
+ # Create a sidebar with navigation links
25
+ st.sidebar.title("Navigation")
26
+ page = st.sidebar.selectbox("Select a page", ["Home", "Wellness Test"])
27
+
28
+ if page == "Home":
29
+ show_home_page()
30
+ elif page == "Wellness Test":
31
+ show_wellness_test_page()
32
+
33
+ def show_home_page():
34
+ st.title("Student Wellness Test")
35
+ st.subheader("A Website to test your wellness")
36
+ st.write("A Project By Sugih Ahmad Fauzan and Marco William")
37
+ st.write('To Start Test, Click on the left side bar and choose Wellness Test')
38
+
39
+ def show_wellness_test_page():
40
+ st.title("Wellness Test App")
41
+
42
+ st.write("This app allows you to take the GAD (Generalized Anxiety Disorder), SWL (Satisfaction with Life), SPIN (Social Phobia Inventory), and answer some Personal Questions.")
43
+
44
+ # GAD Test
45
+ st.header("GAD Test")
46
+ gad_questions = ["Feeling nervous, anxious or on edge?",
47
+ "Not being able to stop or control worrying?",
48
+ "Worrying too much about different things?",
49
+ "Trouble relaxing?",
50
+ "Being so restless that it's hard to sit still?",
51
+ "Becoming easily annoyed or irritable?",
52
+ "Feeling afraid as if something awful might happen"]
53
+ gad_responses = collect_gad_responses(gad_questions)
54
+ gad_total_score = sum(gad_responses.values())
55
+
56
+ st.divider()
57
+ # SWL Test
58
+ st.header("SWL Test")
59
+ swl_questions = ["In most ways, my life is close to my ideal.",
60
+ "The conditions of my life are excellent.",
61
+ "I am satisfied with my life.",
62
+ "So far, I have gotten the important things I want in life.",
63
+ "If I could live my life over, I would change almost nothing"]
64
+ swl_responses = collect_swl_responses(swl_questions)
65
+ swl_total_score = sum(swl_responses.values())
66
+
67
+ st.divider()
68
+ # SPIN Test
69
+ st.header("SPIN Test")
70
+ spin_questions = ["I avoid talking to people I don’t know.",
71
+ "I am afraid to speak in public.",
72
+ "I avoid activities in which I am the center of attention.",
73
+ "Being criticized scares me.",
74
+ "I avoid making phone calls.",
75
+ "I avoid parties and social events.",
76
+ "I avoid participating in class or at meetings.",
77
+ "I avoid participating in small groups.",
78
+ "I avoid eating with others.",
79
+ "I am uncomfortable writing in front of others.",
80
+ "I avoid talking to authority figures.",
81
+ "I avoid using public restrooms.",
82
+ "I avoid expressing disagreement with others.",
83
+ "I avoid talking to strangers.",
84
+ "I avoid eye contact with others.",
85
+ "I am uncomfortable talking to people in authority.",
86
+ "I am afraid to date or ask someone out on a date"]
87
+ spin_responses = collect_spin_responses(spin_questions)
88
+ spin_total_score = sum(spin_responses.values())
89
+
90
+ st.divider()
91
+ # Personal Questions
92
+ st.header("Personal Questions")
93
+ income = st.number_input("1. How much do you earn in a month?", value=0, step=1)
94
+ age = st.number_input("2. How old are you?", value=18, step=1)
95
+ work_options = {"Not Working" :0, "Part Time":1, "Full Time":2}
96
+ work = st.selectbox("3. What is your employment status?", options=list(work_options.keys()))
97
+ degree_options = {"Still in School" : 0, "Bachelor":1, "Master":2, "Doctor":3, "Professor":4}
98
+ degree = st.selectbox("4. What is your highest degree?", options=list(degree_options.keys()))
99
+ confidence_rating = st.slider("5. Rate your confidence when talking to somebody (1 lowest, 5 highest)", min_value=1, max_value=5, value=3)
100
+ gender_options = {"Male": 0, "Female": 1}
101
+ gender = st.selectbox("6. What is your gender?", options=list(gender_options.keys()))
102
+
103
+ # Collect all answers in lists
104
+ GAD_T = gad_total_score/21
105
+ SWL_T = swl_total_score/25
106
+ SPIN_T = spin_total_score/51
107
+ GAD_T = round(GAD_T,6)
108
+ SWL_T = round(SWL_T,6)
109
+ SPIN_T = round(SPIN_T,6)
110
+
111
+ all_gad_answers = list(gad_responses.values())
112
+ all_swl_answers = list(swl_responses.values())
113
+ all_spin_answers = list(spin_responses.values())
114
+ all_personal_answers = [confidence_rating,income, gender_options[gender], age, work_options[work], degree_options[degree], GAD_T, SWL_T, SPIN_T]
115
+
116
+ all_answers = all_gad_answers + all_swl_answers + all_spin_answers + all_personal_answers
117
+ display_df = pd.DataFrame([all_answers], columns=get_feature_names())
118
+ df = display_df.copy()
119
+
120
+ # scaler_path = "scaler.pkl" # Replace with the actual path to your model file
121
+ # with open(scaler_path, 'rb') as file:
122
+ # data = pickle.load(file)
123
+ # scaler = data['scaler']
124
+
125
+ # model = load_model('Anxiety_ANN_model.h5')
126
+
127
+ # result = model.predict(df)
128
+ # result = int(result*100)
129
+
130
+ # st.write("Kemungkinan anda mengalami Anxiety sebesar : ",result,"%")
131
+ # df = scaler.transform(df)
132
+
133
+ st.subheader("DataFrame of Answers")
134
+ st.dataframe(df)
135
+
136
+ pred = st.button('Prediksi')
137
+
138
+ if pred:
139
+ # Pass the values to the prediction page
140
+ result = predict_result(df)
141
+ st.write("Kemungkinan anda mengalami Anxiety sebesar : ",result,"%")
142
+ threshold = 50
143
+ thresholded_result = 1 if result > threshold else 0
144
+ df['Label'] = thresholded_result
145
+ save_dataframe_to_firestore(df)
146
+
147
+
148
+ def collect_gad_responses(questions):
149
+ # Initialize a dictionary to store responses
150
+ responses = {}
151
+ # Iterate through GAD questions and collect user responses
152
+ for i, question in enumerate(questions, start=1):
153
+ st.subheader(f"GAD{i}")
154
+ st.write(f"**Question**: {question}")
155
+ # Answer options for GAD
156
+ response = st.radio(f"Select your response (GAD{i}):",
157
+ options=["Not at all", "Several days", "More than half the days", "Nearly every day"],
158
+ key=f"gad_radio_{i}")
159
+ # Map response to a numerical value for scoring
160
+ if response == "Not at all":
161
+ score = 0
162
+ elif response == "Several days":
163
+ score = 1
164
+ elif response == "More than half the days":
165
+ score = 2
166
+ else:
167
+ score = 3
168
+ # Store the response and score
169
+ responses[f'gad{i}'] = score
170
+ return responses
171
+
172
+ def collect_swl_responses(questions):
173
+ # Initialize a dictionary to store responses
174
+ responses = {}
175
+ # Iterate through SWL questions and collect user responses
176
+ for i, question in enumerate(questions, start=1):
177
+ st.subheader(f"SWL{i}")
178
+ st.write(f"**Question**: {question}")
179
+ # Answer options for SWL
180
+ response = st.radio(f"Select your response (SWL{i}):",
181
+ options=["Strongly Disagree", "Disagree", "Neither Agree nor Disagree", "Agree", "Strongly Agree"],
182
+ key=f"swl_radio_{i}")
183
+ # Map response to a numerical value for scoring
184
+ if response == "Strongly Disagree":
185
+ score = 1
186
+ elif response == "Disagree":
187
+ score = 2
188
+ elif response == "Neither Agree nor Disagree":
189
+ score = 3
190
+ elif response == "Agree":
191
+ score = 4
192
+ else:
193
+ score = 5
194
+ # Store the response and score
195
+ responses[f'swl{i}'] = score
196
+ return responses
197
+
198
+ def collect_spin_responses(questions):
199
+ # Initialize a dictionary to store responses
200
+ responses = {}
201
+ # Iterate through SPIN questions and collect user responses
202
+ for i, question in enumerate(questions, start=1):
203
+ st.subheader(f"SPIN{i}")
204
+ st.write(f"**Question**: {question}")
205
+ # Answer options for SPIN
206
+ response = st.radio(f"Select your response (SPIN{i}):",
207
+ options=["Not at all", "A little bit", "Somewhat", "Very much"],
208
+ key=f"spin_radio_{i}")
209
+ # Map response to a numerical value for scoring
210
+ if response == "Not at all":
211
+ score = 0
212
+ elif response == "A little bit":
213
+ score = 1
214
+ elif response == "Somewhat":
215
+ score = 2
216
+ else:
217
+ score = 3
218
+ # Store the response and score
219
+ responses[f'spin{i}'] = score
220
+ return responses
221
+
222
+ def get_feature_names():
223
+ gad_features = [f'GAD{i}' for i in range(1, 8)]
224
+ swl_features = [f'SWL{i}' for i in range(1, 6)]
225
+ spin_features = [f'SPIN{i}' for i in range(1, 18)]
226
+ personal_features = ['Narcissism','earnings','Gender','Age','Work','Degree','GAD_T', 'SWL_T', 'SPIN_T']
227
+ return gad_features + swl_features + spin_features + personal_features
228
+
229
+ def predict_result(answers):
230
+ scaler_path = "scaler.pkl" # Replace with the actual path to your model file
231
+ with open(scaler_path, 'rb') as file:
232
+ data = pickle.load(file)
233
+ scaler = data['scaler']
234
+
235
+ model = load_model('Anxiety_ANN_model.h5')
236
+ df = answers
237
+ # df = scaler.transform(df)
238
+ result = model.predict(df)
239
+ result = int(result*100)
240
+ return result
241
+
242
+ def save_dataframe_to_firestore(dataframe):
243
+ # Convert DataFrame to dictionary
244
+ data_dict = dataframe.to_dict(orient='records')
245
+
246
+ # Add your Firestore collection and document name
247
+ doc_ref = fs.collection("user_data").add({"data": data_dict})
248
+
249
+ return "Successfull Write to Database"
250
+
251
+ if __name__ == "__main__":
252
+ main()
253
+
254
+
requirements.txt ADDED
@@ -0,0 +1,6 @@
 
 
 
 
 
 
 
1
+ numpy==1.26.2
2
+ pandas==2.1.3
3
+ scikit-learn==1.3.2
4
+ scipy==1.11.4
5
+ tensorflow==2.15.0
6
+ firebase-admin==6.2.0
scaler.pkl ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:bddfe75d9cc5f35fcf49ded354cef9b1afebc8d3ba4a47a14a4fc91cefd307ef
3
+ size 1777