-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathapp.py
More file actions
152 lines (114 loc) · 6.32 KB
/
app.py
File metadata and controls
152 lines (114 loc) · 6.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
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
from flask import Flask, render_template, request, url_for
import numpy as np
from sklearn.linear_model import LinearRegression
from sklearn.preprocessing import PolynomialFeatures
import pickle
app = Flask(__name__, template_folder='Templates')
model_HP_EngineSize = pickle.load(
open('./Prediction_Model/model_price_from_engine_size_horsepower.pkl', 'rb'))
model_HP = pickle.load(
open('./Prediction_Model/model_price_from_horsepower.pkl', 'rb'))
model_highwaympg = pickle.load(
open('./Prediction_Model/model_price_from_highwaympg.pkl', 'rb'))
model_weight_from_lbh = pickle.load(
open('./Prediction_Model/model_weight_from_lbh.pkl', 'rb'))
model_weight_cityMPG_engineSize = pickle.load(
open('./Prediction_Model/model_weight_cityMPG_engineSize.pkl', 'rb'))
model_weight_from_lbh_enginesize_HP = pickle.load(
open('./Prediction_Model/model_weight_from_lbh_enginesize_HP.pkl', 'rb'))
model_city_mpg = pickle.load(
open('./Prediction_Model/model_city_mpg.pkl', 'rb'))
model_city_mpg_enigne_hp_wieght = pickle.load(
open('./Prediction_Model/predict_city_mpg_enigne_hp_wieght.pkl', 'rb'))
@app.route("/")
def hello():
return render_template('index.html')
@app.route("/tryPredict_HP_EngineSize")
def tryPredict():
return render_template('tryPredict_HP_EngineSize.html')
@app.route("/predict", methods=['POST'])
def predict():
engine_size = request.form['engine-size']
horsepower = request.form['horsepower']
prediction = model_HP_EngineSize.predict([[engine_size, horsepower]])
output = round(prediction[0], 2)
return render_template('predictions_HP_EngineSize.html', prediction_text=f'For an engine size = {engine_size} and horsepower = {horsepower} price can be estimated as ${output}')
@app.route("/tryPredict_HP")
def tryPredict_HP():
return render_template('tryPredict_HP.html')
@app.route("/predict_HP", methods=['POST'])
def predict_HP():
horsepower = request.form['horsepower']
prediction = model_HP.predict([[horsepower]])
output = round(prediction[0], 2)
return render_template('predictions_HP.html', prediction_text=f'For a horsepower = {horsepower} price can be estimated as ${output}')
@app.route("/tryPredict_highwaympg")
def tryPredict_highwaympg():
return render_template('tryPredict_highwaympg.html')
@app.route("/predict_highwaympg", methods=['POST'])
def predict_highwaympg():
highway_mpg = request.form['highway-mpg']
highway_mpg = np.array(highway_mpg)
poly = PolynomialFeatures(degree=11, include_bias=False)
poly_features = poly.fit_transform(highway_mpg.reshape(-1, 1))
prediction = model_highwaympg.predict(poly_features)
output = round(prediction[0], 2)
return render_template('predictions_highwaympg.html', prediction_text=f'For a Highway MPG = {highway_mpg} price can be estimated as ${output}')
@app.route("/tryPredict_weight_from_lbh")
def tryPredict_weight_from_lbh():
return render_template('tryPredict_weight_from_lbh.html')
@app.route("/predict_weight_from_lbh", methods=['POST'])
def predict_weight_from_lbh():
height = request.form['height']
width = request.form['width']
length = request.form['length']
prediction = model_weight_from_lbh.predict([[height, width, length]])
output = round(prediction[0], 2)
return render_template('predictions_weight_from_lbh.html', prediction_text=f'For height = {height}, length = {length} and width = {width} price can be estimated as ${output}')
@app.route("/tryPredict_weight_cityMPG_engineSize")
def tryPredict_weight_cityMPG_engineSize():
return render_template('tryPredict_cityMPG_engineSize.html')
@app.route("/predict_weight_cityMPG_engineSize", methods=['POST'])
def predict_weight_cityMPG_engineSize():
engine_size = request.form['engine-size']
citympg = request.form['city-mpg']
prediction = model_HP_EngineSize.predict([[engine_size, citympg]])
output = round(prediction[0], 2)
return render_template('predictions_cityMPG_engineSize.html', prediction_text=f'For an engine size = {engine_size} and city-mpg = {citympg} price can be estimated as ${output}')
@app.route("/tryPredict_weight_from_lbh_enginesize_HP")
def tryPredict_weight_from_lbh_enginesize_HP():
return render_template('tryPredict_weight_from_lbh_enginesize_HP.html')
@app.route("/predict_weight_from_lbh_enginesize_HP", methods=['POST'])
def predict_weight_from_lbh_enginesize_HP():
height = request.form['height']
width = request.form['width']
length = request.form['length']
engine_size = request.form['engine-size']
horsepower = request.form['horsepower']
prediction = model_weight_from_lbh_enginesize_HP.predict(
[[height, width, length, engine_size, horsepower]])
output = round(prediction[0], 2)
return render_template('predictions_weight_from_lbh_enginesize_HP.html', prediction_text=f'For height = {height}, length = {length}, width = {width}, engine size = {engine_size} and horsepower = {horsepower} price can be estimated as ${output}')
@app.route("/tryPredict_city_mpg")
def tryPredict_city_mpg():
return render_template('tryPredict_city_mpg.html')
@app.route("/predict_city_mpg", methods=['POST'])
def predict_city_mpg():
horsepower = request.form['horsepower']
prediction = model_city_mpg.predict([[horsepower]])
output = round(prediction[0], 2)
return render_template('predictions_city_mpg.html', prediction_text=f'For a horsepower = {horsepower} City MPG can be estimated as {output}')
@app.route("/tryPredict_city_mpg_enigne_hp_wieght")
def tryPredict_city_mpg_enigne_hp_wieght():
return render_template('tryPredict_city_mpg_enigne_hp_wieght.html')
@app.route("/predict_city_mpg_enigne_hp_wieght", methods=['POST'])
def predict_city_mpg_enigne_hp_wieght():
weight = request.form['weight']
engine_size = request.form['engine-size']
horsepower = request.form['horsepower']
prediction = model_city_mpg_enigne_hp_wieght.predict(
[[weight, engine_size, horsepower]])
output = round(prediction[0], 2)
return render_template('predict_city_mpg_enigne_hp_wieght.html', prediction_text=f'For weight = {weight}, engine size = {engine_size} and horsepower = {horsepower} City MPG can be estimated as {output}')
if __name__ == "__main__":
app.run()