first commit
Browse files
app.py
ADDED
|
@@ -0,0 +1,65 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import pandas as pd
|
| 2 |
+
import numpy as np
|
| 3 |
+
import joblib
|
| 4 |
+
import gradio as gr
|
| 5 |
+
|
| 6 |
+
gender_mapping = {'Male': 1, 'Female': 0}
|
| 7 |
+
married_mapping = {'Yes': 1, 'No': 0}
|
| 8 |
+
education_mapping = {'Graduate': 1, 'Not Graduate': 0}
|
| 9 |
+
self_employed_mapping = {'Yes': 1, 'No': 0}
|
| 10 |
+
property_area_mapping = {'Urban': 2, 'Semiurban': 1, 'Rural': 0}
|
| 11 |
+
credit_mapping = {'Yes': 1, 'No': 0}
|
| 12 |
+
dependents_mapping = {'0': 0, '1': 1, '2': 2, '3+': 3}
|
| 13 |
+
|
| 14 |
+
def predict_the_loan(gender, married, dependents, education, self_employed,
|
| 15 |
+
applicant_income, coapplicant_income, loan_amount,
|
| 16 |
+
loan_amount_term, credit_history, property_area):
|
| 17 |
+
|
| 18 |
+
gender = gender_mapping[gender]
|
| 19 |
+
married = married_mapping[married]
|
| 20 |
+
education = education_mapping[education]
|
| 21 |
+
self_employed = self_employed_mapping[self_employed]
|
| 22 |
+
property_area = property_area_mapping[property_area]
|
| 23 |
+
dependents = dependents_mapping[dependents]
|
| 24 |
+
credit_history = credit_mapping[credit_history]
|
| 25 |
+
|
| 26 |
+
input_data = pd.DataFrame({
|
| 27 |
+
'Gender': [gender],
|
| 28 |
+
'Married': [married],
|
| 29 |
+
'Dependents': [dependents],
|
| 30 |
+
'Education': [education],
|
| 31 |
+
'Self_Employed': [self_employed],
|
| 32 |
+
'ApplicantIncome': [applicant_income],
|
| 33 |
+
'CoapplicantIncome': [coapplicant_income],
|
| 34 |
+
'LoanAmount': [loan_amount],
|
| 35 |
+
'Loan_Amount_Term': [loan_amount_term],
|
| 36 |
+
'Credit_History': [credit_history],
|
| 37 |
+
'Property_Area': [property_area]
|
| 38 |
+
})
|
| 39 |
+
|
| 40 |
+
model = joblib.load("random_forest_model.pkl")
|
| 41 |
+
prediction = model.predict(input_data)[0]
|
| 42 |
+
|
| 43 |
+
return "Approved" if prediction == 1 else "Rejected"
|
| 44 |
+
|
| 45 |
+
app = gr.Interface(
|
| 46 |
+
fn=predict_the_loan,
|
| 47 |
+
inputs=[
|
| 48 |
+
gr.Dropdown(["Male", "Female"], label="Gender"),
|
| 49 |
+
gr.Radio(["Yes", "No"], label="Married"),
|
| 50 |
+
gr.Dropdown(["0", "1", "2", "3+"], label="Dependents"),
|
| 51 |
+
gr.Dropdown(["Graduate", "Not Graduate"], label="Education"),
|
| 52 |
+
gr.Radio(["Yes", "No"], label="Self Employed"),
|
| 53 |
+
gr.Number(label="Applicant Income"),
|
| 54 |
+
gr.Number(label="Coapplicant Income"),
|
| 55 |
+
gr.Number(label="Loan Amount"),
|
| 56 |
+
gr.Number(label="Loan Amount Term"),
|
| 57 |
+
gr.Radio(["Yes", "No"], label="Credit History"),
|
| 58 |
+
gr.Dropdown(["Urban", "Semiurban", "Rural"], label="Property Area")
|
| 59 |
+
],
|
| 60 |
+
outputs=gr.Textbox(label="Prediction"),
|
| 61 |
+
title="AI-Powered Loan Approval Prediction System",
|
| 62 |
+
description="Enter the details and get the prediction"
|
| 63 |
+
)
|
| 64 |
+
|
| 65 |
+
app.launch()
|