SHARE
TWEET

Untitled

a guest Oct 20th, 2019 82 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. import numpy as np
  2. from flask import Flask, request, jsonify, render_template
  3. import pickle
  4.  
  5. app = Flask(__name__)
  6. model = pickle.load(open('model.pkl', 'rb'))
  7.  
  8. @app.route('/')
  9. def home():
  10.     return render_template('index.html')
  11.  
  12. @app.route('/predict',methods=['POST'])
  13. def predict():
  14.  
  15.     int_features = [int(x) for x in request.form.values()]
  16.     final_features = [np.array(int_features)]
  17.     prediction = model.predict(final_features)
  18.  
  19.     output = round(prediction[0], 2)
  20.  
  21.     return render_template('index.html', prediction_text='Sales should be $ {}'.format(output))
  22.  
  23. @app.route('/results',methods=['POST'])
  24. def results():
  25.  
  26.     data = request.get_json(force=True)
  27.     prediction = model.predict([np.array(list(data.values()))])
  28.  
  29.     output = prediction[0]
  30.     return jsonify(output)
  31.  
  32. if __name__ == "__main__":
  33.     app.run(debug=True)
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top