Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
|
@@ -47,7 +47,6 @@ def process_uploaded_file(uploaded_file, required_columns):
|
|
| 47 |
|
| 48 |
# Standardize column names to uppercase and strip spaces
|
| 49 |
df.columns = df.columns.str.upper().str.strip()
|
| 50 |
-
# st.write("DataFrame columns:", df.columns.tolist())
|
| 51 |
|
| 52 |
# Standardize required columns to uppercase and strip spaces
|
| 53 |
required_columns_upper = [col.upper().strip() for col in required_columns]
|
|
@@ -321,16 +320,44 @@ elif interface == "Batch Prediction":
|
|
| 321 |
|
| 322 |
st.success('Batch predictions completed for all selected models.')
|
| 323 |
|
| 324 |
-
#
|
| 325 |
-
|
| 326 |
-
|
| 327 |
-
|
| 328 |
-
|
| 329 |
-
|
| 330 |
-
|
| 331 |
-
|
| 332 |
-
|
| 333 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 334 |
else:
|
| 335 |
st.info('Awaiting CSV or Excel file to be uploaded.')
|
| 336 |
|
|
@@ -340,4 +367,4 @@ st.sidebar.write(f"Total models available: {len(models)}")
|
|
| 340 |
st.sidebar.write(f"Models selected for prediction: {len(selected_models)}")
|
| 341 |
st.sidebar.write("### Model Accuracies")
|
| 342 |
for model, accuracy in model_accuracies.items():
|
| 343 |
-
st.sidebar.write(f"{model}: {accuracy}%")
|
|
|
|
| 47 |
|
| 48 |
# Standardize column names to uppercase and strip spaces
|
| 49 |
df.columns = df.columns.str.upper().str.strip()
|
|
|
|
| 50 |
|
| 51 |
# Standardize required columns to uppercase and strip spaces
|
| 52 |
required_columns_upper = [col.upper().strip() for col in required_columns]
|
|
|
|
| 320 |
|
| 321 |
st.success('Batch predictions completed for all selected models.')
|
| 322 |
|
| 323 |
+
# Download options
|
| 324 |
+
st.header('Download Predictions')
|
| 325 |
+
download_option = st.radio(
|
| 326 |
+
"Choose how to download your predictions:",
|
| 327 |
+
("All Models in Separate Files", "Churn and Non-Churn in Separate Files")
|
| 328 |
+
)
|
| 329 |
+
|
| 330 |
+
if download_option == "All Models in Separate Files":
|
| 331 |
+
# Allow user to download the results for each model
|
| 332 |
+
for model_name, output_df in model_outputs.items():
|
| 333 |
+
csv = output_df.to_csv(index=False).encode('utf-8')
|
| 334 |
+
st.download_button(
|
| 335 |
+
label=f"Download {model_name} Predictions as CSV",
|
| 336 |
+
data=csv,
|
| 337 |
+
file_name=f'{model_name.lower().replace(" ", "_")}_predictions.csv',
|
| 338 |
+
mime='text/csv',
|
| 339 |
+
)
|
| 340 |
+
elif download_option == "Churn and Non-Churn in Separate Files":
|
| 341 |
+
# Consolidate results for all models and split into churn and non-churn files
|
| 342 |
+
for model_name, output_df in model_outputs.items():
|
| 343 |
+
churn_df = output_df[output_df['Churn'] == 'Yes']
|
| 344 |
+
non_churn_df = output_df[output_df['Churn'] == 'No']
|
| 345 |
+
|
| 346 |
+
churn_csv = churn_df.to_csv(index=False).encode('utf-8')
|
| 347 |
+
non_churn_csv = non_churn_df.to_csv(index=False).encode('utf-8')
|
| 348 |
+
|
| 349 |
+
st.download_button(
|
| 350 |
+
label=f"Download {model_name} Churn Predictions as CSV",
|
| 351 |
+
data=churn_csv,
|
| 352 |
+
file_name=f'{model_name.lower().replace(" ", "_")}_churn_predictions.csv',
|
| 353 |
+
mime='text/csv',
|
| 354 |
+
)
|
| 355 |
+
st.download_button(
|
| 356 |
+
label=f"Download {model_name} Non-Churn Predictions as CSV",
|
| 357 |
+
data=non_churn_csv,
|
| 358 |
+
file_name=f'{model_name.lower().replace(" ", "_")}_non_churn_predictions.csv',
|
| 359 |
+
mime='text/csv',
|
| 360 |
+
)
|
| 361 |
else:
|
| 362 |
st.info('Awaiting CSV or Excel file to be uploaded.')
|
| 363 |
|
|
|
|
| 367 |
st.sidebar.write(f"Models selected for prediction: {len(selected_models)}")
|
| 368 |
st.sidebar.write("### Model Accuracies")
|
| 369 |
for model, accuracy in model_accuracies.items():
|
| 370 |
+
st.sidebar.write(f"{model}: {accuracy}%")
|