File size: 3,418 Bytes
f31f205
8f104ab
7962c69
8f104ab
8e8fa12
f31f205
faa8739
f31f205
fc524a4
faa8739
f31f205
8e8fa12
ce08d4c
f31f205
 
 
faa8739
f31f205
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
import joblib
import pandas as pd
import streamlit as st
from huggingface_hub import hf_hub_download

REPO_ID = "chanyaphas/creditc"

access_token = st.secrets["HF_TOKEN"]

model = joblib.load(
    hf_hub_download(repo_id=REPO_ID, filename='model.joblib', token=access_token, repo_type="space")
)

unique_values = joblib.load(
    hf_hub_download(repo_id=REPO_ID, filename='unique_values.joblib', token=access_token, repo_type="space")
)

EDU_DICT = {'Lower secondary': 1,
            'Secondary / secondary special': 2,
            'Academic degree': 3,
            'Incomplete higher': 4,
            'Higher education' : 5
            }

def main():
    st.title("Credit Card Approval Prediction")

    with st.form("questionaire"):

        Gender = st.selectbox('Gender', unique_values['CODE_GENDER'])
        Own_car = st.selectbox('Own_car', unique_values['FLAG_OWN_CAR'])
        Property = st.selectbox('Property', unique_values['FLAG_OWN_REALTY'])
        Income_type = st.selectbox('Income_type', unique_values['NAME_INCOME_TYPE'])
        Marital_status = st.selectbox('Marital_status', unique_values['NAME_FAMILY_STATUS'])
        Housing_type = st.selectbox('Housing_type', unique_values['NAME_HOUSING_TYPE'])
        Education = st.selectbox('Education', unique_values['NAME_EDUCATION_TYPE'])

        Income = st.slider('Income', min_value=27000, max_value=1575000)
        Children = st.slider('Children', min_value=0, max_value=19)
        Day_Employed = st.slider('Day_Employed', min_value=0, max_value=3)
        Flag_Mobile = st.slider('Flag_Mobile', min_value=0, max_value=1)
        Flag_work_phone = st.slider('Flag_work_phone', min_value=0, max_value=1)
        Flag_Phone = st.slider('Flag_Phone', min_value=0, max_value=1)
        Flag_Email = st.slider('Flag_Email', min_value=0, max_value=1)
        Family_mem = st.slider('Family_mem', min_value=1, max_value=20)

        clicked = st.form_submit_button("Result")
        if clicked:
            result = model.predict(pd.DataFrame({
                                                "CODE_GENDER": [Gender],
                                                "FLAG_OWN_CAR": [Own_car],
                                                "FLAG_OWN_REALTY": [Property],
                                                "CNT_CHILDREN": [Children],
                                                "AMT_INCOME_TOTAL": [Income],
                                                "NAME_INCOME_TYPE": [Income_type],
                                                "NAME_EDUCATION_TYPE": [EDU_DICT[Education]],
                                                "NAME_FAMILY_STATUS": [Marital_status],
                                                "NAME_HOUSING_TYPE": [Housing_type],
                                                "DAYS_EMPLOYED": [Day_Employed],
                                                "FLAG_MOBIL": [Flag_Mobile],
                                                "FLAG_WORK_PHONE": [Flag_work_phone],
                                                "FLAG_PHONE": [Flag_Phone],
                                                "FLAG_EMAIL": [Flag_Email],
                                                "CNT_FAM_MEMBERS": [Family_mem]}))

            result = 'Pass' if result[0] == 1 else 'Did not Pass'

            st.success('Credit Card approval prediction results is {}'.format(result))

if __name__ == '__main__':
    main()