Spaces:
Runtime error
Runtime error
File size: 618 Bytes
3cfb08f 4a71f4f 3cfb08f | 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 | from flask import Flask, request, jsonify
import os, joblib, pandas as pd
app = Flask(__name__)
_model = None
def get_model():
global _model
if _model is None:
_model = joblib.load(os.path.join("models", "best_model.joblib"))
return _model
@app.get("/health")
def health():
return {"status": "ok"}
@app.post("/predict")
def predict():
payload = request.get_json(force=True)
X = pd.DataFrame([payload])
yhat = get_model().predict(X)
return jsonify({"prediction": float(yhat[0])})
if __name__ == "__main__":
app.run(host="0.0.0.0", port=int(os.environ.get("PORT", 7860))) |