Arunachalam S commited on
Commit
02783b9
1 Parent(s): eb2a78b

added bigquery

Browse files
Files changed (2) hide show
  1. app.py +31 -6
  2. requirements.txt +3 -1
app.py CHANGED
@@ -1,7 +1,23 @@
1
  import streamlit as st
2
  import joblib
3
  import pandas as pd
 
 
4
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
5
  st.title("Welcome to ABC Bank")
6
 
7
  model = joblib.load('model_final.joblib')
@@ -11,9 +27,9 @@ with st.form('Loan Form',clear_on_submit=True):
11
  col1,col2 = st.columns(2)
12
  with col1:
13
  Gender = st.selectbox('Gender',('Male','Female'))
14
- Applicant_Income = st.number_input('Applicant Income',min_value=150)
15
  Coapplicant_Income = st.number_input('Co-applicant Income',min_value=0)
16
- Loan_amount = st.number_input('Loan Amount (In thousands)',min_value=5)
17
  Loan_Amount_Term = st.number_input('Loan Amount Term (Months)',min_value=12)
18
  with col2:
19
  Property_Area = st.selectbox('Property Area',('Urban','Rural','Semiurban'))
@@ -28,8 +44,8 @@ with st.form('Loan Form',clear_on_submit=True):
28
  'Dependents': [Dependents],
29
  'Education': [Education],
30
  'Self_Employed': [Self_Employed],
31
- 'Applicant_Income': [Applicant_Income],
32
- 'Coapplicant_Income': [Coapplicant_Income],
33
  'Loan_Amount': [Loan_amount],
34
  'Loan_Amount_Term': [Loan_Amount_Term],
35
  'Credit_History': [Credit_History],
@@ -41,14 +57,23 @@ with st.form('Loan Form',clear_on_submit=True):
41
  emi = ((principle*1000) + interest)/term
42
  return emi
43
  df['EMI'] = df.apply(lambda row: emi_calculator(row['Loan_Amount'],row['Loan_Amount_Term']),axis =1)
44
- df['Balance_Income'] = df['Applicant_Income'] + df['Coapplicant_Income'] - df['EMI']
 
 
45
  df.drop(columns = ['Applicant_Income','Coapplicant_Income','Loan_Amount','Loan_Amount_Term'])
46
 
47
  submit = st.form_submit_button('Predict')
48
  if submit:
49
  prediction = model.predict(df)
 
 
 
 
 
 
50
  if prediction:
51
- st.success('Congratulations, Your Home Loan is Approved!!')
 
52
  else:
53
  st.error('We are extremely sorry to inform you that you Home Loan is not approved. Please reach out to nearest branch for further clarification')
54
 
 
1
  import streamlit as st
2
  import joblib
3
  import pandas as pd
4
+ from google.cloud import bigquery
5
+ import datetime
6
 
7
+ # Retrieve the base64-encoded credentials from environment variables
8
+ encoded_credentials = os.getenv('BIGQUERY_KEY')
9
+
10
+ # Decode the base64-encoded credentials
11
+ decoded_credentials = base64.b64decode(encoded_credentials).decode('utf-8')
12
+
13
+ # Set Google Application Credentials
14
+ os.environ['GOOGLE_APPLICATION_CREDENTIALS'] = decoded_credentials
15
+ keypath = r'C:\Users\aruni\Project\Loan_Approval\youtube-analytics-keys.json'
16
+ dataset = 'home_loan'
17
+ table = 'home_loan_approval'
18
+ client = bigquery.Client()
19
+
20
+ table_ref = client.dataset(dataset).table(table)
21
  st.title("Welcome to ABC Bank")
22
 
23
  model = joblib.load('model_final.joblib')
 
27
  col1,col2 = st.columns(2)
28
  with col1:
29
  Gender = st.selectbox('Gender',('Male','Female'))
30
+ Applicant_Income = st.number_input('Applicant Income',min_value=15000)
31
  Coapplicant_Income = st.number_input('Co-applicant Income',min_value=0)
32
+ Loan_amount = st.number_input('Loan Amount (In Lakhs)',min_value=2)
33
  Loan_Amount_Term = st.number_input('Loan Amount Term (Months)',min_value=12)
34
  with col2:
35
  Property_Area = st.selectbox('Property Area',('Urban','Rural','Semiurban'))
 
44
  'Dependents': [Dependents],
45
  'Education': [Education],
46
  'Self_Employed': [Self_Employed],
47
+ 'Applicant_Income': [Applicant_Income/100],
48
+ 'Coapplicant_Income': [Coapplicant_Income/100],
49
  'Loan_Amount': [Loan_amount],
50
  'Loan_Amount_Term': [Loan_Amount_Term],
51
  'Credit_History': [Credit_History],
 
57
  emi = ((principle*1000) + interest)/term
58
  return emi
59
  df['EMI'] = df.apply(lambda row: emi_calculator(row['Loan_Amount'],row['Loan_Amount_Term']),axis =1)
60
+ df['EMI'] = round(df['EMI'],2)
61
+ df['Balance_Income'] = (df['Applicant_Income'] + df['Coapplicant_Income']) - df['EMI']
62
+ df['Balance_Income'] = round(df['Balance_Income'],2)
63
  df.drop(columns = ['Applicant_Income','Coapplicant_Income','Loan_Amount','Loan_Amount_Term'])
64
 
65
  submit = st.form_submit_button('Predict')
66
  if submit:
67
  prediction = model.predict(df)
68
+ df['_created_at'] = datetime.datetime.now()
69
+ df['_created_by'] = 'user'
70
+ df['Approval_Id'] = df['_created_by']+'-'+df['_created_at'].astype('str')
71
+ df['Prediction'] = prediction
72
+ job = client.load_table_from_dataframe(df, table_ref)
73
+ result = job.result()
74
  if prediction:
75
+
76
+ st.success(f'Congratulations, Your Home Loan is Approved!!')
77
  else:
78
  st.error('We are extremely sorry to inform you that you Home Loan is not approved. Please reach out to nearest branch for further clarification')
79
 
requirements.txt CHANGED
@@ -1,4 +1,6 @@
1
  streamlit==1.12.0
2
  pandas==2.0.3
3
  scikit-learn==1.2.2
4
- joblib==1.3.2
 
 
 
1
  streamlit==1.12.0
2
  pandas==2.0.3
3
  scikit-learn==1.2.2
4
+ joblib==1.3.2
5
+ xgboost==2.0.3
6
+ google-cloud-bigquery==3.25.0