soumickmj commited on
Commit
713959d
1 Parent(s): 4eb6070
Files changed (2) hide show
  1. NdR_disease.py +16 -8
  2. app.py +3 -0
NdR_disease.py CHANGED
@@ -197,7 +197,7 @@ def run_disease_train():
197
 
198
  def get_user_input_and_predict(linear_model, neural_model, scaler, conditions, num_classes):
199
  st.write("\nAdjust the sliders for the following symptoms on a scale from 0 (none) to 10 (severe):")
200
-
201
  # Feature names
202
  feature_names = ['Fever', 'Cough', 'Sneezing', 'Runny Nose', 'Nausea', 'Vomiting',
203
  'Diarrhea', 'Headache', 'Fatigue', 'Stress Level']
@@ -205,24 +205,32 @@ def get_user_input_and_predict(linear_model, neural_model, scaler, conditions, n
205
  # Create sliders for user input
206
  user_features = []
207
  for feature in feature_names:
208
- value = st.slider(feature, 0, 10, 5) # Default value set to 5
209
- user_features.append(value)
210
-
 
 
 
211
  # Calculate interaction terms
212
  interaction_term = np.sin(user_features[7]) * np.log1p(user_features[9]) # Headache and Stress Level
213
  interaction_term2 = user_features[0] * user_features[4] # Fever * Nausea
214
  user_features.extend([interaction_term, interaction_term2])
215
-
216
  # Add a button to trigger the predictions
217
  if st.button('Calculate Predictions'):
 
 
 
 
 
218
  # Normalize features
219
  user_features = scaler.transform([user_features])
220
  user_tensor = torch.from_numpy(user_features).float()
221
-
222
  # Random prediction
223
  random_pred = np.random.randint(num_classes)
224
  st.write(f"\nRandom Prediction: {conditions[random_pred]}")
225
-
226
  # Linear Model Prediction
227
  linear_model.eval()
228
  with torch.no_grad():
@@ -230,7 +238,7 @@ def get_user_input_and_predict(linear_model, neural_model, scaler, conditions, n
230
  _, predicted = torch.max(outputs.data, 1)
231
  linear_pred = predicted.item()
232
  st.write(f"Linear Model Prediction: {conditions[linear_pred]}")
233
-
234
  # Neural Network Prediction
235
  neural_model.eval()
236
  with torch.no_grad():
 
197
 
198
  def get_user_input_and_predict(linear_model, neural_model, scaler, conditions, num_classes):
199
  st.write("\nAdjust the sliders for the following symptoms on a scale from 0 (none) to 10 (severe):")
200
+
201
  # Feature names
202
  feature_names = ['Fever', 'Cough', 'Sneezing', 'Runny Nose', 'Nausea', 'Vomiting',
203
  'Diarrhea', 'Headache', 'Fatigue', 'Stress Level']
 
205
  # Create sliders for user input
206
  user_features = []
207
  for feature in feature_names:
208
+ # Use session state to retain slider values
209
+ default_value = 5
210
+ user_input = st.slider(feature, 0, 10, st.session_state.get(feature, default_value))
211
+ st.session_state[feature] = user_input
212
+ user_features.append(user_input)
213
+
214
  # Calculate interaction terms
215
  interaction_term = np.sin(user_features[7]) * np.log1p(user_features[9]) # Headache and Stress Level
216
  interaction_term2 = user_features[0] * user_features[4] # Fever * Nausea
217
  user_features.extend([interaction_term, interaction_term2])
218
+
219
  # Add a button to trigger the predictions
220
  if st.button('Calculate Predictions'):
221
+ # Set session state to indicate the button was clicked
222
+ st.session_state.button_clicked = True
223
+
224
+ # Only show predictions if the button has been clicked
225
+ if st.session_state.button_clicked:
226
  # Normalize features
227
  user_features = scaler.transform([user_features])
228
  user_tensor = torch.from_numpy(user_features).float()
229
+
230
  # Random prediction
231
  random_pred = np.random.randint(num_classes)
232
  st.write(f"\nRandom Prediction: {conditions[random_pred]}")
233
+
234
  # Linear Model Prediction
235
  linear_model.eval()
236
  with torch.no_grad():
 
238
  _, predicted = torch.max(outputs.data, 1)
239
  linear_pred = predicted.item()
240
  st.write(f"Linear Model Prediction: {conditions[linear_pred]}")
241
+
242
  # Neural Network Prediction
243
  neural_model.eval()
244
  with torch.no_grad():
app.py CHANGED
@@ -10,6 +10,9 @@ from sklearn.model_selection import train_test_split
10
 
11
  from NdR_disease import run_disease_train, get_user_input_and_predict
12
 
 
 
 
13
 
14
  # Function for male superhero task
15
  def run_male_superhero_task():
 
10
 
11
  from NdR_disease import run_disease_train, get_user_input_and_predict
12
 
13
+ if 'button_clicked' not in st.session_state:
14
+ st.session_state.button_clicked = False
15
+
16
 
17
  # Function for male superhero task
18
  def run_male_superhero_task():