Download src/app.py from sevvaliclal/UsedCarPricePredictor: direct link, hf CLI and curl.
- Browser
- Download file 1.01 kB
-
https://huggingface.co/spaces/sevvaliclal/UsedCarPricePredictor/resolve/main/src/app.py
- Command line
-
hf download hf://spaces/sevvaliclal/UsedCarPricePredictor/src/app.py
-
curl -L -o app.py https://huggingface.co/spaces/sevvaliclal/UsedCarPricePredictor/resolve/main/src/app.py
1.01 kB
| 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}") | |