Spaces:
Running
Running
import gradio as gr | |
import joblib | |
# Load the trained model | |
model = joblib.load("loan_classifier.joblib") | |
# Load Standared Scaler | |
scalar = joblib.load("std_scaler.bin") | |
def predict_loan_status( | |
int_rate, | |
installment, | |
log_annual_inc, | |
dti, | |
fico, | |
revol_bal, | |
revol_util, | |
inq_last_6mths, | |
delinq_2yrs, | |
pub_rec, | |
installment_to_income_ratio, | |
credit_history, | |
): | |
input_dict = { | |
"int.rate": int_rate, | |
"installment": installment, | |
"log.annual.inc": log_annual_inc, | |
"dti": dti, | |
"fico": fico, | |
"revol.bal": revol_bal, | |
"revol.util": revol_util, | |
"inq.last.6mths": inq_last_6mths, | |
"delinq.2yrs": delinq_2yrs, | |
"pub.rec": pub_rec, | |
"installment_to_income_ratio": installment_to_income_ratio, | |
"credit_history": credit_history, | |
} | |
# Convert the dictionary to a 2D array | |
input_array = [list(input_dict.values())] | |
scaled_array = scalar.transform(input_array) | |
prediction = model.predict(scaled_array)[0] | |
if prediction == 0: | |
return "Loan fully paid" | |
else: | |
return "Loan not fully paid" | |
inputs = [ | |
gr.Slider(0.06, 0.23, step=0.01, label="Interest Rate"), | |
gr.Slider(100, 950, step=10, label="Installment"), | |
gr.Slider(7, 15, step=0.1, label="Log Annual Income"), | |
gr.Slider(0, 40, step=1, label="DTI Ratio"), | |
gr.Slider(600, 850, step=1, label="FICO Score"), | |
gr.Slider(0, 120000, step=1000, label="Revolving Balance"), | |
gr.Slider(0, 120, step=1, label="Revolving Utilization"), | |
gr.Slider(0, 10, step=1, label="Inquiries in Last 6 Months"), | |
gr.Slider(0, 20, step=1, label="Delinquencies in Last 2 Years"), | |
gr.Slider(0, 10, step=1, label="Public Records"), | |
gr.Slider(0, 5, step=0.1, label="Installment to Income Ratio"), | |
gr.Slider(0, 1, step=0.01, label="Credit History"), | |
] | |
outputs = [gr.Label(num_top_classes=2)] | |
title = "Loan Approval Classifier" | |
description = ( | |
"Enter the details of the loan applicant to check if the loan is approved or not." | |
) | |
gr.Interface( | |
fn=predict_loan_status, | |
inputs=inputs, | |
outputs=outputs, | |
title=title, | |
description=description, | |
).launch() | |