Spaces:
Runtime error
Runtime error
File size: 3,000 Bytes
e80b3a7 72abf1a e80b3a7 72abf1a e80b3a7 |
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 |
# Import library yang dibutuhkan
import joblib
import pandas as pd
import streamlit as st
from huggingface_hub import hf_hub_download
# Nama repo
REPO_ID = "chanyaphas/creditc"
# Personal Access Token untuk koneksi pada model
access_token = st.secrets["HF_TOKEN"]
# Inisialisasi model yang lebih dari satu
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")
)
# Dictionary pada model
EDU_DICT = {'Lower secondary': 1,
'Secondary / Secondary special' :2 ,
'Academic degree': 3,
'Incomplete higher': 4,
'Higher education': 5
}
# Beri judul pada apps
st.title("Credit Card Approval Prediction")
# Buat form input user, hasil input akan di prediksi
with st.form("questionare"):
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=157500)
Children = st.number_input('Children', min_value=0, max_value=19)
Day_Employed = st.number_input('Day_Employed', min_value=0, max_value=3)
Flag_Mobile = st.number_input('Flag_Mobile', min_value=0, max_value=1)
Flag_work_phone = st.number_input('Flag_work_phone', min_value=0, max_value=1)
Flag_Phone = st.number_input('Flag_Phone', min_value=0, max_value=1)
Flag_Email = st.number_input('Flag_Email', min_value=0, max_value=1)
Family_mem = st.number_input('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(f'Credit card approval prediction result is {result}') |