Team Ai
Apppublic

greenlights/gitapp

sourceHugging Faceupdated 4y agoView on Hugging Face
1likes
app.py40 linesDownload Raw Back to root
1import numpy as np2import json3from flask import Flask, request, jsonify, render_template4import pickle5 6app = Flask(__name__)7model = pickle.load(open('model.pkl', 'rb'))8 9@app.route('/')10def home():11    return render_template('index.html')12 13@app.route('/predict',methods=['POST'])14def predict():15    '''16    For rendering results on HTML GUI17    '''18    int_features = [int(x) for x in request.form.values()]19    final_features = [np.array(int_features)]20    prediction = model.predict(final_features)21 22    output = round(prediction[0], 2)23 24    return render_template('index.html', prediction_text='Salary is {}'.format(output))25 26 27@app.route('/predict_api',methods=['POST'])28def predict_api():29    '''30    For direct API calls trought request31    '''32    data = request.get_json(force=True)33    prediction = model.predict([np.array(list(data.values()))])34 35    output = prediction[0]36    return jsonify(output)37 38if __name__ == "__main__":39    app.run(debug=True)40