Spaces:
Sleeping
Sleeping
Upload 5 files
Browse files- Dockerfile +3 -2
- app.py +47 -0
- model/dt_clf.joblib +3 -0
- predictor.py +39 -0
- requirements.txt +0 -3
Dockerfile
CHANGED
|
@@ -10,7 +10,8 @@ RUN apt-get update && apt-get install -y \
|
|
| 10 |
&& rm -rf /var/lib/apt/lists/*
|
| 11 |
|
| 12 |
COPY requirements.txt ./
|
| 13 |
-
COPY
|
|
|
|
| 14 |
|
| 15 |
RUN pip3 install -r requirements.txt
|
| 16 |
|
|
@@ -18,4 +19,4 @@ EXPOSE 8501
|
|
| 18 |
|
| 19 |
HEALTHCHECK CMD curl --fail http://localhost:8501/_stcore/health
|
| 20 |
|
| 21 |
-
ENTRYPOINT ["streamlit", "run", "
|
|
|
|
| 10 |
&& rm -rf /var/lib/apt/lists/*
|
| 11 |
|
| 12 |
COPY requirements.txt ./
|
| 13 |
+
COPY . .
|
| 14 |
+
# COPY src/ ./src/
|
| 15 |
|
| 16 |
RUN pip3 install -r requirements.txt
|
| 17 |
|
|
|
|
| 19 |
|
| 20 |
HEALTHCHECK CMD curl --fail http://localhost:8501/_stcore/health
|
| 21 |
|
| 22 |
+
ENTRYPOINT ["streamlit", "run", "app.py", "--server.port=8501", "--server.address=0.0.0.0"]
|
app.py
ADDED
|
@@ -0,0 +1,47 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import streamlit as st
|
| 2 |
+
from predictor import make_prediction
|
| 3 |
+
|
| 4 |
+
st.set_page_config(page_title='Webfala', page_icon='💰')
|
| 5 |
+
st.title('Webfala Loan Eligibility Predictor')
|
| 6 |
+
st.markdown("Provide your details to check if you're eligible for a loan")
|
| 7 |
+
|
| 8 |
+
#collect user inputs
|
| 9 |
+
full_name = st.text_input('Full name', placeholder='Enter your full name')
|
| 10 |
+
gender = st.selectbox('Gender', ['Female', 'Male'])
|
| 11 |
+
married = st.selectbox('Married', ['Yes', 'No'])
|
| 12 |
+
dependents = st.selectbox('Number of Dependents', ['0', '1', '2', '3', '3+'])
|
| 13 |
+
education = st.selectbox('Education', ['Graduate', 'Not Graduate'])
|
| 14 |
+
self_employed = st.selectbox('Self Employed', ['Yes', 'No'])
|
| 15 |
+
applicant_income = st.number_input('Applicant Income(₦)', min_value=0)
|
| 16 |
+
coapplicant_income = st.number_input('Co-applicant Income(₦)', min_value=0)
|
| 17 |
+
loan_amount = st.number_input('Loan Amount (in thousand ₦)', min_value=0)
|
| 18 |
+
loan_term = st.number_input('Loan term (in days: 0 - 365)', min_value=0)
|
| 19 |
+
credit_history = st.selectbox('Credit History', [1, 0])
|
| 20 |
+
property_area = st.selectbox('Property Area', ['Urban', 'Semiurban', 'Rural'])
|
| 21 |
+
|
| 22 |
+
#Bundle inputs
|
| 23 |
+
user_input = {
|
| 24 |
+
'Gender': gender,
|
| 25 |
+
'Married': married,
|
| 26 |
+
'Dependents': dependents,
|
| 27 |
+
'Education': education,
|
| 28 |
+
'Self_Employed': self_employed,
|
| 29 |
+
'ApplicantIncome': applicant_income,
|
| 30 |
+
'CoapplicantIncome': coapplicant_income,
|
| 31 |
+
'LoanAmount': loan_amount,
|
| 32 |
+
'Loan_Amount_Term': loan_term,
|
| 33 |
+
'Credit_History': credit_history,
|
| 34 |
+
'Property_Area': property_area
|
| 35 |
+
}
|
| 36 |
+
|
| 37 |
+
if st.button('Check Eligibility'):
|
| 38 |
+
with st.spinner("Analyzing..."):
|
| 39 |
+
pred, prob = make_prediction(user_input)
|
| 40 |
+
if pred == 1:
|
| 41 |
+
st.success(f"Dear {full_name}, you're eligible for this loan ")
|
| 42 |
+
else:
|
| 43 |
+
st.error(f"Dear {full_name}, sorry, you're not eligible for this loan")
|
| 44 |
+
st.info(f'Confidence: **{prob:.2f}** %')
|
| 45 |
+
|
| 46 |
+
st.markdown("---")
|
| 47 |
+
st.markdown("Copyright 2025")
|
model/dt_clf.joblib
ADDED
|
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
version https://git-lfs.github.com/spec/v1
|
| 2 |
+
oid sha256:c1e81f8aa83ffd9e86de9d1183ae8610e02074e074fbd0731a10b7e40729e231
|
| 3 |
+
size 2985
|
predictor.py
ADDED
|
@@ -0,0 +1,39 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import joblib
|
| 2 |
+
import numpy as np
|
| 3 |
+
import pandas as pd
|
| 4 |
+
|
| 5 |
+
#MODEL_PATH = 'model/dt_clf.joblib' #another method to load the model
|
| 6 |
+
model = joblib.load('model/dt_clf.joblib')
|
| 7 |
+
|
| 8 |
+
FEATURE_NAMES = ['Gender', 'Married', 'Dependents', 'Education',
|
| 9 |
+
'Self_Employed', 'ApplicantIncome', 'CoapplicantIncome', 'LoanAmount',
|
| 10 |
+
'Loan_Amount_Term', 'Credit_History', 'Property_Area']
|
| 11 |
+
|
| 12 |
+
def preprocess_input(user_input):
|
| 13 |
+
mapping = {
|
| 14 |
+
'Gender': {'Female': 0, 'Male': 1},
|
| 15 |
+
'Married': {"Yes": 1, 'No': 0},
|
| 16 |
+
'Education': {'Graduate': 1, 'Not Graduate': 0},
|
| 17 |
+
'Self_Employed': {'Yes': 1, 'No': 0},
|
| 18 |
+
'Property_Area': {'Rural': 0, "Semiurban": 1, 'Urban': 2},
|
| 19 |
+
'Dependents': {'0':0, '1':1, '2':2, '3':3, '3+':4}
|
| 20 |
+
}
|
| 21 |
+
|
| 22 |
+
processed = []
|
| 23 |
+
for feature in FEATURE_NAMES:
|
| 24 |
+
val = user_input[feature]
|
| 25 |
+
if feature in mapping:
|
| 26 |
+
val = mapping[feature][val]
|
| 27 |
+
processed.append(val)
|
| 28 |
+
|
| 29 |
+
return np.array(processed).reshape(1, -1)
|
| 30 |
+
|
| 31 |
+
def make_prediction(user_input):
|
| 32 |
+
try:
|
| 33 |
+
processed_input = preprocess_input(user_input)
|
| 34 |
+
pred = model.predict(processed_input)[0]
|
| 35 |
+
prob = model.predict_proba(processed_input).max()
|
| 36 |
+
return pred, prob
|
| 37 |
+
except Exception as e:
|
| 38 |
+
return f'Error: {str(e)}', 0.0
|
| 39 |
+
|
requirements.txt
CHANGED
|
@@ -1,3 +0,0 @@
|
|
| 1 |
-
altair
|
| 2 |
-
pandas
|
| 3 |
-
streamlit
|
|
|
|
|
|
|
|
|
|
|
|