Spaces:
Build error
Build error
Commit ·
f4c3d7a
1
Parent(s): a42d546
Intial commit
Browse files
app.py
ADDED
|
@@ -0,0 +1,66 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
# importing required libraries
|
| 2 |
+
import pickle
|
| 3 |
+
import streamlit as st
|
| 4 |
+
|
| 5 |
+
# loading the trained model
|
| 6 |
+
pickle_in = open('classifier.pkl', 'rb')
|
| 7 |
+
classifier = pickle.load(pickle_in)
|
| 8 |
+
|
| 9 |
+
# this is the main function in which we define our app
|
| 10 |
+
def main():
|
| 11 |
+
# header of the page
|
| 12 |
+
html_temp = """
|
| 13 |
+
<div style ="background-color:yellow;padding:13px">
|
| 14 |
+
<h1 style ="color:black;text-align:center;">Check your Loan Eligibility</h1>
|
| 15 |
+
</div>
|
| 16 |
+
"""
|
| 17 |
+
st.markdown(html_temp, unsafe_allow_html = True)
|
| 18 |
+
|
| 19 |
+
# following lines create boxes in which user can enter data required to make prediction
|
| 20 |
+
Gender = st.selectbox('Gender',("Male","Female","Other"))
|
| 21 |
+
Married = st.selectbox('Marital Status',("Unmarried","Married","Other"))
|
| 22 |
+
ApplicantIncome = st.number_input("Monthly Income in Rupees")
|
| 23 |
+
LoanAmount = st.number_input("Loan Amount in Rupees")
|
| 24 |
+
result =""
|
| 25 |
+
|
| 26 |
+
# when 'Check' is clicked, make the prediction and store it
|
| 27 |
+
if st.button("Check"):
|
| 28 |
+
result = prediction(Gender, Married, ApplicantIncome, LoanAmount)
|
| 29 |
+
st.success('Your loan is {}'.format(result))
|
| 30 |
+
|
| 31 |
+
# defining the function which will make the prediction using the data which the user inputs
|
| 32 |
+
def prediction(Gender, Married, ApplicantIncome, LoanAmount):
|
| 33 |
+
|
| 34 |
+
# 2. Loading and Pre-processing the data
|
| 35 |
+
|
| 36 |
+
if Gender == "Male":
|
| 37 |
+
Gender = 0
|
| 38 |
+
else:
|
| 39 |
+
Gender = 1
|
| 40 |
+
|
| 41 |
+
if Married == "Married":
|
| 42 |
+
Married = 1
|
| 43 |
+
else:
|
| 44 |
+
Married = 0
|
| 45 |
+
|
| 46 |
+
#3. Building the model to automate Loan Eligibility
|
| 47 |
+
|
| 48 |
+
# if (ApplicantIncome >= 50000):
|
| 49 |
+
# loan_status = 'Approved'
|
| 50 |
+
# elif (LoanAmount < 500000):
|
| 51 |
+
# loan_status = 'Approved'
|
| 52 |
+
# else:
|
| 53 |
+
# loan_status = 'Rejected'
|
| 54 |
+
# return loan_status
|
| 55 |
+
|
| 56 |
+
prediction = classifier.predict(
|
| 57 |
+
[[Gender, Married, ApplicantIncome, LoanAmount]])
|
| 58 |
+
|
| 59 |
+
if prediction == 0:
|
| 60 |
+
pred = 'Rejected'
|
| 61 |
+
else:
|
| 62 |
+
pred = 'Approved'
|
| 63 |
+
return pred
|
| 64 |
+
|
| 65 |
+
if __name__=='__main__':
|
| 66 |
+
main()
|