File size: 2,249 Bytes
d69b07a a51e5f6 d69b07a a51e5f6 d69b07a a51e5f6 d69b07a a51e5f6 d69b07a a51e5f6 d69b07a a51e5f6 d69b07a a51e5f6 d69b07a a51e5f6 d69b07a a51e5f6 d69b07a a51e5f6 d69b07a a51e5f6 | 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 | import gradio as gr
import joblib
import numpy as np
# Load the pre-trained model
model = joblib.load("model_loan_predector.pkl")
# Define prediction function
def predict_loan(gender, married, education, self_employed, applicant_income, coapplicant_income,
loan_amount, loan_term, credit_history, property_area):
# Encode inputs manually (simulate label encoding)
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]
]])
# Predict
prediction = model.predict(input_data)[0]
prob = model.predict_proba(input_data)[0][1]
# Risk Level
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
}
# Gradio Interface
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()
|