File size: 953 Bytes
d25b6dc |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 |
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)
|