import pickle import numpy as np import streamlit as st from tensorflow.keras.models import load_model import warnings warnings.filterwarnings("ignore", category=UserWarning) st.set_page_config(layout='wide', initial_sidebar_state="collapsed") def load_essential_models(scaler_6_path, scaler_8_path, scaler_full_path, clf_6_path, clf_8_path, clf_full_path): scaler_6 = pickle.load(open(file=scaler_6_path, mode='rb')) scaler_8 = pickle.load(open(file=scaler_8_path, mode='rb')) scaler_21 = pickle.load(open(file=scaler_full_path, mode='rb')) clf_6 = pickle.load(open(file=clf_6_path, mode='rb')) clf_8 = load_model(clf_8_path, compile=False) clf_21 = load_model(clf_full_path, compile=False) return scaler_6, scaler_8, scaler_21, clf_6, clf_8, clf_21 def convert_prediction(prediction): if prediction == [0]: return 'S' elif prediction == [1]: return 'M' else: return 'L' st.markdown("

Vietnamese Woman Bra Size Classifier

", unsafe_allow_html=True) scaler_6, scaler_8, scaler_21, clf_6, clf_8, clf_21 = load_essential_models(scaler_6_path='./Models/6/scaler.pkl', scaler_8_path='./Models/8/scaler.pkl', scaler_full_path='./Models/21/scaler.pkl', clf_6_path='./Models/6/svc_fs_tune.pkl', clf_8_path='./Models/8/ANN_8.h5', clf_full_path='./Models/21/ANNs_full.h5') header_col_1, header_col_2 = st.columns([3, 2]) num_of_features = header_col_1.selectbox(label='Please select the number of measurements you have:', options=['6 measurements', '8 measurements', '21 measurements']) # h, w, bmi, vtn, vn, vcn, cn, cnnp, cnnt, cntp, cntt, ccnp, ccnt, snt, sndp, sndt, xup, xut, cl, ttp, ttt = [0.0]*21 if num_of_features == '6 measurements': sample_options_6 = header_col_2.selectbox(label='Measurement sample options:', options=['Sample 1 (Small)', 'Sample 2 (Medium)', 'Sample 3 (Large)']) container_col_1, container_col_2, container_col_3 = st.columns([1, 1, 1]) if sample_options_6 == 'Sample 1 (Small)': vtn = container_col_1.number_input(label='Upper bust circumference (cm):', value=82.00, min_value=0.00, step=0.01) vn = container_col_2.number_input(label='Bust circumference (cm):', value=82.40, min_value=0.00, step=0.01) vcn = container_col_3.number_input(label='Chest circumference (cm):', value=73.10, min_value=0.00, step=0.01) cl = container_col_1.number_input(label='Size difference (cm):', value=9.30, min_value=0.00, step=0.01) ttp = container_col_2.number_input(label='Volume of right breast (cm3):', value=325.6, min_value=0.00, step=0.01) ttt = container_col_3.number_input(label='Volume of left breast (cm3):', value=325.6, min_value=0.00, step=0.01) elif sample_options_6 == 'Sample 2 (Medium)': vtn = container_col_1.number_input(label='Upper bust circumference (cm):', value=77.20, min_value=0.00, step=0.01) vn = container_col_2.number_input(label='Bust circumference (cm):', value=78.60, min_value=0.00, step=0.01) vcn = container_col_3.number_input(label='Chest circumference (cm):', value=66.50, min_value=0.00, step=0.01) cl = container_col_1.number_input(label='Size difference (cm):', value=12.10, min_value=0.00, step=0.01) ttp = container_col_2.number_input(label='Volume of right breast (cm3):', value=388.80, min_value=0.00, step=0.01) ttt = container_col_3.number_input(label='Volume of left breast (cm3):', value=324.60, min_value=0.00, step=0.01) else: vtn = container_col_1.number_input(label='Upper bust circumference (cm):', value=86.50, min_value=0.00, step=0.01) vn = container_col_2.number_input(label='Bust circumference (cm):', value=88.00, min_value=0.00, step=0.01) vcn = container_col_3.number_input(label='Chest circumference (cm):', value=74.00, min_value=0.00, step=0.01) cl = container_col_1.number_input(label='Size difference (cm):', value=14.00, min_value=0.00, step=0.01) ttp = container_col_2.number_input(label='Volume of right breast (cm3):', value=451.30, min_value=0.00, step=0.01) ttt = container_col_3.number_input(label='Volume of left breast (cm3):', value=471.60, min_value=0.00, step=0.01) elif num_of_features == '8 measurements': sample_options_8 = header_col_2.selectbox(label='Measurement sample options:', options=['Sample 1 (Small)', 'Sample 2 (Medium)', 'Sample 3 (Large)']) container_col_1, container_col_2, container_col_3, container_col_4 = st.columns([1, 1, 1, 1]) if sample_options_8 == 'Sample 1 (Small)': ttp = container_col_1.number_input(label='Volume of right breast (cm3):', value=287.50, min_value=0.00, step=0.01) cl = container_col_2.number_input(label='Size difference (cm):', value=7.00, min_value=0.00, step=0.01) cnnp = container_col_3.number_input(label='Outer right breast curve (cm):', value=8.50, min_value=0.00, step=0.01) vn = container_col_4.number_input(label='Bust circumference (cm):', value=74.50, min_value=0.00, step=0.01) vtn = container_col_1.number_input(label='Upper bust circumference (cm):', value=74.00, min_value=0.00, step=0.01) cnnt = container_col_2.number_input(label='Outer left breast curve (cm):', value=8.90, min_value=0.00, step=0.01) cntp = container_col_3.number_input(label='Inner right breast curve (cm):', value=8.50, min_value=0.00, step=0.01) vcn = container_col_4.number_input(label='Chest circumference (cm):', value=67.50, min_value=0.00, step=0.01) elif sample_options_8 == 'Sample 2 (Medium)': ttp = container_col_1.number_input(label='Volume of right breast (cm3):', value=489.60, min_value=0.00, step=0.01) cl = container_col_2.number_input(label='Size difference (cm):', value=13.00, min_value=0.00, step=0.01) cnnp = container_col_3.number_input(label='Outer right breast curve (cm):', value=12.40, min_value=0.00, step=0.01) vn = container_col_4.number_input(label='Bust circumference (cm):', value=78.30, min_value=0.00, step=0.01) vtn = container_col_1.number_input(label='Upper bust circumference (cm):', value=77.20, min_value=0.00, step=0.01) cnnt = container_col_2.number_input(label='Outer left breast curve (cm):', value=11.60, min_value=0.00, step=0.01) cntp = container_col_3.number_input(label='Inner right breast curve (cm):', value=8.70, min_value=0.00, step=0.01) vcn = container_col_4.number_input(label='Chest circumference (cm):', value=65.30, min_value=0.00, step=0.01) else: ttp = container_col_1.number_input(label='Volume of right breast (cm3):', value=568.2, min_value=0.00, step=0.01) cl = container_col_2.number_input(label='Size difference (cm):', value=13.7, min_value=0.00, step=0.01) cnnp = container_col_3.number_input(label='Outer right breast curve (cm):', value=14.0, min_value=0.00, step=0.01) vn = container_col_4.number_input(label='Bust circumference (cm):', value=88.7, min_value=0.00, step=0.01) vtn = container_col_1.number_input(label='Upper bust circumference (cm):', value=86.5, min_value=0.00, step=0.01) cnnt = container_col_2.number_input(label='Outer left breast curve (cm):', value=12.5, min_value=0.00, step=0.01) cntp = container_col_3.number_input(label='Inner right breast curve (cm):', value=10.7, min_value=0.00, step=0.01) vcn = container_col_4.number_input(label='Chest circumference (cm):', value=75.0, min_value=0.00, step=0.01) else: sample_options_21 = header_col_2.selectbox(label='Measurement sample options:', options=['Sample 1 (Small)', 'Sample 2 (Medium)', 'Sample 3 (Large)']) container_col_1, container_col_2, container_col_3, container_col_4, container_col_5 = st.columns([1, 1, 1, 1, 1]) if sample_options_21 == 'Sample 1 (Small)': h = container_col_1.number_input(label='Height (cm):', value=158.50, min_value=0.00, step=0.01) w = container_col_2.number_input(label='Weight (kg):', value=44.00, min_value=0.00, step=0.01) bmi = container_col_3.number_input(label='BMI (kg/h^2):', value=17.50, min_value=0.00, step=0.01) vtn = container_col_4.number_input(label='Upper bust circumference (cm): ', value=75.40, min_value=0.00, step=0.01) vn = container_col_5.number_input(label='Bust circumference (cm):', value=81.10, min_value=0.00, step=0.01) vcn = container_col_1.number_input(label='Chest circumference (cm):', value=74.80, min_value=0.00, step=0.01) cn = container_col_2.number_input(label='Distance between nipple points (cm):', value=14.50, min_value=0.00, step=0.01) cnnp = container_col_3.number_input(label='Outer right breast curve (cm):', value=13.80, min_value=0.00, step=0.01) cnnt = container_col_4.number_input(label='Outer left breast curve (cm):', value=14.40, min_value=0.00, step=0.01) cntp = container_col_5.number_input(label='Inner right breast curve (cm):', value=8.60, min_value=0.00, step=0.01) cntt = container_col_1.number_input(label='Inner left breast curve (cm):', value=8.40, min_value=0.00, step=0.01) ccnp = container_col_2.number_input(label='Right breast curve (cm):', value=21.50, min_value=0.00, step=0.01) ccnt = container_col_3.number_input(label='Left breast curve (cm):', value=21.20, min_value=0.00, step=0.01) snt = container_col_4.number_input(label='Upper breast projection (cm):', value=8.90, min_value=0.00, step=0.01) sndp = container_col_5.number_input(label='Lower right breast projection (cm):', value=6.50, min_value=0.00, step=0.01) sndt = container_col_1.number_input(label='Lower left breast projection (cm):', value=6.50, min_value=0.00, step=0.01) xup = container_col_2.number_input(label='Distance from sternum to right nipple point (cm):', value=21.80, min_value=0.00, step=0.01) xut = container_col_3.number_input(label='Distance from sternum to left nipple point (cm):', value=21.10, min_value=0.00, step=0.01) cl = container_col_4.number_input(label='Size difference (cm):', value=6.30, min_value=0.00, step=0.01) ttp = container_col_5.number_input(label='Volume of right breast (cm3):', value=325.10, min_value=0.00, step=0.01) ttt = container_col_3.number_input(label='Volume of left breast (cm3):', value=335.70, min_value=0.00, step=0.01) elif sample_options_21 == 'Sample 2 (Medium)': h = container_col_1.number_input(label='Height (cm):', value=163.00, min_value=0.00, step=0.01) w = container_col_2.number_input(label='Weight (kg):', value=43.00, min_value=0.00, step=0.01) bmi = container_col_3.number_input(label='BMI (kg/h^2):', value=16.20, min_value=0.00, step=0.01) vtn = container_col_4.number_input(label='Upper bust circumference (cm): ', value=76.00, min_value=0.00, step=0.01) vn = container_col_5.number_input(label='Bust circumference (cm):', value=79.00, min_value=0.00, step=0.01) vcn = container_col_1.number_input(label='Chest circumference (cm):', value=64.00, min_value=0.00, step=0.01) cn = container_col_2.number_input(label='Distance between nipple points (cm):', value=16.50, min_value=0.00, step=0.01) cnnp = container_col_3.number_input(label='Outer right breast curve (cm):', value=13.10, min_value=0.00, step=0.01) cnnt = container_col_4.number_input(label='Outer left breast curve (cm):', value=12.60, min_value=0.00, step=0.01) cntp = container_col_5.number_input(label='Inner right breast curve (cm):', value=9.20, min_value=0.00, step=0.01) cntt = container_col_1.number_input(label='Inner left breast curve (cm):', value=9.10, min_value=0.00, step=0.01) ccnp = container_col_2.number_input(label='Right breast curve (cm):', value=19.80, min_value=0.00, step=0.01) ccnt = container_col_3.number_input(label='Left breast curve (cm):', value=18.20, min_value=0.00, step=0.01) snt = container_col_4.number_input(label='Upper breast projection (cm):', value=8.40, min_value=0.00, step=0.01) sndp = container_col_5.number_input(label='Lower right breast projection (cm):', value=3.50, min_value=0.00, step=0.01) sndt = container_col_1.number_input(label='Lower left breast projection (cm):', value=3.70, min_value=0.00, step=0.01) xup = container_col_2.number_input(label='Distance from sternum to right nipple point (cm):', value=21.00, min_value=0.00, step=0.01) xut = container_col_3.number_input(label='Distance from sternum to left nipple point (cm):', value=20.50, min_value=0.00, step=0.01) cl = container_col_4.number_input(label='Size difference (cm):', value=15.00, min_value=0.00, step=0.01) ttp = container_col_5.number_input(label='Volume of right breast (cm3):', value=521.60, min_value=0.00, step=0.01) ttt = container_col_3.number_input(label='Volume of left breast (cm3):', value=513.50, min_value=0.00, step=0.01) else: h = container_col_1.number_input(label='Height (cm):', value=152.00, min_value=0.00, step=0.01) w = container_col_2.number_input(label='Weight (kg):', value=46.00, min_value=0.00, step=0.01) bmi = container_col_3.number_input(label='BMI (kg/h^2):', value=19.90, min_value=0.00, step=0.01) vtn = container_col_4.number_input(label='Upper bust circumference (cm): ', value=77.50, min_value=0.00, step=0.01) vn = container_col_5.number_input(label='Bust circumference (cm):', value=85.50, min_value=0.00, step=0.01) vcn = container_col_1.number_input(label='Chest circumference (cm):', value=70.40, min_value=0.00, step=0.01) cn = container_col_2.number_input(label='Distance between nipple points (cm):', value=18.90, min_value=0.00, step=0.01) cnnp = container_col_3.number_input(label='Outer right breast curve (cm):', value=13.50, min_value=0.00, step=0.01) cnnt = container_col_4.number_input(label='Outer left breast curve (cm):', value=12.50, min_value=0.00, step=0.01) cntp = container_col_5.number_input(label='Inner right breast curve (cm):', value=10.30, min_value=0.00, step=0.01) cntt = container_col_1.number_input(label='Inner left breast curve (cm):', value=10.50, min_value=0.00, step=0.01) ccnp = container_col_2.number_input(label='Right breast curve (cm):', value=20.40, min_value=0.00, step=0.01) ccnt = container_col_3.number_input(label='Left breast curve (cm):', value=20.10, min_value=0.00, step=0.01) snt = container_col_4.number_input(label='Upper breast projection (cm):', value=8.50, min_value=0.00, step=0.01) sndp = container_col_5.number_input(label='Lower right breast projection (cm):', value=5.50, min_value=0.00, step=0.01) sndt = container_col_1.number_input(label='Lower left breast projection (cm):', value=4.20, min_value=0.00, step=0.01) xup = container_col_2.number_input(label='Distance from sternum to right nipple point (cm):', value=19.50, min_value=0.00, step=0.01) xut = container_col_3.number_input(label='Distance from sternum to left nipple point (cm):', value=20.50, min_value=0.00, step=0.01) cl = container_col_4.number_input(label='Size difference (cm):', value=15.10, min_value=0.00, step=0.01) ttp = container_col_5.number_input(label='Volume of right breast (cm3):', value=625.80, min_value=0.00, step=0.01) ttt = container_col_3.number_input(label='Volume of left breast (cm3):', value=585.40, min_value=0.00, step=0.01) col_1, col_2, col_3, col_4, col_5 = st.columns([1, 1, 1, 1, 1]) with col_3: predict = st.button(label='Predict', use_container_width=True) if predict: if num_of_features == '6 measurements': X_6 = np.array([[vtn, vn, vcn, cl, ttp, ttt]]) X_6 = scaler_6.transform(X_6) y_6 = clf_6.predict(X_6) st.success(f'We recommend you choosing **{convert_prediction(y_6)}** size!') elif num_of_features == '8 measurements': X_8 = np.array([[ttp, cl, cnnp, vn, vtn, cnnt, cntp, vcn]]) X_8 = scaler_8.transform(X_8) y_8 = clf_8.predict(X_8) st.success(f'We recommend you choosing **{convert_prediction(np.argmax(y_8, axis=1))}** size!') else: X_21 = np.array([[h, w, bmi, vtn, vn, vcn, cn, cnnp, cnnt, cntp, cntt, ccnp, ccnt, snt, sndp, sndt, xup, xut, cl, ttp, ttt]]) X_21 = scaler_21.transform(X_21) y_21 = clf_21.predict(X_21) st.success(f'We recommend you choosing **{convert_prediction(np.argmax(y_21, axis=1))}** size!')