Spaces:
Sleeping
Sleeping
Gokulnath2003
commited on
Commit
•
06b9cbb
1
Parent(s):
0b73ca6
Update app.py
Browse files
app.py
CHANGED
@@ -1,48 +1,79 @@
|
|
1 |
import streamlit as st
|
2 |
import pandas as pd
|
3 |
-
import joblib
|
4 |
import numpy as np
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
5 |
|
6 |
-
#
|
7 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
8 |
|
9 |
# Streamlit app
|
10 |
-
st.title('Used Car Price
|
11 |
-
|
12 |
-
#
|
13 |
-
st.
|
14 |
-
|
15 |
-
#
|
16 |
-
brand = st.
|
17 |
-
|
18 |
-
vehicle_age = st.
|
19 |
-
km_driven = st.
|
20 |
-
mileage = st.
|
21 |
-
engine = st.
|
22 |
-
max_power = st.
|
23 |
-
seats = st.
|
24 |
-
seller_type = st.
|
25 |
-
fuel_type = st.
|
26 |
-
transmission_type = st.
|
27 |
|
28 |
# Button to trigger the prediction
|
29 |
-
if st.
|
|
|
30 |
input_data = pd.DataFrame({
|
|
|
|
|
31 |
'vehicle_age': [vehicle_age],
|
32 |
'km_driven': [km_driven],
|
33 |
'mileage': [mileage],
|
34 |
'engine': [engine],
|
35 |
'max_power': [max_power],
|
36 |
'seats': [seats],
|
37 |
-
'brand': [brand],
|
38 |
-
'model': [model_input],
|
39 |
'seller_type': [seller_type],
|
40 |
'fuel_type': [fuel_type],
|
41 |
'transmission_type': [transmission_type]
|
42 |
})
|
43 |
|
|
|
|
|
|
|
44 |
# Predict the price
|
45 |
-
predicted_price = model.predict(
|
46 |
|
47 |
# Display the result
|
48 |
st.write(f'The predicted selling price for the car is: ₹ {predicted_price[0]:,.2f}')
|
|
|
1 |
import streamlit as st
|
2 |
import pandas as pd
|
|
|
3 |
import numpy as np
|
4 |
+
import joblib
|
5 |
+
from sklearn.ensemble import RandomForestRegressor
|
6 |
+
from sklearn.preprocessing import StandardScaler, OneHotEncoder
|
7 |
+
from sklearn.compose import ColumnTransformer
|
8 |
+
from sklearn.pipeline import Pipeline
|
9 |
+
|
10 |
+
# Load the trained Random Forest model
|
11 |
+
@st.cache
|
12 |
+
def load_model():
|
13 |
+
# Replace with path to your trained Random Forest model if necessary
|
14 |
+
return joblib.load('random_forest_model.pkl')
|
15 |
+
|
16 |
+
model = load_model()
|
17 |
+
|
18 |
+
# Sample Data
|
19 |
+
url = "https://raw.githubusercontent.com/manishkr1754/CarDekho_Used_Car_Price_Prediction/main/notebooks/data/cardekho_dataset.csv"
|
20 |
+
df = pd.read_csv(url)
|
21 |
+
|
22 |
+
# Extract features for preprocessing
|
23 |
+
num_features = ['vehicle_age', 'km_driven', 'mileage', 'engine', 'max_power', 'seats']
|
24 |
+
cat_features = ['brand', 'model', 'seller_type', 'fuel_type', 'transmission_type']
|
25 |
|
26 |
+
# Preprocessing pipeline
|
27 |
+
numeric_transformer = StandardScaler()
|
28 |
+
onehot_transformer = OneHotEncoder()
|
29 |
+
|
30 |
+
preprocessor = ColumnTransformer(
|
31 |
+
transformers=[
|
32 |
+
('num', numeric_transformer, num_features),
|
33 |
+
('cat', onehot_transformer, cat_features)
|
34 |
+
])
|
35 |
|
36 |
# Streamlit app
|
37 |
+
st.title('Used Car Price Prediction')
|
38 |
+
|
39 |
+
# Main form for user input
|
40 |
+
st.header('Enter Car Details')
|
41 |
+
|
42 |
+
# Input fields
|
43 |
+
brand = st.selectbox('Brand', df['brand'].unique())
|
44 |
+
model = st.text_input('Model', '')
|
45 |
+
vehicle_age = st.number_input('Vehicle Age (in years)', min_value=0, max_value=50, value=5)
|
46 |
+
km_driven = st.number_input('Kilometers Driven', min_value=0, max_value=300000, value=50000)
|
47 |
+
mileage = st.number_input('Mileage (kmpl)', min_value=0.0, max_value=50.0, value=15.0)
|
48 |
+
engine = st.number_input('Engine (cc)', min_value=500, max_value=5000, value=1500)
|
49 |
+
max_power = st.number_input('Max Power (bhp)', min_value=0, max_value=500, value=100)
|
50 |
+
seats = st.number_input('Seats', min_value=2, max_value=8, value=5)
|
51 |
+
seller_type = st.selectbox('Seller Type', df['seller_type'].unique())
|
52 |
+
fuel_type = st.selectbox('Fuel Type', df['fuel_type'].unique())
|
53 |
+
transmission_type = st.selectbox('Transmission Type', df['transmission_type'].unique())
|
54 |
|
55 |
# Button to trigger the prediction
|
56 |
+
if st.button('Predict Price'):
|
57 |
+
# Create input dataframe
|
58 |
input_data = pd.DataFrame({
|
59 |
+
'brand': [brand],
|
60 |
+
'model': [model],
|
61 |
'vehicle_age': [vehicle_age],
|
62 |
'km_driven': [km_driven],
|
63 |
'mileage': [mileage],
|
64 |
'engine': [engine],
|
65 |
'max_power': [max_power],
|
66 |
'seats': [seats],
|
|
|
|
|
67 |
'seller_type': [seller_type],
|
68 |
'fuel_type': [fuel_type],
|
69 |
'transmission_type': [transmission_type]
|
70 |
})
|
71 |
|
72 |
+
# Preprocess the input
|
73 |
+
input_data_transformed = preprocessor.fit_transform(input_data)
|
74 |
+
|
75 |
# Predict the price
|
76 |
+
predicted_price = model.predict(input_data_transformed)
|
77 |
|
78 |
# Display the result
|
79 |
st.write(f'The predicted selling price for the car is: ₹ {predicted_price[0]:,.2f}')
|