LamaAl commited on
Commit
2d1db40
·
1 Parent(s): 96c4893

Create app.py

Browse files
Files changed (1) hide show
  1. app.py +64 -0
app.py ADDED
@@ -0,0 +1,64 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import pickle5
2
+ import streamlit as st
3
+
4
+ # loading the trained model
5
+ pickle_in = open('classifier.pkl', 'rb')
6
+ classifier = pickle5.load(pickle_in)
7
+
8
+
9
+ @st.cache()
10
+ # defining the function which will make the prediction using the data which the user inputs
11
+ def prediction(Gender, Married, ApplicantIncome, LoanAmount, Credit_History):
12
+ # Pre-processing user input
13
+ if Gender == "Male":
14
+ Gender = 0
15
+ else:
16
+ Gender = 1
17
+
18
+ if Married == "Unmarried":
19
+ Married = 0
20
+ else:
21
+ Married = 1
22
+
23
+ if Credit_History == "Unclear Debts":
24
+ Credit_History = 0
25
+ else:
26
+ Credit_History = 1
27
+
28
+ LoanAmount = LoanAmount / 1000
29
+
30
+ # Making predictions
31
+ prediction = classifier.predict(
32
+ [[Gender, Married, ApplicantIncome, LoanAmount, Credit_History]])
33
+
34
+ if prediction == 0:
35
+ pred = 'Rejected'
36
+ else:
37
+ pred = 'Approved'
38
+ return pred
39
+
40
+
41
+ # this is the main function in which we define our webpage
42
+ def main():
43
+ # front end elements of the web page
44
+ st.title("Streamlit Loan Prediction ML App By DSC PSAU ")
45
+
46
+ # display the front end aspect
47
+
48
+ # following lines create boxes in which user can enter data required to make prediction
49
+ Gender = st.selectbox('Gender', ("Male", "Female"))
50
+ Married = st.selectbox('Marital Status', ("Unmarried", "Married"))
51
+ ApplicantIncome = st.number_input("Applicants monthly income")
52
+ LoanAmount = st.number_input("Total loan amount")
53
+ Credit_History = st.selectbox('Credit_History', ("Unclear Debts", "No Unclear Debts"))
54
+ result = ""
55
+
56
+ # when 'Predict' is clicked, make the prediction and store it
57
+ if st.button("Predict"):
58
+ result = prediction(Gender, Married, ApplicantIncome, LoanAmount, Credit_History)
59
+ st.success('Your loan is {}'.format(result))
60
+ print(LoanAmount)
61
+
62
+
63
+ if __name__ == '__main__':
64
+ main()