Spaces:
Runtime error
Runtime error
Update src/streamlit_app.py
Browse files12345678910111213141516171819202122232425262728293031323334353637383940import altair as altimport numpy as npimport pandas as pdimport streamlit as st"""# Welcome to Streamlit!Edit `/streamlit_app.py` to customize this app to your heart's desire :heart:.If you have any questions, checkout our [documentation](https://docs.streamlit.io) and [communityforums](https://discuss.streamlit.io).In the meantime, below is an example of what you can do with just a few lines of code:"""num_points = st.slider("Number of points in spiral", 1, 10000, 1100)num_turns = st.slider("Number of turns in spiral", 1, 300, 31)indices = np.linspace(0, 1, num_points)theta = 2 * np.pi * num_turns * indicesradius = indicesx = radius * np.cos(theta)y = radius * np.sin(theta)df = pd.DataFrame({"x": x,"y": y,"idx": indices,"rand": np.random.randn(num_points),})st.altair_chart(alt.Chart(df, height=700, width=700).mark_point(filled=True).encode(x=alt.X("x", axis=None),y=alt.Y("y", axis=None),color=alt.Color("idx", legend=None, scale=alt.Scale()),size=alt.Size("rand", legend=None, scale=alt.Scale(range=[1, 150])),))123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106import streamlit as stimport pandas as pd# import joblibimport pickle# scaler = joblib.load('scaler.pkl')with open('scaler.pkl', 'rb') as file:scaler = pickle.load(file)with open('credit_default.pkl', 'rb') as file:model = pickle.load(file)st.title('Prediksi Default Loan Customer')Name = st.text_input('Name', placeholder='Input Your Name..')# Streamlit input widgetsGENDER = st.radio("Jenis Kelamin", ["Laki-laki", "Perempuan"])AGE = st.slider('Umur (Tahun)', 0, 130, 20)Type_Occupation = st.selectbox("Jenis Pekerjaan",("High skill tech staff", 'Core staff', 'Sales staff', 'Laborers','Cooking staff', 'Managers', 'Accountants', 'Cleaning staff', 'Drivers','Private service staff', 'Low-skill Laborers', 'IT staff','Waiters/barmen staff', 'Medicine staff', 'Security staff', 'HR staff','Secretaries', 'Realty agents'),placeholder="Pilih Pekerjaanmu...",)Marital_status = st.selectbox("Status Pernikahan",('Married', 'Single / not married', 'Civil marriage', 'Separated', 'Widow'),placeholder="Pilih Jenis Pendapatanmu...",)Family_Members = st.slider('Jumlah Anggota Keluarga', 0, 20, 2)Type_Income = st.selectbox("Jenis Pendapatan",('Commercial associate', 'Pensioner', 'Working', 'State servant'),placeholder="Pilih Jenis Pendapatanmu...",)YEAR_EMPLOYED = st.slider('Lama Bekerja (Tahun)', 0, 60, 5)EDUCATION = st.selectbox("Pendidikan",('Higher education', 'Secondary / secondary special', 'Lower secondary','Incomplete higher', 'Academic degree'),placeholder="Pilih Pendidikan Terakhirmu...",)Housing_type = st.selectbox("Tipe Rumah",('House / apartment', 'With parents', 'Rented apartment','Municipal apartment', 'Co-op apartment', 'Office apartment'),placeholder="Pilih Tipe Rumahmu...",)# Mapping dictionariesHousing_type_map = {'House / apartment': 0, 'Rented apartment': 1, 'With parents': 2,'Municipal apartment': 3, 'Co-op apartment': 4, 'Office apartment': 5}EDUCATION_map = {'Higher education': 0, 'Secondary / secondary special': 1, 'Lower secondary': 2,'Incomplete higher': 3, 'Academic degree': 4}Type_Occupation_map = {'Private service staff': 0, 'Laborers': 1, 'Managers': 2, 'Medicine staff': 3,'Cooking staff': 4, 'Sales staff': 5, 'Accountants': 6, 'High skill tech staff': 7,'Cleaning staff': 8, 'Drivers': 9, 'Low-skill Laborers': 10, 'IT staff': 11,'Waiters/barmen staff': 12, 'Core staff': 13, 'Security staff': 14, 'HR staff': 15,'Secretaries': 16, 'Realty agents': 17}GENDER_map = {'Laki-laki': 1, 'Perempuan': 0}Marital_status_map = {'Married': 0, 'Single / not married': 1, 'Civil marriage': 2, 'Separated': 3, 'Widow': 4}Type_Income_map = {'Commercial associate': 0, 'Pensioner': 1, 'Working': 2, 'State servant': 3}df = pd.DataFrame()if st.button('Prediksi Loan Customer'):Name = NameHousing_type_value = Housing_type_map[Housing_type]EDUCATION_value = EDUCATION_map[EDUCATION]Type_Occupation_value = Type_Occupation_map[Type_Occupation]GENDER_value = GENDER_map[GENDER]Marital_status_value = Marital_status_map[Marital_status]Type_Income_value = Type_Income_map[Type_Income]card_credit = [GENDER_value, Type_Occupation_value, Type_Income_value, Marital_status_value, EDUCATION_value, AGE, Housing_type_value, YEAR_EMPLOYED]df = pd.DataFrame([card_credit], columns=['GENDER', 'Type_Occupation', 'Type_Income', 'Marital_status', 'EDUCATION', 'AGE', 'Housing_type', 'YEAR_EMPLOYED'])if not df.empty:c_scaler = scaler.transform(df.values.reshape(1, -1))loan_prediction = model.predict(c_scaler)if loan_prediction[0] == 1:loan_diagnose = f"Pengajuan Kartu Kredit Atas Nama {Name} Ditolak"else:loan_diagnose = f"Pengajuan Kartu Kredit Atas Nama {Name} Diterima"if loan_prediction[0] == 1:st.error(loan_diagnose, icon="❌")else:st.success(loan_diagnose, icon="✅")else:st.error("Harap isi semua form terlebih dahulu.")
src/streamlit_app.py+104-38