Skip to content

Instantly share code, notes, and snippets.

@nithyadurai87
Created October 23, 2018 06:47
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save nithyadurai87/9d04097e006e2fe6c7a96b1da643cb3a to your computer and use it in GitHub Desktop.
Save nithyadurai87/9d04097e006e2fe6c7a96b1da643cb3a to your computer and use it in GitHub Desktop.
import os
import json
import pandas as pd
import numpy
from flask import Flask, render_template, request, jsonify
from pandas.io.json import json_normalize
from sklearn.externals import joblib
app = Flask(__name__)
port = int(os.getenv('PORT', 5500))
@app.route('/')
def home():
return render_template('index.html')
@app.route('/api/salepricemodel', methods=['POST'])
def salepricemodel():
if request.method == 'POST':
try:
post_data = request.get_json()
json_data = json.dumps(post_data)
s = pd.read_json(json_data)
p = joblib.load("./salepricemodel.pkl")
r = p.predict(s)
return str(r)
except Exception as e:
return (e)
if __name__ == '__main__':
app.run(host='0.0.0.0', port=port, debug=True)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment