MahmutCanBoran's picture
Upload app.py
7d0b642 verified
import streamlit as st
import numpy as np
import xgboost as xgb
# Sayfa ayarları
st.set_page_config(page_title="BMW Model Predictor", layout="centered")
st.title("🚗 BMW Model Predictor")
st.markdown("This app estimates the BMW model based on price, mileage, fuel type, engine power and vehicle type information.")
# Modeli yükle
model = xgb.XGBClassifier()
model.load_model("bmw_model.json")
# Sınıf listelerini yükle
fuel_classes = np.load("fuel_classes.npy", allow_pickle=True)
car_type_classes = np.load("car_type_classes.npy", allow_pickle=True)
target_classes = np.load("target_classes.npy", allow_pickle=True)
# Kullanıcı girişleri
price = st.number_input("💶 Price (EUR)", min_value=1000, max_value=200000, step=1000)
mileage = st.number_input("🛣️ Mileage (km)", min_value=0, max_value=400000, step=1000)
engine_power = st.number_input("⚙️ Engine Power (hp)", min_value=50, max_value=1000, step=10)
fuel_type = st.selectbox("⛽ Fuel Type", fuel_classes)
car_type = st.selectbox("🚘 Car Type", car_type_classes)
# Tahmin butonu
if st.button("Predict"):
try:
# Girdileri encode et
fuel_encoded = list(fuel_classes).index(fuel_type)
car_type_encoded = list(car_type_classes).index(car_type)
# Özellik vektörü oluştur
input_features = np.array([[engine_power, mileage, price, fuel_encoded, car_type_encoded]])
# Tahmin
prediction = model.predict(input_features)[0]
predicted_label = target_classes[prediction]
st.success(f"Predicted BMW model: **{predicted_label}**")
except Exception as e:
st.error(f"Something went wrong: {e}")