IbraahimLab's picture
first commit
6503da8 verified
import pandas as pd
import numpy as np
import joblib
import gradio as gr
gender_mapping = {'Male': 1, 'Female': 0}
married_mapping = {'Yes': 1, 'No': 0}
education_mapping = {'Graduate': 1, 'Not Graduate': 0}
self_employed_mapping = {'Yes': 1, 'No': 0}
property_area_mapping = {'Urban': 2, 'Semiurban': 1, 'Rural': 0}
credit_mapping = {'Yes': 1, 'No': 0}
dependents_mapping = {'0': 0, '1': 1, '2': 2, '3+': 3}
def predict_the_loan(gender, married, dependents, education, self_employed,
applicant_income, coapplicant_income, loan_amount,
loan_amount_term, credit_history, property_area):
gender = gender_mapping[gender]
married = married_mapping[married]
education = education_mapping[education]
self_employed = self_employed_mapping[self_employed]
property_area = property_area_mapping[property_area]
dependents = dependents_mapping[dependents]
credit_history = credit_mapping[credit_history]
input_data = pd.DataFrame({
'Gender': [gender],
'Married': [married],
'Dependents': [dependents],
'Education': [education],
'Self_Employed': [self_employed],
'ApplicantIncome': [applicant_income],
'CoapplicantIncome': [coapplicant_income],
'LoanAmount': [loan_amount],
'Loan_Amount_Term': [loan_amount_term],
'Credit_History': [credit_history],
'Property_Area': [property_area]
})
model = joblib.load("random_forest_model.pkl")
prediction = model.predict(input_data)[0]
return "Approved" if prediction == 1 else "Rejected"
app = gr.Interface(
fn=predict_the_loan,
inputs=[
gr.Dropdown(["Male", "Female"], label="Gender"),
gr.Radio(["Yes", "No"], label="Married"),
gr.Dropdown(["0", "1", "2", "3+"], label="Dependents"),
gr.Dropdown(["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"),
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="Prediction"),
title="AI-Powered Loan Approval Prediction System",
description="Enter the details and get the prediction"
)
app.launch()