pred / app.py
ramy21's picture
Deploy predictive maintenance model
d25b6dc
raw
history blame contribute delete
953 Bytes
from flask import Flask, request, jsonify
import joblib
import pandas as pd
app = Flask(__name__)
model = joblib.load("model.pkl")
@app.route("/predict", methods=["POST"])
def predict():
"""
Predict machine failure
Expected JSON format:
{
"Type": 1,
"Air temperature [K]": 300.0,
"Process temperature [K]": 310.0,
"Rotational speed [rpm]": 1500,
"Torque [Nm]": 40.0,
"Tool wear [min]": 100
}
"""
data = request.json
df = pd.DataFrame([data])
prediction = int(model.predict(df)[0])
probability = float(model.predict_proba(df)[0][1])
return jsonify({
"prediction": prediction,
"failure_probability": probability,
"status": "failure" if prediction == 1 else "normal"
})
@app.route("/health", methods=["GET"])
def health():
return jsonify({"status": "healthy"})
if __name__ == "__main__":
app.run(host="0.0.0.0", port=7860)