| import streamlit as st |
| import pandas as pd |
| import numpy as np |
| import joblib |
|
|
| |
| model = joblib.load("src/final_model.pkl") |
| features = joblib.load("src/model_features.pkl") |
|
|
| st.title("🚗 Used Car Price Predictor") |
|
|
| |
| model_year = st.number_input("Model Year", 1990, 2024, 2018) |
| milage = st.number_input("Milage", 0, 500000, 50000) |
| horsepower = st.number_input("Horsepower", 50, 1500, 200) |
|
|
| car_age = 2024 - model_year |
| milage_per_year = milage / (car_age if car_age > 0 else 1) |
|
|
| |
| input_data = pd.DataFrame([{ |
| "model_year": model_year, |
| "milage": milage, |
| "horsepower": horsepower, |
| "car_age": car_age, |
| "milage_per_year": milage_per_year |
| }]) |
|
|
| |
| for col in features: |
| if col not in input_data.columns: |
| input_data[col] = 0 |
|
|
| input_data = input_data[features] |
|
|
| if st.button("Predict Price"): |
| prediction = model.predict(input_data) |
| prediction = np.expm1(prediction) |
| st.success(f"Estimated Price: ${prediction[0]:,.2f}") |
|
|