ML_Assignment_7 / app.py
Hrridoyv2's picture
done!
22de844 verified
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)