soumickmj commited on
Commit
b8d7e60
1 Parent(s): 14e62e5

Update NdR_disease.py

Browse files
Files changed (1) hide show
  1. NdR_disease.py +29 -26
NdR_disease.py CHANGED
@@ -196,6 +196,10 @@ def run_disease_train():
196
  return linear_model, neural_model, scaler, conditions, num_classes
197
 
198
  # Function to get user input and make predictions
 
 
 
 
199
  def get_user_input_and_predict(linear_model, neural_model, scaler, conditions, num_classes):
200
  st.write("\nAdjust the sliders for the following symptoms on a scale from 0 (none) to 10 (severe):")
201
 
@@ -214,29 +218,28 @@ def get_user_input_and_predict(linear_model, neural_model, scaler, conditions, n
214
  interaction_term2 = user_features[0] * user_features[4] # Fever * Nausea
215
  user_features.extend([interaction_term, interaction_term2])
216
 
217
- # Normalize features
218
- user_features = scaler.transform([user_features])
219
- user_tensor = torch.from_numpy(user_features).float()
220
-
221
- # Random prediction
222
- random_pred = np.random.randint(num_classes)
223
- st.write(f"\nRandom Prediction: {conditions[random_pred]}")
224
-
225
- # Linear Model Prediction
226
- linear_model.eval()
227
- with torch.no_grad():
228
- outputs = linear_model(user_tensor)
229
- _, predicted = torch.max(outputs.data, 1)
230
- linear_pred = predicted.item()
231
- st.write(f"Linear Model Prediction: {conditions[linear_pred]}")
232
-
233
- # Neural Network Prediction
234
- neural_model.eval()
235
- with torch.no_grad():
236
- outputs = neural_model(user_tensor)
237
- _, predicted = torch.max(outputs.data, 1)
238
- neural_pred = predicted.item()
239
- st.write(f"Neural Network Prediction: {conditions[neural_pred]}")
240
-
241
- linear_model, neural_model, scaler, conditions, num_classes = run_disease_train()
242
- get_user_input_and_predict(linear_model, neural_model, scaler, conditions, num_classes)
 
196
  return linear_model, neural_model, scaler, conditions, num_classes
197
 
198
  # Function to get user input and make predictions
199
+ import streamlit as st
200
+ import numpy as np
201
+ import torch
202
+
203
  def get_user_input_and_predict(linear_model, neural_model, scaler, conditions, num_classes):
204
  st.write("\nAdjust the sliders for the following symptoms on a scale from 0 (none) to 10 (severe):")
205
 
 
218
  interaction_term2 = user_features[0] * user_features[4] # Fever * Nausea
219
  user_features.extend([interaction_term, interaction_term2])
220
 
221
+ # Add a button to trigger the predictions
222
+ if st.button('Calculate Predictions'):
223
+ # Normalize features
224
+ user_features = scaler.transform([user_features])
225
+ user_tensor = torch.from_numpy(user_features).float()
226
+
227
+ # Random prediction
228
+ random_pred = np.random.randint(num_classes)
229
+ st.write(f"\nRandom Prediction: {conditions[random_pred]}")
230
+
231
+ # Linear Model Prediction
232
+ linear_model.eval()
233
+ with torch.no_grad():
234
+ outputs = linear_model(user_tensor)
235
+ _, predicted = torch.max(outputs.data, 1)
236
+ linear_pred = predicted.item()
237
+ st.write(f"Linear Model Prediction: {conditions[linear_pred]}")
238
+
239
+ # Neural Network Prediction
240
+ neural_model.eval()
241
+ with torch.no_grad():
242
+ outputs = neural_model(user_tensor)
243
+ _, predicted = torch.max(outputs.data, 1)
244
+ neural_pred = predicted.item()
245
+ st.write(f"Neural Network Prediction: {conditions[neural_pred]}")