LS_Predictor / app.py
cadifam's picture
Update app.py
d2f422d verified
raw
history blame contribute delete
No virus
2.53 kB
import numpy as np
import pandas as pd
import pickle
import gradio as gr
from catboost import CatBoostClassifier
clf = CatBoostClassifier()
clf.load_model("./loan_model.bin")
def predict(customerid: 0,
gender: 'Female',
married: 'No',
dependents: 2,
education: 'Graduate',
self_employed: 'Yes',
applicantincome: 50083.0,
coapplicantincome: 10.0,
loanamount: 100.0,
loan_amount_term: 24,
credit_history: 0,
property_area: 'Rural'):
prediction_array = np.array([customerid, gender, married, dependents, education, self_employed, applicantincome, coapplicantincome, loanamount, loan_amount_term, credit_history, property_area])
verdict = clf.predict(prediction_array)
if verdict >= 0.5:
print('Good Standing - Approved: "Applicant stand a higher chance paying back loan"')
else:
print('Bad Standing - Rejected: "Applicant stand a higher chance defaulting payment"')
with gr.Blocks() as demo:
with gr.Row() as row1:
customerid = gr.Slider(1,1000000000, label="ClientID", interactive = True)
gender = gr.Dropdown(choices=[0,1], label="Gender")
married = gr.Dropdown(choices=[0,1], label="Marital Status")
dependents = gr.Dropdown(choices=[0,1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19,20], label="Dependants")
education = gr.Dropdown(choices=["Graduate", "Not Graduate"], label="Education")
self_employed = gr.Dropdown(choices=[0,1], label="Employment Status")
applicantincome = gr.Slider(1,100000, label = "Applicant's Income", interactive = True)
coapplicantincome = gr.Slider(1,100000, label = "CoApplicant's Income", interactive = True)
loanamount = gr.Slider(1,100000, label = "Loan Amount", interactive = True)
loan_amount_term = gr.Slider(1,480, label = "Loan Period", interactive = True)
credit_history = gr.Dropdown(choices=[0,1], label="Credit history")
property_area = gr.Dropdown(choices=["Rural", "Urban"], label="Property Area")
submit = gr.Button(value = 'Predict')
output = gr.Textbox(label = "Verdict:", interactive = False)
submit.click(predict, input = [customerid, gender, married, dependents, education, self_employed, applicantincome, coapplicantincome, loanamount, loan_amount_term, credit_history, property_area], outputs = [output])
demo.launch(share = False, debut = False)