Spaces:
Runtime error
Runtime error
# 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}') |