Spaces:
Sleeping
Sleeping
import gradio as gr | |
import numpy as np | |
import joblib | |
from sklearn.preprocessing import LabelEncoder, MinMaxScaler | |
def rf_predict(gn, mrg, dpnd, edu, slf_emp, app_inc, coapp_inc, l_am, l_am_tm, cr_hist, prp_area): | |
rf = joblib.load('RandomForest.pkl') | |
encoder = LabelEncoder() | |
scaler = MinMaxScaler() | |
ftr = np.array([gn, mrg, dpnd, edu, slf_emp, app_inc, coapp_inc, l_am, l_am_tm, cr_hist, prp_area]).reshape(1, -1) | |
for i in [0, 1, 2, 3, 4, 9, 10]: | |
ftr[:, i] = encoder.fit_transform(ftr[:, i].reshape(1,-1)) | |
for j in [5, 6, 7, 8]: | |
ftr[:, j] = scaler.fit_transform(ftr[:, j].reshape(1,-1)) | |
if rf.predict(ftr)==1: | |
return 'Yes' | |
elif rf.predict(ftr)==0: | |
return 'No' | |
rf_interface = gr.Interface( | |
fn=rf_predict, | |
inputs = [gr.Radio(['Male','Female'],label="Gender:"), | |
gr.Radio(['Yes','No'],label="Marital Status:"), | |
gr.Dropdown([0,1,2,'3+'],label="Dependents:"), | |
gr.Radio(['Graduate','Not Graduate'],label="Education Level:"), | |
gr.Radio(['Yes','No'],label="Self-Employed:"), | |
gr.Number(label="Applicant Income:"), | |
gr.Number(label="Copplicant Income:"), | |
gr.Number(label="Loan Amount:"), | |
gr.Number(label="Loan Amount Term:"), | |
gr.Radio(['Yes','No'],label="Credit History:"), | |
gr.Dropdown(['Urban','Semiurban','Rural'],label='Property Area:')], | |
outputs = gr.Textbox(label="Loan Approval", lines=1), | |
title="Random Forest Classifier [Manual]", | |
description="This interface uses Random Forest Classifier for the prediction of approval of Loans") | |
rf_interface.launch() |