forked from rajtilakls2510/car_price_predictor
-
Notifications
You must be signed in to change notification settings - Fork 0
/
application.py
43 lines (31 loc) · 1.25 KB
/
application.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
from flask import Flask,render_template,request,redirect
from flask_cors import CORS,cross_origin
import pickle
import pandas as pd
import numpy as np
app=Flask(__name__)
cors=CORS(app)
model=pickle.load(open('LinearRegressionModel.pkl','rb'))
car=pd.read_csv('Cleaned_Car_data.csv')
@app.route('/',methods=['GET','POST'])
def index():
companies=sorted(car['company'].unique())
car_models=sorted(car['name'].unique())
year=sorted(car['year'].unique(),reverse=True)
fuel_type=car['fuel_type'].unique()
companies.insert(0,'Select Company')
return render_template('index.html',companies=companies, car_models=car_models, years=year,fuel_types=fuel_type)
@app.route('/predict',methods=['POST'])
@cross_origin()
def predict():
company=request.form.get('company')
car_model=request.form.get('car_models')
year=request.form.get('year')
fuel_type=request.form.get('fuel_type')
driven=request.form.get('kilo_driven')
prediction=model.predict(pd.DataFrame(columns=['name', 'company', 'year', 'kms_driven', 'fuel_type'],
data=np.array([car_model,company,year,driven,fuel_type]).reshape(1, 5)))
print(prediction)
return str(np.round(prediction[0],2))
if __name__=='__main__':
app.run()