Spaces:
Sleeping
Sleeping
File size: 2,044 Bytes
6551468 85e7810 711541e 06821a8 711541e 724fb8c 85e7810 6551468 711541e 85e7810 6551468 711541e 85e7810 711541e 6551468 85e7810 711541e 00854a8 85e7810 6551468 711541e 85e7810 711541e 85e7810 711541e 85e7810 802ee17 711541e 85e7810 711541e 85e7810 711541e 6551468 | 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 72 73 | #importing necessary packages and modules
import gradio as gr
import joblib
import numpy as np
# Load the trained loan model
model = joblib.load("loan_RFmodel.joblib")
#This function
#Takes input from user and uses the trained model to predict loan eligibility.
def predict_loan_status(
married,
dependents,
education,
applicant_income,
coapplicant_income,
loan_amount,
loan_amount_term,
credit_history,
property_area
):
#Encoding the categorical variables for model prediction
married = 1 if married == "Yes" else 0
education = 1 if education == "Graduate" else 0
property_area_map = {
"Urban": 2,
"Semiurban": 1,
"Rural": 0
}
property_area = property_area_map[property_area]
# Combine inputs into model-ready format
features = np.array([[
married,
dependents,
education,
applicant_income,
coapplicant_income,
loan_amount,
loan_amount_term,
credit_history,
property_area
]])
# Making prediction
prediction = model.predict(features)[0]
return "Loan Approved" if prediction == 1 else "Loan Rejected"
# Building the Gradio User Interface
Gardio_interface = gr.Interface(
fn=predict_loan_status,
inputs=[
gr.Radio(["Yes", "No"], label="Married"),
gr.Number(label="Number of Dependents"),
gr.Radio(["Graduate", "Not Graduate"], label="Education"),
gr.Number(label="Applicant Income"),
gr.Number(label="Coapplicant Income"),
gr.Number(label="Loan Amount"),
gr.Number(label="Loan Amount Term(Days)"),
gr.Radio([1, 0], label="Credit History (1 = Good, 0 = Bad)"),
gr.Radio(["Urban", "Semiurban", "Rural"], label="Property Area"),
],
outputs="text",
title="Loan Status Prediction System",
description="Predict whether a loan application will be approved or rejected using a trained machine learning model."
)
if __name__ == "__main__":
Gardio_interface.launch() |