-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathapp.py
More file actions
108 lines (91 loc) · 3.19 KB
/
app.py
File metadata and controls
108 lines (91 loc) · 3.19 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
from flask import Flask, request, render_template
import pickle
import numpy as np
import os
app = Flask(__name__)
model = pickle.load(open('models/model.pkl', 'rb'))
def extract_numeric_part(term_str):
return ''.join(filter(str.isdigit, term_str))
@app.route('/')
def home():
return render_template("index.html")
@app.route('/predict', methods=['GET', 'POST'])
def predict():
if request.method == 'POST':
gender = request.form['gender']
married = request.form['married']
dependents = request.form['dependents']
education = request.form['education']
employed = request.form['employed']
credit = float(request.form['credit'])
area = request.form['area']
ApplicantIncome = float(request.form['ApplicantIncome'])
CoapplicantIncome = float(request.form['CoapplicantIncome'])
LoanAmount = float(request.form['LoanAmount'])
# gender
if gender == "Male":
male = 1
else:
male = 0
# married
if married == "Yes":
married_yes = 1
else:
married_yes = 0
# dependents
if dependents == '1':
dependents_1 = 1
dependents_2 = 0
dependents_3 = 0
elif dependents == '2':
dependents_1 = 0
dependents_2 = 1
dependents_3 = 0
elif dependents == "3+":
dependents_1 = 0
dependents_2 = 0
dependents_3 = 1
else:
dependents_1 = 0
dependents_2 = 0
dependents_3 = 0
# education
if education == "Not Graduate":
not_graduate = 1
else:
not_graduate = 0
# employed
if employed == "Yes":
employed_yes = 1
else:
employed_yes = 0
# property area
if area == "Semiurban":
semiurban = 1
urban = 0
elif area == "Urban":
semiurban = 0
urban = 1
else:
semiurban = 0
urban = 0
ApplicantIncomelog = np.log(ApplicantIncome)
totalincomelog = np.log(ApplicantIncome + CoapplicantIncome)
LoanAmountlog = np.log(LoanAmount)
# Extract numerical part from 'Loan_Amount_Term'
loan_term_str = request.form['Loan_Amount_Term']
loan_term_numeric = extract_numeric_part(loan_term_str)
# Convert to float
Loan_Amount_Term = float(loan_term_numeric)
prediction = model.predict([[credit, ApplicantIncomelog, LoanAmountlog, Loan_Amount_Term, totalincomelog, male, married_yes, dependents_1, dependents_2, dependents_3, not_graduate, employed_yes, semiurban, urban]])
if prediction == "N":
prediction = "No"
else:
prediction = "Yes"
return render_template("prediction.html", prediction_text="Your Loan Approval status is {}".format(prediction))
else:
return render_template("prediction.html")
if __name__ == "__main__":
# Use the PORT environment variable if available, otherwise default to 5000
port = int(os.environ.get("PORT", 5000))
app.run(host='0.0.0.0', port=port, debug=True)