EAV123 commited on
Commit
5ae966a
·
verified ·
1 Parent(s): 0f1f788

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +31 -6
app.py CHANGED
@@ -120,12 +120,37 @@ elif page == "Data Upload":
120
  uploaded_file = st.file_uploader("Upload your CSV file", type=["csv"])
121
 
122
  if uploaded_file:
123
- df = pd.read_csv(uploaded_file)
124
- st.write("Uploaded Data Preview:", df.head())
125
-
126
- if st.button("Predict for Dataset"):
127
- df["Prediction"] = df.apply(lambda row: predict_susceptibility(row.to_dict(), model, encoders)["Final Output"], axis=1)
128
- st.write("Prediction Results", df)
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
129
 
130
  # About Page
131
  elif page == "About":
 
120
  uploaded_file = st.file_uploader("Upload your CSV file", type=["csv"])
121
 
122
  if uploaded_file:
123
+ try:
124
+ df = pd.read_csv(uploaded_file)
125
+ st.write("Uploaded Data Preview:", df.head())
126
+
127
+ # Validate the required columns
128
+ required_columns = ['organism', 'antibiotic', 'was_positive']
129
+ missing_columns = [col for col in required_columns if col not in df.columns]
130
+
131
+ if missing_columns:
132
+ st.error(f"The uploaded CSV is missing the following required columns: {', '.join(missing_columns)}")
133
+ else:
134
+ # Process predictions
135
+ if st.button("Predict for Dataset"):
136
+ with st.spinner("Processing predictions..."):
137
+ df["Prediction"] = df.apply(
138
+ lambda row: predict_susceptibility(row.to_dict(), model, encoders)["Final Output"], axis=1
139
+ )
140
+
141
+ st.success("Predictions complete!")
142
+ st.write("Prediction Results:", df)
143
+
144
+ # Optionally, download the results as a CSV
145
+ csv = df.to_csv(index=False)
146
+ st.download_button(
147
+ label="Download Results as CSV",
148
+ data=csv,
149
+ file_name="predictions.csv",
150
+ mime='text/csv'
151
+ )
152
+ except Exception as e:
153
+ st.error(f"Error reading the uploaded CSV file: {e}")
154
 
155
  # About Page
156
  elif page == "About":