Loan_Approval_Detection / src /streamlit_app.py
HarunDemircioglu11's picture
Update src/streamlit_app.py
5f306fc verified
import streamlit as st
import pickle
import numpy as np
import pandas as pd
import os
# Feature açıklamaları ve aralıklar
feature_info = {
"person_home_ownership_encoded": {
"label": "Ev Sahipliği Durumu (0: Kiracı, 1: Ev sahibi, 2: Diğer)",
"min": 0, "max": 2, "value": 0,
"help": "Kişinin ev sahipliği durumu (0: Kiracı, 1: Ev sahibi, 2: Diğer)"
},
"loan_int_rate": {
"label": "Kredi Faiz Oranı (%)",
"min": 0.0, "max": 40.0, "value": 5.0,
"help": "Kredinin faiz oranı. Yüzde olarak girin."
},
"loan_percent_income": {
"label": "Kredi/Gelir Oranı (%)",
"min": 0.0, "max": 100.0, "value": 30.0,
"help": "Kredi miktarının gelire oranı, yüzde olarak."
},
"loan_grade_encoded": {
"label": "Kredi Notu (0: A, 1: B, ..., 6: G, 7: Diğer)",
"min": 0, "max": 7, "value": 0,
"help": "Kredi notu kategorisi (0: A, 1: B, ..., 6: G, 7: Diğer)"
},
"int_income_ratio": {
"label": "Faiz/Gelir Oranı",
"min": 0.0, "max": 5.0, "value": 1.0,
"help": "Faiz oranının gelire oranı."
},
"grade_default_interaction": {
"label": "Not & Temerrüt Etkileşimi (0-3)",
"min": 0, "max": 3, "value": 0,
"help": "Kredi notu ile temerrüt etkileşimi."
},
"high_percent_income": {
"label": "Yüksek Gelir Oranı (0: Hayır, 1: Evet)",
"min": 0, "max": 1, "value": 0,
"help": "Kredi/giriş oranı yüksek mi? (0: Hayır, 1: Evet)"
},
"high_int_rate": {
"label": "Yüksek Faiz Oranı (0: Hayır, 1: Evet)",
"min": 0, "max": 1, "value": 0,
"help": "Faiz oranı yüksek mi? (0: Hayır, 1: Evet)"
},
"loan_to_income": {
"label": "Kredi / Gelir Oranı",
"min": 0.0, "max": 2.0, "value": 1.0,
"help": "Kredi tutarının gelirine oranı."
}
}
# Model ve feature isimlerini src klasöründen yükle
model_path = "src/loan.pkl"
if not os.path.exists(model_path):
st.error(f"Model dosyası bulunamadı: {model_path}")
st.stop()
with open(model_path, "rb") as file:
model, feature_names = pickle.load(file)
st.title("Loan Approval Prediction App")
st.markdown("Aşağıdaki bilgileri doldurun, başvurunuzun onaylanıp onaylanmayacağını tahmin edelim.")
user_input = []
for feat in feature_names:
info = feature_info.get(feat, {})
if "min" in info and "max" in info:
if isinstance(info["value"], int):
value = st.number_input(
info.get("label", feat),
min_value=info["min"], max_value=info["max"], value=info["value"],
help=info.get("help", "")
)
else:
value = st.number_input(
info.get("label", feat),
min_value=float(info["min"]), max_value=float(info["max"]), value=float(info["value"]),
help=info.get("help", "")
)
else:
value = st.number_input(feat, value=0.0)
user_input.append(value)
if st.button("Tahmin Et"):
X = pd.DataFrame([user_input], columns=feature_names)
prediction = model.predict(X)[0]
if prediction == 1:
st.success("🟢 **Tebrikler, Kredi Başvurunuz Onaylandı!**")
else:
st.error("🔴 **Üzgünüz, Başvurunuz Onaylanmadı.**")