-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathapp.py
More file actions
50 lines (40 loc) · 1.32 KB
/
app.py
File metadata and controls
50 lines (40 loc) · 1.32 KB
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
40
41
42
43
44
45
46
47
48
49
50
# -*- coding: utf-8 -*-
"""
Spyder Editor
This is a temporary script file.
"""
import numpy as np
from flask import Flask, request, jsonify, render_template
import pickle
app = Flask(__name__)
model = pickle.load(open('RandomForestRegression_model.pkl', 'rb'))
@app.route('/')
def home():
return render_template('index.html')
@app.route('/predict',methods=['POST'])
def predict():
'''
For rendering results on HTML GUI
'''
input_features = [int(x) for x in request.form.values()]
Area=input_features[0]
BHK=input_features[1]
Bathroom=input_features[2]
Parking=input_features[3]
Per_Sqft=input_features[4]
Type_Builder_Floor=input_features[5]
final_features = [np.array([Area, BHK, Bathroom, Parking, Per_Sqft, Type_Builder_Floor])]
Prediction = model.predict(final_features)
output = round(Prediction[0], 2)
return render_template('index.html', prediction_text='Housing Price would be ₹ {}'.format(output))
@app.route('/predict_api',methods=['POST'])
def predict_api():
'''
For direct API calls trought request
'''
data = request.get_json(force=True)
Prediction = model.predict([np.array(list(data.values()))])
output = Prediction[0]
return jsonify(output)
if __name__ == "__main__":
app.run(debug=True)