-
Notifications
You must be signed in to change notification settings - Fork 1
/
app.py
80 lines (63 loc) · 2.37 KB
/
app.py
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
import pickle
import requests
import streamlit as st
from requests.auth import HTTPBasicAuth
import os
import json
from dotenv import load_dotenv, find_dotenv
load_dotenv(find_dotenv())
API_URL = "https://ml-api-phn4j6lmdq-uc.a.run.app"
BASIC_AUTH_USERNAME = os.getenv("BASIC_AUTH_USERNAME")
BASIC_AUTH_PASSWORD = os.getenv("BASIC_AUTH_PASSWORD")
# defining the function which will make the prediction using the data which the user inputs
def prediction(Gender, Married, ApplicantIncome, LoanAmount, Credit_History):
# Pre-processing user input
if Gender == "Masculino":
Gender = 0
else:
Gender = 1
if Married == "Solteiro":
Married = 0
else:
Married = 1
if Credit_History == "Com dividas":
Credit_History = 0
else:
Credit_History = 1
LoanAmount = LoanAmount / 1000
data = {
"Gender": Gender,
"Married": Married,
"ApplicantIncome": ApplicantIncome,
"LoanAmount": LoanAmount,
"Credit_History": Credit_History
}
prediction = requests.post(API_URL + '/score', json=data, auth=HTTPBasicAuth(BASIC_AUTH_USERNAME, BASIC_AUTH_PASSWORD))
if prediction == 0:
pred = 'Rejected'
else:
pred = 'Approved'
return pred
# this is the main function in which we define our webpage
def main():
# front end elements of the web page
html_temp = """
<div style ="background-color:yellow;padding:13px">
<h1 style ="color:black;text-align:center;">Consulta de emprestimo</h1>
</div>
"""
# display the front end aspect
st.markdown(html_temp, unsafe_allow_html = True)
# following lines create boxes in which user can enter data required to make prediction
Gender = st.selectbox('Gender',("Masculino","Feminino"))
Married = st.selectbox('Marital Status',("Solteiro","Casado"))
ApplicantIncome = st.number_input("Renda Mensal")
LoanAmount = st.number_input("Valor Emprestimo")
Credit_History = st.selectbox('Credit_History',("Com dividas","Sem dividas"))
result =""
# when 'Predict' is clicked, make the prediction and store it
if st.button("Predict"):
result = prediction(Gender, Married, ApplicantIncome, LoanAmount, Credit_History)
st.success('Your loan is {}'.format(result))
if __name__=='__main__':
main()