|
|
import streamlit as st |
|
|
import joblib |
|
|
import pandas as pd |
|
|
|
|
|
|
|
|
model_path = "random_forest_model.pkl" |
|
|
model = joblib.load(model_path) |
|
|
|
|
|
|
|
|
st.title("Car Price Prediction") |
|
|
|
|
|
|
|
|
brand = st.text_input("Brand", "BMW") |
|
|
model_name = st.text_input("Model", "320i") |
|
|
year = st.number_input("Year", min_value=2000, max_value=2024, value=2018) |
|
|
mileage = st.number_input("Mileage (in km)", min_value=0, max_value=500000, value=50000) |
|
|
fuel_type = st.selectbox("Fuel Type", ["Petrol", "Diesel", "Hybrid", "Electric"]) |
|
|
engine_size = st.number_input("Engine Size (in liters)", min_value=0.5, max_value=6.0, value=2.0) |
|
|
|
|
|
|
|
|
def predict_price(brand, model_name, year, mileage, fuel_type, engine_size): |
|
|
|
|
|
input_data = pd.DataFrame([[brand, model_name, year, mileage, fuel_type, engine_size]], |
|
|
columns=["Brand", "Model", "Year", "Mileage", "Fuel Type", "Engine Size"]) |
|
|
|
|
|
|
|
|
prediction = model.predict(input_data) |
|
|
|
|
|
return f"Estimated Price: {prediction[0]:,.2f} €" |
|
|
|
|
|
|
|
|
if st.button("Predict Price"): |
|
|
result = predict_price(brand, model_name, year, mileage, fuel_type, engine_size) |
|
|
st.success(result) |