Upload folder using huggingface_hub
Browse files
app.py
CHANGED
|
@@ -2,13 +2,12 @@
|
|
| 2 |
import joblib
|
| 3 |
import pandas as pd
|
| 4 |
from flask import Flask, request, jsonify
|
| 5 |
-
from utils.validation import validate_and_prepare_input, InputValidationError
|
| 6 |
|
| 7 |
# Initialize Flask app with a name
|
| 8 |
pred_mainteanance_api = Flask ("Engine Maintenance Predictor")
|
| 9 |
|
| 10 |
# Load the trained churn prediction model
|
| 11 |
-
model = joblib.load ("best_eng_fail_pred_model.joblib")
|
| 12 |
|
| 13 |
# Define a route for the home page
|
| 14 |
@pred_mainteanance_api.get ('/')
|
|
@@ -21,34 +20,32 @@ def predict_need_maintenance ():
|
|
| 21 |
# Get JSON data from the request
|
| 22 |
engine_sensor_inputs = request.get_json ()
|
| 23 |
|
|
|
|
| 24 |
|
| 25 |
-
|
| 26 |
-
input_json = request.get_json()
|
| 27 |
-
input_df = pd.DataFrame([input_json])
|
| 28 |
|
| 29 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 30 |
|
| 31 |
-
|
|
|
|
| 32 |
|
| 33 |
-
|
| 34 |
-
|
| 35 |
-
"prediction": int(prediction)
|
| 36 |
-
})
|
| 37 |
|
| 38 |
-
|
| 39 |
-
|
| 40 |
-
|
| 41 |
-
|
| 42 |
-
|
| 43 |
-
}), 400
|
| 44 |
|
| 45 |
-
except Exception as e:
|
| 46 |
-
return jsonify({
|
| 47 |
-
"status": "error",
|
| 48 |
-
"error_type": "internal_error",
|
| 49 |
-
"message": "Unexpected server error"
|
| 50 |
-
}), 500
|
| 51 |
-
|
| 52 |
|
| 53 |
# Run the Flask app
|
| 54 |
if __name__ == "__main__":
|
|
|
|
| 2 |
import joblib
|
| 3 |
import pandas as pd
|
| 4 |
from flask import Flask, request, jsonify
|
|
|
|
| 5 |
|
| 6 |
# Initialize Flask app with a name
|
| 7 |
pred_mainteanance_api = Flask ("Engine Maintenance Predictor")
|
| 8 |
|
| 9 |
# Load the trained churn prediction model
|
| 10 |
+
model = joblib.load ("best_eng_fail_pred_model.joblib.joblib")
|
| 11 |
|
| 12 |
# Define a route for the home page
|
| 13 |
@pred_mainteanance_api.get ('/')
|
|
|
|
| 20 |
# Get JSON data from the request
|
| 21 |
engine_sensor_inputs = request.get_json ()
|
| 22 |
|
| 23 |
+
import datetime
|
| 24 |
|
| 25 |
+
current_year = datetime.datetime.now ().year # dynamic current year
|
|
|
|
|
|
|
| 26 |
|
| 27 |
+
# Extract relevant features from the input data
|
| 28 |
+
data_info = {
|
| 29 |
+
'Engine_rpm' : engine_sensor_inputs ['Engine_rpm'],
|
| 30 |
+
'Lub_oil_pressure' : engine_sensor_inputs ['Lub_oil_pressure'],
|
| 31 |
+
'Fuel_pressure' : engine_sensor_inputs ['Fuel_pressure'],
|
| 32 |
+
'Coolant_pressure' : engine_sensor_inputs ['Coolant_pressure'],
|
| 33 |
+
'lub_oil_temp' : engine_sensor_inputs ['lub_oil_temp'],
|
| 34 |
+
'Coolant_temp' : engine_sensor_inputs ['Coolant_temp']
|
| 35 |
+
}
|
| 36 |
|
| 37 |
+
# Convert the extracted data into a DataFrame
|
| 38 |
+
input_data = pd.DataFrame ([data_info])
|
| 39 |
|
| 40 |
+
# Enforce types - convert all to float
|
| 41 |
+
input_data = input_data.astype (float)
|
|
|
|
|
|
|
| 42 |
|
| 43 |
+
# Make prediction using the trained model
|
| 44 |
+
predicted_sales = model.predict (input_data).tolist ()[0]
|
| 45 |
+
|
| 46 |
+
# Return the prediction as a JSON response
|
| 47 |
+
return jsonify ({'NeedsMaintenance': predicted_sales})
|
|
|
|
| 48 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 49 |
|
| 50 |
# Run the Flask app
|
| 51 |
if __name__ == "__main__":
|