Update app.py
Browse files
app.py
CHANGED
|
@@ -1,4 +1,5 @@
|
|
| 1 |
import gradio as gr
|
|
|
|
| 2 |
|
| 3 |
def credit_scoring_model(
|
| 4 |
name,
|
|
@@ -12,64 +13,81 @@ def credit_scoring_model(
|
|
| 12 |
score = 0
|
| 13 |
reasons = []
|
| 14 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 15 |
# ----------------------------
|
| 16 |
# INCOME (30%)
|
| 17 |
# ----------------------------
|
| 18 |
if income >= 15000000:
|
| 19 |
-
|
| 20 |
reasons.append("Penghasilan sangat baik")
|
| 21 |
elif income >= 8000000:
|
| 22 |
-
|
| 23 |
reasons.append("Penghasilan baik")
|
| 24 |
elif income >= 5000000:
|
| 25 |
-
|
| 26 |
reasons.append("Penghasilan cukup")
|
| 27 |
else:
|
| 28 |
-
|
| 29 |
reasons.append("Penghasilan rendah")
|
| 30 |
|
|
|
|
|
|
|
|
|
|
| 31 |
# ----------------------------
|
| 32 |
# EMPLOYMENT STATUS (20%)
|
| 33 |
# ----------------------------
|
| 34 |
if employment_status == "Tetap":
|
| 35 |
-
|
| 36 |
reasons.append("Status pekerjaan tetap")
|
| 37 |
elif employment_status == "Kontrak":
|
| 38 |
-
|
| 39 |
reasons.append("Status pekerjaan kontrak")
|
| 40 |
else:
|
| 41 |
-
|
| 42 |
reasons.append("Status pekerjaan tidak tetap")
|
| 43 |
|
|
|
|
|
|
|
|
|
|
| 44 |
# ----------------------------
|
| 45 |
# CREDIT HISTORY (30%)
|
| 46 |
# ----------------------------
|
| 47 |
if credit_history == "Lancar":
|
| 48 |
-
|
| 49 |
reasons.append("Riwayat kredit lancar")
|
| 50 |
elif credit_history == "Pernah Tunggakan":
|
| 51 |
-
|
| 52 |
reasons.append("Pernah mengalami tunggakan")
|
| 53 |
else:
|
| 54 |
-
|
| 55 |
reasons.append("Riwayat kredit buruk")
|
| 56 |
|
|
|
|
|
|
|
|
|
|
| 57 |
# ----------------------------
|
| 58 |
-
# GPA (20%)
|
| 59 |
# ----------------------------
|
| 60 |
if gpa >= 3.75:
|
| 61 |
-
|
| 62 |
reasons.append("IPK sangat baik")
|
| 63 |
elif gpa >= 3.25:
|
| 64 |
-
|
| 65 |
reasons.append("IPK baik")
|
| 66 |
elif gpa >= 3.0:
|
| 67 |
-
|
| 68 |
reasons.append("IPK cukup")
|
| 69 |
else:
|
| 70 |
-
|
| 71 |
reasons.append("IPK rendah / tidak tersedia")
|
| 72 |
|
|
|
|
|
|
|
|
|
|
| 73 |
# ----------------------------
|
| 74 |
# FINAL DECISION
|
| 75 |
# ----------------------------
|
|
@@ -86,7 +104,20 @@ def credit_scoring_model(
|
|
| 86 |
grade = "D"
|
| 87 |
decision = "β TIDAK LAYAK"
|
| 88 |
|
| 89 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 90 |
π€ Nama : {name}
|
| 91 |
π Nomor : {number}
|
| 92 |
πΌ Pekerjaan : {job}
|
|
@@ -102,17 +133,20 @@ Keputusan Kredit : {decision}
|
|
| 102 |
|
| 103 |
π Catatan:
|
| 104 |
Model ini bersifat rule-based & explainable,
|
| 105 |
-
|
| 106 |
"""
|
| 107 |
|
|
|
|
|
|
|
|
|
|
| 108 |
# ============================
|
| 109 |
-
# GRADIO UI
|
| 110 |
# ============================
|
| 111 |
with gr.Blocks() as demo:
|
| 112 |
gr.Markdown("## π¦ Credit Scoring Model (CSM)")
|
| 113 |
gr.Markdown(
|
| 114 |
-
"Simulasi penilaian kelayakan kredit berbasis
|
| 115 |
-
"
|
| 116 |
)
|
| 117 |
|
| 118 |
with gr.Row():
|
|
@@ -134,11 +168,13 @@ with gr.Blocks() as demo:
|
|
| 134 |
|
| 135 |
gpa = gr.Slider(2.0, 4.0, step=0.01, label="IPK (Opsional)")
|
| 136 |
|
| 137 |
-
|
| 138 |
label="Hasil Analisis Credit Scoring",
|
| 139 |
lines=18
|
| 140 |
)
|
| 141 |
|
|
|
|
|
|
|
| 142 |
submit = gr.Button("π Hitung Skor Kredit")
|
| 143 |
|
| 144 |
submit.click(
|
|
@@ -152,7 +188,7 @@ with gr.Blocks() as demo:
|
|
| 152 |
credit_history,
|
| 153 |
gpa
|
| 154 |
],
|
| 155 |
-
outputs=
|
| 156 |
)
|
| 157 |
|
| 158 |
demo.launch()
|
|
|
|
| 1 |
import gradio as gr
|
| 2 |
+
import matplotlib.pyplot as plt
|
| 3 |
|
| 4 |
def credit_scoring_model(
|
| 5 |
name,
|
|
|
|
| 13 |
score = 0
|
| 14 |
reasons = []
|
| 15 |
|
| 16 |
+
# ============================
|
| 17 |
+
# SCORING DETAIL (for chart)
|
| 18 |
+
# ============================
|
| 19 |
+
score_detail = {}
|
| 20 |
+
|
| 21 |
# ----------------------------
|
| 22 |
# INCOME (30%)
|
| 23 |
# ----------------------------
|
| 24 |
if income >= 15000000:
|
| 25 |
+
income_score = 30
|
| 26 |
reasons.append("Penghasilan sangat baik")
|
| 27 |
elif income >= 8000000:
|
| 28 |
+
income_score = 25
|
| 29 |
reasons.append("Penghasilan baik")
|
| 30 |
elif income >= 5000000:
|
| 31 |
+
income_score = 20
|
| 32 |
reasons.append("Penghasilan cukup")
|
| 33 |
else:
|
| 34 |
+
income_score = 10
|
| 35 |
reasons.append("Penghasilan rendah")
|
| 36 |
|
| 37 |
+
score += income_score
|
| 38 |
+
score_detail["Penghasilan"] = income_score
|
| 39 |
+
|
| 40 |
# ----------------------------
|
| 41 |
# EMPLOYMENT STATUS (20%)
|
| 42 |
# ----------------------------
|
| 43 |
if employment_status == "Tetap":
|
| 44 |
+
emp_score = 20
|
| 45 |
reasons.append("Status pekerjaan tetap")
|
| 46 |
elif employment_status == "Kontrak":
|
| 47 |
+
emp_score = 12
|
| 48 |
reasons.append("Status pekerjaan kontrak")
|
| 49 |
else:
|
| 50 |
+
emp_score = 5
|
| 51 |
reasons.append("Status pekerjaan tidak tetap")
|
| 52 |
|
| 53 |
+
score += emp_score
|
| 54 |
+
score_detail["Status Pekerjaan"] = emp_score
|
| 55 |
+
|
| 56 |
# ----------------------------
|
| 57 |
# CREDIT HISTORY (30%)
|
| 58 |
# ----------------------------
|
| 59 |
if credit_history == "Lancar":
|
| 60 |
+
credit_score = 30
|
| 61 |
reasons.append("Riwayat kredit lancar")
|
| 62 |
elif credit_history == "Pernah Tunggakan":
|
| 63 |
+
credit_score = 15
|
| 64 |
reasons.append("Pernah mengalami tunggakan")
|
| 65 |
else:
|
| 66 |
+
credit_score = 5
|
| 67 |
reasons.append("Riwayat kredit buruk")
|
| 68 |
|
| 69 |
+
score += credit_score
|
| 70 |
+
score_detail["Riwayat Kredit"] = credit_score
|
| 71 |
+
|
| 72 |
# ----------------------------
|
| 73 |
+
# GPA (20%)
|
| 74 |
# ----------------------------
|
| 75 |
if gpa >= 3.75:
|
| 76 |
+
gpa_score = 20
|
| 77 |
reasons.append("IPK sangat baik")
|
| 78 |
elif gpa >= 3.25:
|
| 79 |
+
gpa_score = 15
|
| 80 |
reasons.append("IPK baik")
|
| 81 |
elif gpa >= 3.0:
|
| 82 |
+
gpa_score = 10
|
| 83 |
reasons.append("IPK cukup")
|
| 84 |
else:
|
| 85 |
+
gpa_score = 5
|
| 86 |
reasons.append("IPK rendah / tidak tersedia")
|
| 87 |
|
| 88 |
+
score += gpa_score
|
| 89 |
+
score_detail["IPK"] = gpa_score
|
| 90 |
+
|
| 91 |
# ----------------------------
|
| 92 |
# FINAL DECISION
|
| 93 |
# ----------------------------
|
|
|
|
| 104 |
grade = "D"
|
| 105 |
decision = "β TIDAK LAYAK"
|
| 106 |
|
| 107 |
+
# ============================
|
| 108 |
+
# CREATE BAR CHART
|
| 109 |
+
# ============================
|
| 110 |
+
fig, ax = plt.subplots()
|
| 111 |
+
ax.bar(score_detail.keys(), score_detail.values())
|
| 112 |
+
ax.set_ylim(0, 30)
|
| 113 |
+
ax.set_title("Distribusi Skor Credit Scoring")
|
| 114 |
+
ax.set_ylabel("Skor")
|
| 115 |
+
ax.set_xlabel("Komponen Penilaian")
|
| 116 |
+
|
| 117 |
+
# ============================
|
| 118 |
+
# TEXT REPORT
|
| 119 |
+
# ============================
|
| 120 |
+
report = f"""
|
| 121 |
π€ Nama : {name}
|
| 122 |
π Nomor : {number}
|
| 123 |
πΌ Pekerjaan : {job}
|
|
|
|
| 133 |
|
| 134 |
π Catatan:
|
| 135 |
Model ini bersifat rule-based & explainable,
|
| 136 |
+
cocok untuk Bank, Fintech, Audit, dan Governance.
|
| 137 |
"""
|
| 138 |
|
| 139 |
+
return report, fig
|
| 140 |
+
|
| 141 |
+
|
| 142 |
# ============================
|
| 143 |
+
# GRADIO UI
|
| 144 |
# ============================
|
| 145 |
with gr.Blocks() as demo:
|
| 146 |
gr.Markdown("## π¦ Credit Scoring Model (CSM)")
|
| 147 |
gr.Markdown(
|
| 148 |
+
"Simulasi penilaian kelayakan kredit berbasis "
|
| 149 |
+
"**rule-based & explainable**."
|
| 150 |
)
|
| 151 |
|
| 152 |
with gr.Row():
|
|
|
|
| 168 |
|
| 169 |
gpa = gr.Slider(2.0, 4.0, step=0.01, label="IPK (Opsional)")
|
| 170 |
|
| 171 |
+
output_text = gr.Textbox(
|
| 172 |
label="Hasil Analisis Credit Scoring",
|
| 173 |
lines=18
|
| 174 |
)
|
| 175 |
|
| 176 |
+
output_plot = gr.Plot(label="Visual Distribusi Skor")
|
| 177 |
+
|
| 178 |
submit = gr.Button("π Hitung Skor Kredit")
|
| 179 |
|
| 180 |
submit.click(
|
|
|
|
| 188 |
credit_history,
|
| 189 |
gpa
|
| 190 |
],
|
| 191 |
+
outputs=[output_text, output_plot]
|
| 192 |
)
|
| 193 |
|
| 194 |
demo.launch()
|