Spaces:
Runtime error
Runtime error
Update app.py
Browse files
app.py
CHANGED
|
@@ -0,0 +1,102 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import streamlit as st
|
| 2 |
+
import numpy as np
|
| 3 |
+
import pickle
|
| 4 |
+
import streamlit.components.v1 as components
|
| 5 |
+
from sklearn.preprocessing import LabelEncoder
|
| 6 |
+
le = LabelEncoder()
|
| 7 |
+
|
| 8 |
+
# Load the pickled model
|
| 9 |
+
def load_model():
|
| 10 |
+
return pickle.load(open('Credit_Card_Classification_LogisticRegression.pkl','rb'))
|
| 11 |
+
|
| 12 |
+
# Function for model prediction
|
| 13 |
+
def model_prediction(model, features):
|
| 14 |
+
predicted = str(model.predict(features)[0])
|
| 15 |
+
return predicted
|
| 16 |
+
|
| 17 |
+
def transform(text):
|
| 18 |
+
text = le.fit_transform(text)
|
| 19 |
+
return text[0]
|
| 20 |
+
|
| 21 |
+
def app_design():
|
| 22 |
+
# Add input fields for High, Open, and Low values
|
| 23 |
+
image = 'credit.png'
|
| 24 |
+
st.image(image, use_column_width=True)
|
| 25 |
+
|
| 26 |
+
st.subheader("Enter the following values:")
|
| 27 |
+
|
| 28 |
+
Gender= st.selectbox("Gender",('Yes','No'))
|
| 29 |
+
if Gender == 'Yes':
|
| 30 |
+
Gender = 1
|
| 31 |
+
else:
|
| 32 |
+
Gender = 0
|
| 33 |
+
Age= st.number_input("Age")
|
| 34 |
+
Debt= st.number_input("Debt")
|
| 35 |
+
Married= st.selectbox("Married",('Yes','No'))
|
| 36 |
+
if Married == 'Yes':
|
| 37 |
+
Married = 1
|
| 38 |
+
else:
|
| 39 |
+
Married = 0
|
| 40 |
+
BankCustomer= st.number_input("Bank Customer")
|
| 41 |
+
Industry= st.text_input("Industry")
|
| 42 |
+
Industry = transform([Industry])
|
| 43 |
+
Ethnicity= st.text_input("Ethnicity")
|
| 44 |
+
Ethnicity = transform([Ethnicity])
|
| 45 |
+
YearsEmployed = st.number_input("Years Employed")
|
| 46 |
+
PriorDefault= st.selectbox("Prior Default",('Yes','No'))
|
| 47 |
+
if PriorDefault == 'Yes':
|
| 48 |
+
PriorDefault = 1
|
| 49 |
+
else:
|
| 50 |
+
PriorDefault = 0
|
| 51 |
+
Employed= st.selectbox("Employed",('Yes','No'))
|
| 52 |
+
if Employed == 'Yes':
|
| 53 |
+
Employed = 1
|
| 54 |
+
else:
|
| 55 |
+
Employed = 0
|
| 56 |
+
CreditScore = st.number_input("Credit Score")
|
| 57 |
+
DriversLicense= st.selectbox("Drivers License",('Yes','No'))
|
| 58 |
+
if DriversLicense == 'Yes':
|
| 59 |
+
DriversLicense = 1
|
| 60 |
+
else:
|
| 61 |
+
DriversLicense = 0
|
| 62 |
+
Citizen= st.selectbox("Citizen",('ByBirth','ByOtherMeans'))
|
| 63 |
+
if Citizen == 'ByBirth':
|
| 64 |
+
Citizen = 1
|
| 65 |
+
else:
|
| 66 |
+
Citizen = 0
|
| 67 |
+
ZipCode= st.number_input("ZipCode")
|
| 68 |
+
Income= st.number_input("Income")
|
| 69 |
+
|
| 70 |
+
# Create a feature list from the user inputs
|
| 71 |
+
features = [[Gender, Age,Debt,Married,BankCustomer,Industry,Ethnicity,YearsEmployed,PriorDefault,Employed,CreditScore,DriversLicense,Citizen,ZipCode,Income]]
|
| 72 |
+
|
| 73 |
+
# Load the model
|
| 74 |
+
model = load_model()
|
| 75 |
+
|
| 76 |
+
# Make a prediction when the user clicks the "Predict" button
|
| 77 |
+
if st.button('Predict Status'):
|
| 78 |
+
predicted_value = model_prediction(model, features)
|
| 79 |
+
if(predicted_value==1):
|
| 80 |
+
st.success(f"The credit card is approved")
|
| 81 |
+
|
| 82 |
+
else:
|
| 83 |
+
st.success(f"The credit card is not approved")
|
| 84 |
+
|
| 85 |
+
|
| 86 |
+
|
| 87 |
+
|
| 88 |
+
def main():
|
| 89 |
+
|
| 90 |
+
# Set the app title and add your website name and logo
|
| 91 |
+
st.set_page_config(
|
| 92 |
+
page_title="Credit Card Classification Model",
|
| 93 |
+
page_icon=":chart_with_upwards_trend:",
|
| 94 |
+
)
|
| 95 |
+
|
| 96 |
+
|
| 97 |
+
st.title("Welcome to our Credit Card Classification Model!")
|
| 98 |
+
app_design()
|
| 99 |
+
|
| 100 |
+
|
| 101 |
+
if __name__ == '__main__':
|
| 102 |
+
main()
|