Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
|
@@ -1 +1,44 @@
|
|
|
|
|
|
|
|
|
|
|
| 1 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import gradio as gr
|
| 2 |
+
import joblib
|
| 3 |
+
import pandas as pd
|
| 4 |
|
| 5 |
+
|
| 6 |
+
model = joblib.load('loan_RFmodel.joblib')
|
| 7 |
+
|
| 8 |
+
|
| 9 |
+
def predict_loan(gender, married, dependents, education, self_employed,
|
| 10 |
+
income, co_income, amount, term, history, area):
|
| 11 |
+
|
| 12 |
+
|
| 13 |
+
features = pd.DataFrame([[
|
| 14 |
+
gender, married, dependents, education, self_employed,
|
| 15 |
+
income, co_income, amount, term, history, area
|
| 16 |
+
]], columns=['Gender', 'Married', 'Dependents', 'Education', 'Self_Employed',
|
| 17 |
+
'ApplicantIncome', 'CoapplicantIncome', 'LoanAmount',
|
| 18 |
+
'Loan_Amount_Term', 'Credit_History', 'Property_Area'])
|
| 19 |
+
|
| 20 |
+
prediction = model.predict(features)[0]
|
| 21 |
+
return "✅ Loan Approved" if prediction == 1 else "❌ Loan Rejected"
|
| 22 |
+
|
| 23 |
+
demo = gr.Interface(
|
| 24 |
+
fn=predict_loan,
|
| 25 |
+
inputs=[
|
| 26 |
+
gr.Dropdown(choices=[(1, "Male"), (0, "Female")], label="Gender"),
|
| 27 |
+
gr.Dropdown(choices=[(1, "Yes"), (0, "No")], label="Married"),
|
| 28 |
+
gr.Number(label="Dependents (0, 1, 2, or 3)"),
|
| 29 |
+
gr.Dropdown(choices=[(0, "Graduate"), (1, "Not Graduate")], label="Education"),
|
| 30 |
+
gr.Dropdown(choices=[(1, "Yes"), (0, "No")], label="Self Employed"),
|
| 31 |
+
gr.Number(label="Applicant Income"),
|
| 32 |
+
gr.Number(label="Co-applicant Income"),
|
| 33 |
+
gr.Number(label="Loan Amount"),
|
| 34 |
+
gr.Number(label="Term (e.g. 360)"),
|
| 35 |
+
gr.Dropdown(choices=[(1, "Good"), (0, "Bad")], label="Credit History"),
|
| 36 |
+
gr.Dropdown(choices=[(0, "Rural"), (1, "Semiurban"), (2, "Urban")], label="Property Area")
|
| 37 |
+
],
|
| 38 |
+
outputs="text",
|
| 39 |
+
title="Loan Approval Predictor",
|
| 40 |
+
description="Enter applicant details to predict loan eligibility."
|
| 41 |
+
)
|
| 42 |
+
|
| 43 |
+
# 4. Launch with the correct settings for Hugging Face
|
| 44 |
+
demo.launch(server_name="0.0.0.0", server_port=7860)
|