|
|
import gradio as gr |
|
|
import joblib |
|
|
import numpy as np |
|
|
|
|
|
|
|
|
model = joblib.load("model_loan_predector.pkl") |
|
|
|
|
|
|
|
|
def predict_loan(gender, married, education, self_employed, applicant_income, coapplicant_income, |
|
|
loan_amount, loan_term, credit_history, property_area): |
|
|
|
|
|
|
|
|
input_data = np.array([[ |
|
|
1 if gender == "Male" else 0, |
|
|
1 if married == "Yes" else 0, |
|
|
1 if education == "Graduate" else 0, |
|
|
1 if self_employed == "Yes" else 0, |
|
|
float(applicant_income), |
|
|
float(coapplicant_income), |
|
|
float(loan_amount), |
|
|
float(loan_term), |
|
|
int(credit_history), |
|
|
{"Rural": 0, "Semiurban": 1, "Urban": 2}[property_area] |
|
|
]]) |
|
|
|
|
|
|
|
|
prediction = model.predict(input_data)[0] |
|
|
prob = model.predict_proba(input_data)[0][1] |
|
|
|
|
|
|
|
|
if prob > 0.8: |
|
|
risk = "Low Risk" |
|
|
elif prob > 0.5: |
|
|
risk = "Medium Risk" |
|
|
else: |
|
|
risk = "High Risk" |
|
|
|
|
|
result = f"✅ Approved" if prediction == 1 else "❌ Not Approved" |
|
|
|
|
|
return { |
|
|
"Loan Status": result, |
|
|
"Approval Probability": f"{prob:.2%}", |
|
|
"Risk Category": risk |
|
|
} |
|
|
|
|
|
|
|
|
iface = gr.Interface( |
|
|
fn=predict_loan, |
|
|
inputs=[ |
|
|
gr.Radio(["Male", "Female"], label="Gender"), |
|
|
gr.Radio(["Yes", "No"], label="Married"), |
|
|
gr.Radio(["Graduate", "Not Graduate"], label="Education"), |
|
|
gr.Radio(["Yes", "No"], label="Self Employed"), |
|
|
gr.Number(label="Applicant Income"), |
|
|
gr.Number(label="Coapplicant Income"), |
|
|
gr.Number(label="Loan Amount (in ₹1000s)"), |
|
|
gr.Number(label="Loan Term (in Days)"), |
|
|
gr.Radio(["1", "0"], label="Credit History (1 = Good, 0 = Bad)"), |
|
|
gr.Radio(["Rural", "Semiurban", "Urban"], label="Property Area") |
|
|
], |
|
|
outputs=[ |
|
|
gr.Text(label="Loan Status"), |
|
|
gr.Text(label="Approval Probability"), |
|
|
gr.Text(label="Risk Category") |
|
|
], |
|
|
title="❄️ ICE — Intelligent Credit Evaluator", |
|
|
description="Enter applicant details to predict loan approval status with confidence score and risk level." |
|
|
) |
|
|
|
|
|
iface.launch() |
|
|
|