EAV123 commited on
Commit
79ec034
·
verified ·
1 Parent(s): 1af97d1

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +24 -13
app.py CHANGED
@@ -176,11 +176,12 @@ elif page == "Data Upload":
176
  progress_bar = st.progress(0)
177
  total_rows = len(df)
178
 
179
- # Initialize results columns
180
- df["Prediction"] = ""
181
- df["Rule Guidance"] = ""
182
- df["Model Prediction"] = ""
183
- df["Decision Reason"] = ""
 
184
 
185
  # Process each row with error handling
186
  for i, (index, row) in enumerate(df.iterrows()):
@@ -188,25 +189,35 @@ elif page == "Data Upload":
188
  # Skip rows with invalid data
189
  if (row['organism'] not in encoders['organism'] or
190
  row['antibiotic'] not in encoders['antibiotic']):
191
- df.at[index, "Prediction"] = "Invalid data"
192
  continue
193
 
 
 
 
 
 
 
 
194
  # Get full prediction result
195
- result = predict_susceptibility(row.to_dict(), model, encoders)
196
 
197
  # Store all results
198
  if "Error" in result:
199
- df.at[index, "Prediction"] = "Error: " + result["Error"]
200
  else:
201
- df.at[index, "Prediction"] = result["Final Output"]
202
- df.at[index, "Rule Guidance"] = result["Rule Guidance"]
203
- df.at[index, "Model Prediction"] = result["Model Prediction"]
204
- df.at[index, "Decision Reason"] = result["Decision Reason"]
205
  except Exception as e:
206
- df.at[index, "Prediction"] = f"Error: {str(e)}"
207
 
208
  # Update progress bar
209
  progress_bar.progress((i + 1) / total_rows)
 
 
 
210
 
211
  st.success("Predictions complete!")
212
 
 
176
  progress_bar = st.progress(0)
177
  total_rows = len(df)
178
 
179
+ # Create a new results DataFrame with the same index as the original
180
+ results_df = pd.DataFrame(index=df.index)
181
+ results_df["Prediction"] = ""
182
+ results_df["Rule Guidance"] = ""
183
+ results_df["Model Prediction"] = ""
184
+ results_df["Decision Reason"] = ""
185
 
186
  # Process each row with error handling
187
  for i, (index, row) in enumerate(df.iterrows()):
 
189
  # Skip rows with invalid data
190
  if (row['organism'] not in encoders['organism'] or
191
  row['antibiotic'] not in encoders['antibiotic']):
192
+ results_df.at[index, "Prediction"] = "Invalid data"
193
  continue
194
 
195
+ # Extract only the required columns for prediction
196
+ input_data = {
197
+ 'organism': row['organism'],
198
+ 'antibiotic': row['antibiotic'],
199
+ 'was_positive': row['was_positive']
200
+ }
201
+
202
  # Get full prediction result
203
+ result = predict_susceptibility(input_data, model, encoders)
204
 
205
  # Store all results
206
  if "Error" in result:
207
+ results_df.at[index, "Prediction"] = "Error: " + result["Error"]
208
  else:
209
+ results_df.at[index, "Prediction"] = result["Final Output"]
210
+ results_df.at[index, "Rule Guidance"] = result["Rule Guidance"]
211
+ results_df.at[index, "Model Prediction"] = result["Model Prediction"]
212
+ results_df.at[index, "Decision Reason"] = result["Decision Reason"]
213
  except Exception as e:
214
+ results_df.at[index, "Prediction"] = f"Error: {str(e)}"
215
 
216
  # Update progress bar
217
  progress_bar.progress((i + 1) / total_rows)
218
+
219
+ # Combine original data with results
220
+ df = pd.concat([df, results_df], axis=1)
221
 
222
  st.success("Predictions complete!")
223