-
Notifications
You must be signed in to change notification settings - Fork 0
/
app.py
45 lines (34 loc) · 1.33 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
from flask_cors import CORS
import numpy as np
from flask import Flask, request, jsonify, render_template
import pickle
import pandas as pd
import numpy as np
app = Flask(__name__)
cors= CORS(app)
model = pickle.load(open('LinearRegressionModel.pkl', 'rb'))
cpp=pd.read_csv('Cleaned_CPP_data.csv')
@app.route('/')
def home():
companies=sorted(cpp['company'].unique())
car_models=sorted(cpp['name'].unique())
year=sorted(cpp['year'].unique(),reverse=True)
fuel_type=cpp['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'])
def predict():
'''
For rendering results on HTML GUI
'''
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(debug=True)