-
Notifications
You must be signed in to change notification settings - Fork 0
/
app.py
40 lines (31 loc) · 1.08 KB
/
app.py
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
26
27
28
29
30
31
32
33
34
35
36
37
38
39
import pickle
from flask import Flask,request,app, jsonify,url_for, render_template
import numpy as np
import pandas as pd
app=Flask(__name__)
# load model and scalar
regmodel=pickle.load(open('linear_reg.pkl', 'rb'))
scalar=pickle.load(open('scaling.pkl', 'rb'))
@app.route('/')
def home():
return render_template('home.html')
@app.route('/predict_api', methods=['POST'])
def predict_api():
data=request.json['data']
print(data)
print(np.array(list(data.values())).reshape(1, -1))
row = np.array(list(data.values())).reshape(1, -1)
row_scaled = scalar.fit_transform(row)
output=regmodel.predict(row_scaled)
print(f'prdicted: {output[0]}')
return jsonify(output[0])
@app.route('/predict', methods=['POST'])
def predict():
data=[float(i) for i in request.form.values()]
print(data)
row = np.array(data).reshape(1, -1)
final_input = scalar.fit_transform(row)
final_out=regmodel.predict(final_input)[0]
return render_template("home.html", text="Predicted home price is : {}".format(final_out))
if __name__=="__main__":
app.run(debug=True)