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()