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3 |
+
def credit_scoring_model(
|
| 4 |
+
name,
|
| 5 |
+
number,
|
| 6 |
+
job,
|
| 7 |
+
income,
|
| 8 |
+
employment_status,
|
| 9 |
+
credit_history,
|
| 10 |
+
gpa
|
| 11 |
+
):
|
| 12 |
+
score = 0
|
| 13 |
+
reasons = []
|
| 14 |
+
|
| 15 |
+
# ----------------------------
|
| 16 |
+
# INCOME (30%)
|
| 17 |
+
# ----------------------------
|
| 18 |
+
if income >= 15000000:
|
| 19 |
+
score += 30
|
| 20 |
+
reasons.append("Penghasilan sangat baik")
|
| 21 |
+
elif income >= 8000000:
|
| 22 |
+
score += 25
|
| 23 |
+
reasons.append("Penghasilan baik")
|
| 24 |
+
elif income >= 5000000:
|
| 25 |
+
score += 20
|
| 26 |
+
reasons.append("Penghasilan cukup")
|
| 27 |
+
else:
|
| 28 |
+
score += 10
|
| 29 |
+
reasons.append("Penghasilan rendah")
|
| 30 |
+
|
| 31 |
+
# ----------------------------
|
| 32 |
+
# EMPLOYMENT STATUS (20%)
|
| 33 |
+
# ----------------------------
|
| 34 |
+
if employment_status == "Tetap":
|
| 35 |
+
score += 20
|
| 36 |
+
reasons.append("Status pekerjaan tetap")
|
| 37 |
+
elif employment_status == "Kontrak":
|
| 38 |
+
score += 12
|
| 39 |
+
reasons.append("Status pekerjaan kontrak")
|
| 40 |
+
else:
|
| 41 |
+
score += 5
|
| 42 |
+
reasons.append("Status pekerjaan tidak tetap")
|
| 43 |
+
|
| 44 |
+
# ----------------------------
|
| 45 |
+
# CREDIT HISTORY (30%)
|
| 46 |
+
# ----------------------------
|
| 47 |
+
if credit_history == "Lancar":
|
| 48 |
+
score += 30
|
| 49 |
+
reasons.append("Riwayat kredit lancar")
|
| 50 |
+
elif credit_history == "Pernah Tunggakan":
|
| 51 |
+
score += 15
|
| 52 |
+
reasons.append("Pernah mengalami tunggakan")
|
| 53 |
+
else:
|
| 54 |
+
score += 5
|
| 55 |
+
reasons.append("Riwayat kredit buruk")
|
| 56 |
+
|
| 57 |
+
# ----------------------------
|
| 58 |
+
# GPA (20%) β OPTIONAL
|
| 59 |
+
# ----------------------------
|
| 60 |
+
if gpa >= 3.75:
|
| 61 |
+
score += 20
|
| 62 |
+
reasons.append("IPK sangat baik")
|
| 63 |
+
elif gpa >= 3.25:
|
| 64 |
+
score += 15
|
| 65 |
+
reasons.append("IPK baik")
|
| 66 |
+
elif gpa >= 3.0:
|
| 67 |
+
score += 10
|
| 68 |
+
reasons.append("IPK cukup")
|
| 69 |
+
else:
|
| 70 |
+
score += 5
|
| 71 |
+
reasons.append("IPK rendah / tidak tersedia")
|
| 72 |
+
|
| 73 |
+
# ----------------------------
|
| 74 |
+
# FINAL DECISION
|
| 75 |
+
# ----------------------------
|
| 76 |
+
if score >= 80:
|
| 77 |
+
grade = "A"
|
| 78 |
+
decision = "β
LAYAK KREDIT"
|
| 79 |
+
elif score >= 65:
|
| 80 |
+
grade = "B"
|
| 81 |
+
decision = "π‘ DIPERTIMBANGKAN"
|
| 82 |
+
elif score >= 50:
|
| 83 |
+
grade = "C"
|
| 84 |
+
decision = "π RISIKO MENENGAH"
|
| 85 |
+
else:
|
| 86 |
+
grade = "D"
|
| 87 |
+
decision = "β TIDAK LAYAK"
|
| 88 |
+
|
| 89 |
+
return f"""
|
| 90 |
+
π€ Nama : {name}
|
| 91 |
+
π Nomor : {number}
|
| 92 |
+
πΌ Pekerjaan : {job}
|
| 93 |
+
|
| 94 |
+
π HASIL CREDIT SCORING MODEL (CSM)
|
| 95 |
+
---------------------------------
|
| 96 |
+
Skor Total : {score} / 100
|
| 97 |
+
Grade : {grade}
|
| 98 |
+
Keputusan Kredit : {decision}
|
| 99 |
+
|
| 100 |
+
π§ Alasan Penilaian:
|
| 101 |
+
- """ + "\n- ".join(reasons) + """
|
| 102 |
+
|
| 103 |
+
π Catatan:
|
| 104 |
+
Model ini bersifat rule-based & explainable,
|
| 105 |
+
sesuai untuk simulasi Bank / Fintech / Audit.
|
| 106 |
+
"""
|
| 107 |
+
|
| 108 |
+
# ============================
|
| 109 |
+
# GRADIO UI (HF READY)
|
| 110 |
+
# ============================
|
| 111 |
+
with gr.Blocks() as demo:
|
| 112 |
+
gr.Markdown("## π¦ Credit Scoring Model (CSM)")
|
| 113 |
+
gr.Markdown(
|
| 114 |
+
"Simulasi penilaian kelayakan kredit berbasis **rule-based & explainable** "
|
| 115 |
+
"(cocok untuk Bank, Fintech, Audit, dan Governance)."
|
| 116 |
+
)
|
| 117 |
+
|
| 118 |
+
with gr.Row():
|
| 119 |
+
name = gr.Textbox(label="Nama Lengkap")
|
| 120 |
+
number = gr.Textbox(label="Nomor (HP / ID)")
|
| 121 |
+
|
| 122 |
+
job = gr.Textbox(label="Pekerjaan")
|
| 123 |
+
income = gr.Number(label="Penghasilan Bulanan (Rp)", value=5000000)
|
| 124 |
+
|
| 125 |
+
with gr.Row():
|
| 126 |
+
employment_status = gr.Dropdown(
|
| 127 |
+
["Tetap", "Kontrak", "Tidak Tetap"],
|
| 128 |
+
label="Status Pekerjaan"
|
| 129 |
+
)
|
| 130 |
+
credit_history = gr.Dropdown(
|
| 131 |
+
["Lancar", "Pernah Tunggakan", "Buruk"],
|
| 132 |
+
label="Riwayat Kredit"
|
| 133 |
+
)
|
| 134 |
+
|
| 135 |
+
gpa = gr.Slider(2.0, 4.0, step=0.01, label="IPK (Opsional)")
|
| 136 |
+
|
| 137 |
+
output = gr.Textbox(
|
| 138 |
+
label="Hasil Analisis Credit Scoring",
|
| 139 |
+
lines=18
|
| 140 |
+
)
|
| 141 |
+
|
| 142 |
+
submit = gr.Button("π Hitung Skor Kredit")
|
| 143 |
+
|
| 144 |
+
submit.click(
|
| 145 |
+
credit_scoring_model,
|
| 146 |
+
inputs=[
|
| 147 |
+
name,
|
| 148 |
+
number,
|
| 149 |
+
job,
|
| 150 |
+
income,
|
| 151 |
+
employment_status,
|
| 152 |
+
credit_history,
|
| 153 |
+
gpa
|
| 154 |
+
],
|
| 155 |
+
outputs=output
|
| 156 |
+
)
|
| 157 |
+
|
| 158 |
+
demo.launch()
|