File size: 1,014 Bytes
8f07d0e 60b0c74 51daf15 b7b0b41 6e509d7 51daf15 f9f5174 cb4ea92 f50f99c 51daf15 f50f99c 51daf15 491c0e0 51daf15 7b19fd5 51daf15 7b19fd5 51daf15 7b19fd5 51daf15 | 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 | import streamlit as st
import pandas as pd
import numpy as np
import joblib
# Load model
model = joblib.load("src/final_model.pkl")
features = joblib.load("src/model_features.pkl")
st.title("🚗 Used Car Price Predictor")
# Simple inputs
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)
# Create dataframe
input_data = pd.DataFrame([{
"model_year": model_year,
"milage": milage,
"horsepower": horsepower,
"car_age": car_age,
"milage_per_year": milage_per_year
}])
# Feature alignment
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}")
|