|
|
import gradio as gr |
|
|
import matplotlib.pyplot as plt |
|
|
|
|
|
def credit_scoring_model( |
|
|
name, |
|
|
number, |
|
|
job, |
|
|
income, |
|
|
employment_status, |
|
|
credit_history, |
|
|
gpa |
|
|
): |
|
|
score = 0 |
|
|
reasons = [] |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
score_detail = {} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if income >= 15000000: |
|
|
income_score = 30 |
|
|
reasons.append("Penghasilan sangat baik") |
|
|
elif income >= 8000000: |
|
|
income_score = 25 |
|
|
reasons.append("Penghasilan baik") |
|
|
elif income >= 5000000: |
|
|
income_score = 20 |
|
|
reasons.append("Penghasilan cukup") |
|
|
else: |
|
|
income_score = 10 |
|
|
reasons.append("Penghasilan rendah") |
|
|
|
|
|
score += income_score |
|
|
score_detail["Penghasilan"] = income_score |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if employment_status == "Tetap": |
|
|
emp_score = 20 |
|
|
reasons.append("Status pekerjaan tetap") |
|
|
elif employment_status == "Kontrak": |
|
|
emp_score = 12 |
|
|
reasons.append("Status pekerjaan kontrak") |
|
|
else: |
|
|
emp_score = 5 |
|
|
reasons.append("Status pekerjaan tidak tetap") |
|
|
|
|
|
score += emp_score |
|
|
score_detail["Status Pekerjaan"] = emp_score |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if credit_history == "Lancar": |
|
|
credit_score = 30 |
|
|
reasons.append("Riwayat kredit lancar") |
|
|
elif credit_history == "Pernah Tunggakan": |
|
|
credit_score = 15 |
|
|
reasons.append("Pernah mengalami tunggakan") |
|
|
else: |
|
|
credit_score = 5 |
|
|
reasons.append("Riwayat kredit buruk") |
|
|
|
|
|
score += credit_score |
|
|
score_detail["Riwayat Kredit"] = credit_score |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if gpa >= 3.75: |
|
|
gpa_score = 20 |
|
|
reasons.append("IPK sangat baik") |
|
|
elif gpa >= 3.25: |
|
|
gpa_score = 15 |
|
|
reasons.append("IPK baik") |
|
|
elif gpa >= 3.0: |
|
|
gpa_score = 10 |
|
|
reasons.append("IPK cukup") |
|
|
else: |
|
|
gpa_score = 5 |
|
|
reasons.append("IPK rendah / tidak tersedia") |
|
|
|
|
|
score += gpa_score |
|
|
score_detail["IPK"] = gpa_score |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if score >= 80: |
|
|
grade = "A" |
|
|
decision = "β
LAYAK KREDIT" |
|
|
elif score >= 65: |
|
|
grade = "B" |
|
|
decision = "π‘ DIPERTIMBANGKAN" |
|
|
elif score >= 50: |
|
|
grade = "C" |
|
|
decision = "π RISIKO MENENGAH" |
|
|
else: |
|
|
grade = "D" |
|
|
decision = "β TIDAK LAYAK" |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
fig, ax = plt.subplots() |
|
|
ax.bar(score_detail.keys(), score_detail.values()) |
|
|
ax.set_ylim(0, 30) |
|
|
ax.set_title("Distribusi Skor Credit Scoring") |
|
|
ax.set_ylabel("Skor") |
|
|
ax.set_xlabel("Komponen Penilaian") |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
report = f""" |
|
|
π€ Nama : {name} |
|
|
π Nomor : {number} |
|
|
πΌ Pekerjaan : {job} |
|
|
|
|
|
π HASIL CREDIT SCORING MODEL (CSM) |
|
|
--------------------------------- |
|
|
Skor Total : {score} / 100 |
|
|
Grade : {grade} |
|
|
Keputusan Kredit : {decision} |
|
|
|
|
|
π§ Alasan Penilaian: |
|
|
- """ + "\n- ".join(reasons) + """ |
|
|
|
|
|
π Catatan: |
|
|
Model ini bersifat rule-based & explainable, |
|
|
cocok untuk Bank, Fintech, Audit, dan Governance. |
|
|
""" |
|
|
|
|
|
return report, fig |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
with gr.Blocks() as demo: |
|
|
gr.Markdown("## π¦ Credit Scoring Model (CSM)") |
|
|
gr.Markdown( |
|
|
"Simulasi penilaian kelayakan kredit berbasis " |
|
|
"**rule-based & explainable**." |
|
|
) |
|
|
|
|
|
with gr.Row(): |
|
|
name = gr.Textbox(label="Nama Lengkap") |
|
|
number = gr.Textbox(label="Nomor (HP / ID)") |
|
|
|
|
|
job = gr.Textbox(label="Pekerjaan") |
|
|
income = gr.Number(label="Penghasilan Bulanan (Rp)", value=5000000) |
|
|
|
|
|
with gr.Row(): |
|
|
employment_status = gr.Dropdown( |
|
|
["Tetap", "Kontrak", "Tidak Tetap"], |
|
|
label="Status Pekerjaan" |
|
|
) |
|
|
credit_history = gr.Dropdown( |
|
|
["Lancar", "Pernah Tunggakan", "Buruk"], |
|
|
label="Riwayat Kredit" |
|
|
) |
|
|
|
|
|
gpa = gr.Slider(2.0, 4.0, step=0.01, label="IPK (Opsional)") |
|
|
|
|
|
output_text = gr.Textbox( |
|
|
label="Hasil Analisis Credit Scoring", |
|
|
lines=18 |
|
|
) |
|
|
|
|
|
output_plot = gr.Plot(label="Visual Distribusi Skor") |
|
|
|
|
|
submit = gr.Button("π Hitung Skor Kredit") |
|
|
|
|
|
submit.click( |
|
|
credit_scoring_model, |
|
|
inputs=[ |
|
|
name, |
|
|
number, |
|
|
job, |
|
|
income, |
|
|
employment_status, |
|
|
credit_history, |
|
|
gpa |
|
|
], |
|
|
outputs=[output_text, output_plot] |
|
|
) |
|
|
|
|
|
demo.launch() |
|
|
|