File size: 1,855 Bytes
22de844
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
import gradio as gr
import pandas as pd
import pickle

# =====================
# Load trained model
# =====================
with open("loan_rf_pipeline.pkl", "rb") as f:
    model = pickle.load(f)

# =====================
# Prediction logic
# =====================
def predict_loan(

    Gender, Married, Dependents, Education, Self_Employed,

    ApplicantIncome, CoapplicantIncome, LoanAmount,

    Loan_Amount_Term, Credit_History, Property_Area

):

    input_df = pd.DataFrame([[
        Gender, Married, Dependents, Education, Self_Employed,
        ApplicantIncome, CoapplicantIncome, LoanAmount,
        Loan_Amount_Term, Credit_History, Property_Area
    ]],
    columns=[
        'Gender', 'Married', 'Dependents', 'Education', 'Self_Employed',
        'ApplicantIncome', 'CoapplicantIncome', 'LoanAmount',
        'Loan_Amount_Term', 'Credit_History', 'Property_Area'
    ])

    prediction = model.predict(input_df)[0]

    return "✅ Loan Approved" if prediction == 1 else "❌ Loan Rejected"

# =====================
# App Interface
# =====================
inputs = [
    gr.Radio(["Male", "Female"], label="Gender"),
    gr.Radio(["Yes", "No"], label="Married"),
    gr.Dropdown(["0", "1", "2", "3+"], label="Dependents"),
    gr.Radio(["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 Term (months)", value=360),
    gr.Radio([1.0, 0.0], label="Credit History"),
    gr.Radio(["Urban", "Semiurban", "Rural"], label="Property Area")
]

app = gr.Interface(
    fn=predict_loan,
    inputs=inputs,
    outputs="text",
    title="Loan Approval Prediction System"
)

app.launch(share=True)