-
Notifications
You must be signed in to change notification settings - Fork 0
/
app.py
62 lines (44 loc) · 1.97 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
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
import numpy as np
from flask import Flask, request, jsonify, render_template
import pickle
app = Flask(__name__)
model = pickle.load(open('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
'''
#int_features = [int(x) for x in request.form.values()]
#final_features = np.array(int_features)
#final_features = np.append(final_features, [0]*51)
#final_features = np.reshape(final_features, (1, -1))
list_features = []
list_features = np.append(list_features, request.form.get('area'))
list_features = np.append(list_features, request.form.get('balcony'))
list_features = np.append(list_features, request.form.get('elevator'))
list_features = np.append(list_features, request.form.get('terrace'))
list_features = np.append(list_features, request.form.get('garden'))
list_features = np.append(list_features, request.form.get('garage'))
list_features = np.append(list_features, request.form.get('parking_spot'))
list_features = np.append(list_features, request.form.get('new'))
list_district = [0] * 36
district_number = int(request.form.get('district'))
list_district[district_number] = 1
list_features = np.append(list_features, list_district)
list_rooms = [0] * 11
rooms_number = int(request.form.get('rooms'))
list_rooms[rooms_number] = 1
list_features = np.append(list_features, list_rooms)
list_floors = [0] * 3
floors_number = int(request.form.get('floor'))
list_floors[floors_number] = 1
list_features = np.append(list_features, list_floors)
list_features = np.reshape(list_features, (1, -1))
prediction = model.predict(list_features)
output = int(prediction[0])
return render_template('index.html', prediction_text='Le prix de votre appartement est estimé à {} €.'.format(output))
if __name__ == "__main__":
app.run(debug=True)