File size: 3,527 Bytes
b175ce8
db5ddfa
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
b175ce8
db5ddfa
 
 
 
 
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
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
import streamlit as st
import pandas as pd
import joblib

# =========================
# PAGE CONFIG / SAYFA AYARLARI
# =========================
st.set_page_config(page_title="Diamond Predictor", page_icon="💎", layout="wide")

# =========================
# LOAD MODEL / MODELİ YÜKLE
# =========================
@st.cache_resource
def load_model():
    # Model dosyasının adını kontrol et / Check model filename
    model = joblib.load('diamond_catboost_model.pkl')
    return model

model = load_model()

# =========================
# HEADER / BAŞLIK
# =========================
st.title("💎 Diamond Price Prediction App")
st.subheader("TR: Elmas Fiyat Tahmini Uygulaması | EN: Diamond Price Prediction Tool")
st.write("---")

# =========================
# SIDEBAR - INPUTS / YAN PANEL - GİRDİLER
# =========================
st.sidebar.header("🔧 Input Features / Girdi Özellikleri")

def get_user_inputs():
    carat = st.sidebar.number_input("Carat (Ağırlık)", 0.2, 5.0, 1.0, step=0.01)
    
    cut = st.sidebar.selectbox("Cut (Kesim)", 
                              ["Ideal", "Premium", "Very Good", "Good", "Fair"])
    
    color = st.sidebar.selectbox("Color (Renk)", 
                               ["D", "E", "F", "G", "H", "I", "J"])
    
    clarity = st.sidebar.selectbox("Clarity (Berraklık)", 
                                  ["IF", "VVS1", "VVS2", "VS1", "VS2", "SI1", "SI2", "I1"])
    
    depth = st.sidebar.slider("Depth (%)", 43.0, 79.0, 61.0)
    table = st.sidebar.slider("Table Width (%)", 43.0, 95.0, 57.0)
    
    col1, col2, col3 = st.sidebar.columns(3)
    x = col1.number_input("X (mm)", 0.0, 11.0, 5.0)
    y = col2.number_input("Y (mm)", 0.0, 58.0, 5.0)
    z = col3.number_input("Z (mm)", 0.0, 31.0, 3.0)

    data = {
        'carat': carat, 'cut': cut, 'color': color, 'clarity': clarity,
        'depth': depth, 'table': table, 'x': x, 'y': y, 'z': z
    }
    return pd.DataFrame([data])

input_df = get_user_inputs()

# =========================
# MAIN DISPLAY / ANA EKRAN
# =========================
col_main1, col_main2 = st.columns([1, 1])

with col_main1:
    st.markdown("### 📋 Selected Features / Seçilen Özellikler")
    st.dataframe(input_df, use_container_width=True)

# =========================
# PREPROCESSING / VERİ ÖN İŞLEME
# =========================
# Create dummy variables
input_encoded = pd.get_dummies(input_df)

# Fix 'carat_group_mid' if missing (Modelin beklediği o özel sütun)
if "carat_group_mid" in model.feature_names_:
    input_encoded["carat_group_mid"] = input_df["carat"].iloc[0]

# Align with model features (Modelin beklediği sütun sırasına sok)
final_df = input_encoded.reindex(columns=model.feature_names_, fill_value=0)

# =========================
# PREDICTION / TAHMİN
# =========================
with col_main2:
    st.markdown("### 🎯 Prediction / Tahmin")
    
    if st.button("Predict Price / Fiyatı Tahmin Et"):
        prediction = model.predict(final_df)[0]
        
        st.balloons()
        st.success(f"💰 Estimated Price / Tahmini Fiyat: **${prediction:,.2f}**")
        
        # Additional Info / Ek Bilgi
        st.info("""
        **EN:** This prediction is based on the CatBoost model with 98% accuracy.  
        **TR:** Bu tahmin, %98 doğruluk oranına sahip CatBoost modeli tarafından yapılmıştır.
        """)

# =========================
# FOOTER / ALT BİLGİ
# =========================
st.write("---")
st.caption("Created by Esma | Diamond Price Prediction Project")