Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
|
@@ -4,6 +4,8 @@ import numpy as np
|
|
| 4 |
import os
|
| 5 |
import pandas as pd
|
| 6 |
import openpyxl
|
|
|
|
|
|
|
| 7 |
|
| 8 |
# Load the preprocessor
|
| 9 |
preprocessor_path = 'modelExports/preprocessor.pkl'
|
|
@@ -324,7 +326,7 @@ elif interface == "Batch Prediction":
|
|
| 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":
|
|
@@ -358,6 +360,21 @@ elif interface == "Batch Prediction":
|
|
| 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,4 +384,4 @@ st.sidebar.write(f"Total models available: {len(models)}")
|
|
| 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}%")
|
|
|
|
| 4 |
import os
|
| 5 |
import pandas as pd
|
| 6 |
import openpyxl
|
| 7 |
+
import zipfile
|
| 8 |
+
import io
|
| 9 |
|
| 10 |
# Load the preprocessor
|
| 11 |
preprocessor_path = 'modelExports/preprocessor.pkl'
|
|
|
|
| 326 |
st.header('Download Predictions')
|
| 327 |
download_option = st.radio(
|
| 328 |
"Choose how to download your predictions:",
|
| 329 |
+
("All Models in Separate Files", "Churn and Non-Churn in Separate Files", "Download All at Once")
|
| 330 |
)
|
| 331 |
|
| 332 |
if download_option == "All Models in Separate Files":
|
|
|
|
| 360 |
file_name=f'{model_name.lower().replace(" ", "_")}_non_churn_predictions.csv',
|
| 361 |
mime='text/csv',
|
| 362 |
)
|
| 363 |
+
elif download_option == "Download All at Once":
|
| 364 |
+
# Create a zip file containing all outputs
|
| 365 |
+
zip_buffer = io.BytesIO()
|
| 366 |
+
with zipfile.ZipFile(zip_buffer, "w") as zip_file:
|
| 367 |
+
for model_name, output_df in model_outputs.items():
|
| 368 |
+
csv_data = output_df.to_csv(index=False).encode('utf-8')
|
| 369 |
+
zip_file.writestr(f'{model_name.lower().replace(" ", "_")}_predictions.csv', csv_data)
|
| 370 |
+
zip_buffer.seek(0)
|
| 371 |
+
|
| 372 |
+
st.download_button(
|
| 373 |
+
label="Download All Predictions as ZIP",
|
| 374 |
+
data=zip_buffer,
|
| 375 |
+
file_name='all_model_predictions.zip',
|
| 376 |
+
mime='application/zip'
|
| 377 |
+
)
|
| 378 |
else:
|
| 379 |
st.info('Awaiting CSV or Excel file to be uploaded.')
|
| 380 |
|
|
|
|
| 384 |
st.sidebar.write(f"Models selected for prediction: {len(selected_models)}")
|
| 385 |
st.sidebar.write("### Model Accuracies")
|
| 386 |
for model, accuracy in model_accuracies.items():
|
| 387 |
+
st.sidebar.write(f"{model}: {accuracy}%")
|