File size: 5,000 Bytes
972e6b6 666ee3d 972e6b6 666ee3d 972e6b6 666ee3d 972e6b6 666ee3d 972e6b6 666ee3d 972e6b6 666ee3d 972e6b6 666ee3d 972e6b6 666ee3d 972e6b6 666ee3d 972e6b6 666ee3d 972e6b6 666ee3d 972e6b6 666ee3d 972e6b6 666ee3d 972e6b6 666ee3d 972e6b6 666ee3d 972e6b6 666ee3d 972e6b6 666ee3d 972e6b6 666ee3d 972e6b6 666ee3d 972e6b6 666ee3d 972e6b6 666ee3d 972e6b6 666ee3d 972e6b6 666ee3d 972e6b6 666ee3d 972e6b6 666ee3d 972e6b6 666ee3d 972e6b6 666ee3d 972e6b6 666ee3d 972e6b6 666ee3d 972e6b6 |
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 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 |
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 = []
# ============================
# SCORING DETAIL (for chart)
# ============================
score_detail = {}
# ----------------------------
# INCOME (30%)
# ----------------------------
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
# ----------------------------
# EMPLOYMENT STATUS (20%)
# ----------------------------
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
# ----------------------------
# CREDIT HISTORY (30%)
# ----------------------------
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
# ----------------------------
# GPA (20%)
# ----------------------------
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
# ----------------------------
# FINAL DECISION
# ----------------------------
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"
# ============================
# CREATE BAR CHART
# ============================
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")
# ============================
# TEXT REPORT
# ============================
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
# ============================
# GRADIO UI
# ============================
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()
|