-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathapp.py
More file actions
68 lines (55 loc) · 2.14 KB
/
Copy pathapp.py
File metadata and controls
68 lines (55 loc) · 2.14 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
from flask import Flask, render_template, request
import jsonify
import requests
import pickle
import numpy as np
import sklearn
import os
path = os.path.join('Models','randoforest_regression_model.pkl')
app = Flask(__name__)
model = pickle.load(open(path,'rb'))
@app.route('/',methods=['GET'])
def Home():
return render_template('index.html')
@app.route("/predict",methods=['POST'])
def predict():
if request.method == 'POST':
current_Year = 2021
Year = int(request.form['Year'])
if Year > current_Year:
return render_template('index.html',prediction_text="You can't sell this car")
Present_Price = int(request.form['Present_Price'])
Kms_Driven = int(request.form['Kms_Driven'])
Owner = int(request.form['Owner'])
Fuel_Type_Petrol = request.form['Fuel_Type_Petrol']
if Fuel_Type_Petrol == 'Petrol':
Fuel_Type_Petrol = 1
Fuel_Type_Diesel = 0
elif Fuel_Type_Petrol == 'Diesel':
Fuel_Type_Petrol = 0
Fuel_Type_Diesel = 1
else:
Fuel_Type_Petrol = 0
Fuel_Type_Diesel = 0
Year = current_Year - Year
Seller_Type_Individual = request.form['Seller_Type_Individual']
if Seller_Type_Individual == 'Individual':
Seller_Type_Individual = 1
else:
Seller_Type_Individual = 0
Transmission_Manual = request.form['Transmission_Manual']
if Transmission_Manual == 'Manual':
Transmission_Manual = 1
else:
Transmission_Manual = 0
prediction = model.predict([[Present_Price,Kms_Driven,Owner,Year,Fuel_Type_Diesel,Fuel_Type_Petrol,Seller_Type_Individual,Transmission_Manual]])
output = round(prediction[0],0)
if output < 0:
return render_template('index.html',prediction_text="You can't sell this car")
else:
return render_template('index.html',prediction_text="You can sell this car at {}".format(output))
else:
render_template('templates/index.html')
if __name__ == "__main__":
app.run(debug=True)
app.config['TEMPLATES_AUTO_RELOAD'] = True