You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

31 lines
733 B

from flask import Flask,request,jsonify
import joblib
import pandas as pd
# CREATE FLASK APP
app = Flask(__name__)
# CONNECT POST API CALL ---> predict() Function #http://localhost:5000/predict
@app.route('/predict',methods=['POST'])
def predict():
# GET JSON REQUEST
feat_data = request.json
# CONVERT JSON to PANDAS DF (col names)
df = pd.DataFrame(feat_data)
df = df.reindex(columns=col_names)
# PREDICT
prediction = list(model.predict(df))
return jsonify({'prediction':str(prediction)})
# LOAD MY MODEL and LOAD COLUMN NAMES
if __name__ == '__main__':
model = joblib.load("final_model.pkl")
col_names = joblib.load('column_names.pkl')
app.run(debug=True)