MahmutCanBoran commited on
Commit
7d0b642
·
verified ·
1 Parent(s): d933213

Upload app.py

Browse files
Files changed (1) hide show
  1. app.py +44 -0
app.py ADDED
@@ -0,0 +1,44 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import streamlit as st
2
+ import numpy as np
3
+ import xgboost as xgb
4
+
5
+ # Sayfa ayarları
6
+ st.set_page_config(page_title="BMW Model Predictor", layout="centered")
7
+ st.title("🚗 BMW Model Predictor")
8
+
9
+ st.markdown("This app estimates the BMW model based on price, mileage, fuel type, engine power and vehicle type information.")
10
+
11
+ # Modeli yükle
12
+ model = xgb.XGBClassifier()
13
+ model.load_model("bmw_model.json")
14
+
15
+ # Sınıf listelerini yükle
16
+ fuel_classes = np.load("fuel_classes.npy", allow_pickle=True)
17
+ car_type_classes = np.load("car_type_classes.npy", allow_pickle=True)
18
+ target_classes = np.load("target_classes.npy", allow_pickle=True)
19
+
20
+ # Kullanıcı girişleri
21
+ price = st.number_input("💶 Price (EUR)", min_value=1000, max_value=200000, step=1000)
22
+ mileage = st.number_input("🛣️ Mileage (km)", min_value=0, max_value=400000, step=1000)
23
+ engine_power = st.number_input("⚙️ Engine Power (hp)", min_value=50, max_value=1000, step=10)
24
+
25
+ fuel_type = st.selectbox("⛽ Fuel Type", fuel_classes)
26
+ car_type = st.selectbox("🚘 Car Type", car_type_classes)
27
+
28
+ # Tahmin butonu
29
+ if st.button("Predict"):
30
+ try:
31
+ # Girdileri encode et
32
+ fuel_encoded = list(fuel_classes).index(fuel_type)
33
+ car_type_encoded = list(car_type_classes).index(car_type)
34
+
35
+ # Özellik vektörü oluştur
36
+ input_features = np.array([[engine_power, mileage, price, fuel_encoded, car_type_encoded]])
37
+
38
+ # Tahmin
39
+ prediction = model.predict(input_features)[0]
40
+ predicted_label = target_classes[prediction]
41
+
42
+ st.success(f"Predicted BMW model: **{predicted_label}**")
43
+ except Exception as e:
44
+ st.error(f"Something went wrong: {e}")