Loan_Prediction / app.py
Edidixng's picture
Update app.py
3f1e62b verified
import gradio as gr
import joblib
import pandas as pd
# Load the model
model = joblib.load('loan_RFmodel.joblib')
def predict_loan(gender, married, dependents, education, self_employed,
income, co_income, amount, term, history, area):
# Model still receives the numbers (0, 1) from the dropdown values
features = pd.DataFrame([[
gender, married, dependents, education, self_employed,
income, co_income, amount, term, history, area
]], columns=['Gender', 'Married', 'Dependents', 'Education', 'Self_Employed',
'ApplicantIncome', 'CoapplicantIncome', 'LoanAmount',
'Loan_Amount_Term', 'Credit_History', 'Property_Area'])
prediction = model.predict(features)[0]
return "βœ… Loan Approved" if prediction == 1 else "❌ Loan Rejected"
# The Interface using the ("Label", Value) format
demo = gr.Interface(
fn=predict_loan,
inputs=[
# The FIRST item is what the user sees, the SECOND is the number the model gets
gr.Dropdown(choices=[("Male", 1), ("Female", 0)], label="Gender"),
gr.Dropdown(choices=[("Yes", 1), ("No", 0)], label="Married"),
gr.Dropdown(choices=[("0", 0), ("1", 1), ("2", 2), ("3+", 3)], label="Dependents"),
gr.Dropdown(choices=[("Graduate", 0), ("Not Graduate", 1)], label="Education"),
gr.Dropdown(choices=[("Yes", 1), ("No", 0)], label="Self Employed"),
gr.Number(label="Applicant Income"),
gr.Number(label="Co-applicant Income"),
gr.Number(label="Loan Amount"),
gr.Number(label="Term"),
gr.Dropdown(choices=[("Good", 1), ("Bad", 0)], label="Credit History"),
gr.Dropdown(choices=[("Rural", 0), ("Semiurban", 1), ("Urban", 2)], label="Property Area")
],
outputs="text",
title="🏦 Loan Approval Predictor Final"
)
# Crucial for Hugging Face deployment
demo.launch(server_name="0.0.0.0", server_port=7860)