Update app.py
Browse files
app.py
CHANGED
|
@@ -62,11 +62,27 @@ def predict_need_maintenance_for_batch ():
|
|
| 62 |
# if input is valid - return prediction
|
| 63 |
# in case of error - return appropriate error
|
| 64 |
try:
|
| 65 |
-
|
| 66 |
-
|
| 67 |
-
|
| 68 |
-
|
| 69 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 70 |
# Validate entire batch
|
| 71 |
validated_df = validate_and_prepare_input(input_df, model)
|
| 72 |
|
|
@@ -80,7 +96,7 @@ def predict_need_maintenance_for_batch ():
|
|
| 80 |
"status": "success", # overall batch status
|
| 81 |
"total_records": len(prediction_list),
|
| 82 |
"predictions": prediction_list, # simple list version
|
| 83 |
-
})
|
| 84 |
|
| 85 |
except InputValidationError as e:
|
| 86 |
return jsonify({
|
|
|
|
| 62 |
# if input is valid - return prediction
|
| 63 |
# in case of error - return appropriate error
|
| 64 |
try:
|
| 65 |
+
# Get the uploaded CSV file from the request
|
| 66 |
+
file = request.files ['file']
|
| 67 |
+
|
| 68 |
+
# Read the file into a DataFrame
|
| 69 |
+
input_df = pd.read_csv (file)
|
| 70 |
+
|
| 71 |
+
# Process the data to clean up and make it ready for prediction
|
| 72 |
+
# mostly we will use the file with same format as given in problem statement for batch prediction
|
| 73 |
+
|
| 74 |
+
# remove/drop engine condition column if present
|
| 75 |
+
input_df.drop(columns=['Engine Condition'], inplace=True, errors='ignore')
|
| 76 |
+
|
| 77 |
+
# update column names to replace space with _ (underscore)
|
| 78 |
+
input_df.columns = input_df.columns.str.replace(' ', '_')
|
| 79 |
+
|
| 80 |
+
# get all integer columns
|
| 81 |
+
int_columns = input_df.select_dtypes(include=['int64']).columns
|
| 82 |
+
|
| 83 |
+
# convert integer columns to float
|
| 84 |
+
int_columns[int_columns] = int_columns[int_columns].astype('float64')
|
| 85 |
+
|
| 86 |
# Validate entire batch
|
| 87 |
validated_df = validate_and_prepare_input(input_df, model)
|
| 88 |
|
|
|
|
| 96 |
"status": "success", # overall batch status
|
| 97 |
"total_records": len(prediction_list),
|
| 98 |
"predictions": prediction_list, # simple list version
|
| 99 |
+
})
|
| 100 |
|
| 101 |
except InputValidationError as e:
|
| 102 |
return jsonify({
|