-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathapp.py
221 lines (149 loc) · 6.81 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
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
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
# Import all the libraries
import streamlit as st
import pandas as pd
import numpy as np
import joblib
# Load all the pickle files
# onehotencoder = pickle.load(open('models/onehotencoder.pkl','rb'))
# lablencoder1 = pickle.load(open('models/lablencoder1.pkl','rb'))
# lablencoder2 = pickle.load(open('models/lablencoder2.pkl','rb'))
# scaler = pickle.load(open('models/scaler.pkl','rb'))
# regressor = joblib.load(os.path.expanduser('models/regressor.joblib'))
# with open('models/regressor.joblib', "rb") as f:
# regressor = joblib.load(f)
# Load the playstore data from google drive
# Load the data from google drive
URL = 'https://drive.google.com/file/d/1W188uw5A3Ru9W1ZOYziOYOy2tHS9Z9DT/view?usp=sharing'
path = 'https://drive.google.com/uc?export=download&id='+URL.split('/')[-2]
# Lets view the overall data
df12 = pd.read_csv(path)
st.write('# Car Price Predictor')
gif = 'https://cutewallpaper.org/24/driving-a-car-animated-gif/man-driving-car-stock-animation-car-animation-2d-character-animation-cute-cartoon-wallpapers.gif'
st.image(
gif, # I prefer to load the GIFs using GIPHY
width=200, # The actual size of most gifs on GIPHY are really small, and using the column-width parameter would make it weirdly big. So I would suggest adjusting the width manually!
)
with st.sidebar:
st.write('#### Please enter all the information of your car')
# Levy input
levy = st.slider("How much is the levy (export tax)?", 0, 2300, 0)
# manufacturer
manufacturer = st.selectbox(
label = "Who is your car's manufacturer.",
options = df12['manufacturer'].value_counts().index
)
# st.write('You selected:', manufacturer)
# model
model = st.selectbox(
label = "What is your car's Model.",
options = df12['model'].value_counts().index
)
# st.write('You selected:', Model)
# Prod. year
pyear = st.selectbox(
label = "What is your car's production year.",
options = sorted(df12['prd_yr'].unique().tolist(), reverse=True)
)
# st.write('You selected:', pyear)
# Category
category = st.selectbox(
label = "What is the category of your car?",
options = df12['category'].value_counts().index
)
# st.write('You selected:', Category)
# Leather interior
leatherintr = st.radio(
"Do your car has leather interior?",
('Yes', 'No'))
if leatherintr == 'Yes':
leather_intr = 1
else:
leather_intr = 0
# st.write('You selected:', leather_intr)
# fuel_typ
fuel_typ = st.selectbox(
label = "What is the fuel type of your car?",
options = df12['fuel_typ'].value_counts().index
)
# st.write('You selected:', fuel_typ)
# engine_vol input
engine_vol = st.slider(label = "What is the engine volume of your car?",
min_value=round(df12['engine_vol'].min(),1),
max_value=round(df12['engine_vol'].max(),1),
value=2.5)
# Turbo engine
engineturbo = st.radio(
"Do your car has turbo engine?",
('Yes', 'No'),1)
if engineturbo == 'Yes':
engine_turbo = 1
else:
engine_turbo = 0
# mileage input
mileage = st.slider(label = "What is the mileage (in km) of your car?",
min_value = round(df12['mileage(km)'].min(),1),
max_value = round(df12['mileage(km)'].max(),1),
value = float(round(df12['mileage(km)'].mean(),1))
)
# gear_box
gear_box = st.selectbox(
label = "What is the gear box type of your car?",
options = df12['gear_box'].value_counts().index
)
# gear_box
drive_wheels = st.selectbox(
label = "What is the drive wheel type of your car?",
options = df12['drive_wheels'].value_counts().index
)
# doors
doors = st.selectbox(
label = "How many doors are there in your car?",
options = df12['doors'].value_counts().index
)
# wheel
wheel = st.selectbox(
label = "What is the wheels type in your car?",
options = df12['wheel'].value_counts().index
)
# wheel
color = st.selectbox(
label = "What is the color of your car?",
options = df12['color'].value_counts().index
)
# airbags input
airbags = st.slider(label = "How many air bags are there in your car?",
min_value = int(round(df12['airbags'].min(),0)),
max_value = int(round(df12['airbags'].max(),0)),
value = int(round(df12['airbags'].mean(),0))
)
col = ['levy', 'manufacturer', 'model', 'prd_yr', 'category', 'leather_intr',
'fuel_typ', 'engine_vol', 'mileage(km)', 'gear_box', 'drive_wheels',
'doors', 'wheel', 'color', 'airbags', 'engine_turbo']
values = [[levy, manufacturer, model, pyear, category, leather_intr,
fuel_typ, engine_vol, mileage, gear_box, drive_wheels,
doors, wheel, color, airbags, engine_turbo]]
X_test = pd.DataFrame(values, columns = col)
try:
regressor = joblib.load('pkl/rnf_regressor.pkl')
except:
st.write('Newreg files are unable to load')
try:
# Code to test / execute
onehotencoder = joblib.load('pkl/OHE.pkl')
lablencoder1 = joblib.load('pkl/lbl_encoder_mnf.pkl')
lablencoder2 = joblib.load('pkl/lbl_encoder_mdl.pkl')
scaler = joblib.load('pkl/normalize.pkl')
except:
st.write('pickle files are unable to load')
try:
X_test_OHE = onehotencoder.transform(X_test[['category','fuel_typ','gear_box','drive_wheels','doors','wheel','color']])
X_test['manufacturer'] = lablencoder1.transform(X_test['manufacturer'])
X_test['model'] = lablencoder2.transform(X_test['model'])
X_test_rem = X_test.drop(['category','fuel_typ','gear_box','drive_wheels','doors','wheel','color'], axis =1 )
X_test_transformed = np.concatenate((X_test_rem , X_test_OHE) ,axis=1)
X_test_scale = scaler.transform(X_test_transformed)
prize = round(regressor.predict(X_test_scale)[0])
if st.button('Predict Price'):
st.write('### The estimated price of your car is just $' + str(prize) + "...!")
except:
st.write('Unable to predict.')