ViWoBra / app.py
Truong-Phuc Nguyen
Upload 9 files
a3a53e1 verified
raw
history blame
14.1 kB
import pickle
import numpy as np
import streamlit as st
from tensorflow.keras.models import load_model
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)
clf_21 = load_model(clf_full_path)
return scaler_6, scaler_8, scaler_21, clf_6, clf_8, clf_21
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/ANNs_8base.h5', clf_full_path='./Models/21/ANNs_full.h5')
st.title('Demo System for Vietnamese Woman Bra Size Classifier')
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='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='Your vtn: ', value=82.00, min_value=0.00, step=0.01)
vn = container_col_2.number_input(label='Your vn:', value=82.40, min_value=0.00, step=0.01)
vcn = container_col_3.number_input(label='Your vcn:', value=73.10, min_value=0.00, step=0.01)
cl = container_col_1.number_input(label='Your cl:', value=9.30, min_value=0.00, step=0.01)
ttp = container_col_2.number_input(label='Your ttp:', value=325.6, min_value=0.00, step=0.01)
ttt = container_col_3.number_input(label='Your ttt:', value=325.6, min_value=0.00, step=0.01)
elif sample_options_6 == 'Sample 2 (Medium)':
vtn = container_col_1.number_input(label='Your vtn: ', value=77.20, min_value=0.00, step=0.01)
vn = container_col_2.number_input(label='Your vn:', value=78.60, min_value=0.00, step=0.01)
vcn = container_col_3.number_input(label='Your vcn:', value=66.50, min_value=0.00, step=0.01)
cl = container_col_1.number_input(label='Your cl:', value=12.10, min_value=0.00, step=0.01)
ttp = container_col_2.number_input(label='Your ttp:', value=388.80, min_value=0.00, step=0.01)
ttt = container_col_3.number_input(label='Your ttt:', value=324.60, min_value=0.00, step=0.01)
else:
vtn = container_col_1.number_input(label='Your vtn: ', value=86.50, min_value=0.00, step=0.01)
vn = container_col_2.number_input(label='Your vn:', value=88.00, min_value=0.00, step=0.01)
vcn = container_col_3.number_input(label='Your vcn:', value=74.00, min_value=0.00, step=0.01)
cl = container_col_1.number_input(label='Your cl:', value=14.00, min_value=0.00, step=0.01)
ttp = container_col_2.number_input(label='Your ttp:', value=451.30, min_value=0.00, step=0.01)
ttt = container_col_3.number_input(label='Your ttt:', value=471.60, min_value=0.00, step=0.01)
elif num_of_features == '8 measurements':
sample_options_8 = header_col_2.selectbox(label='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='Your ttp:', value=325.10, min_value=0.00, step=0.01)
cl = container_col_2.number_input(label='Your cl:', value=8.90, min_value=0.00, step=0.01)
cnnp = container_col_3.number_input(label='Your cnnp:', value=12.30, min_value=0.00, step=0.01)
vn = container_col_4.number_input(label='Your vn:', value=83.20, min_value=0.00, step=0.01)
vtn = container_col_1.number_input(label='Your vtn: ', value=80.10, min_value=0.00, step=0.01)
ccnt = container_col_2.number_input(label='Your ccnt:', value=11.10, min_value=0.00, step=0.01)
cntp = container_col_3.number_input(label='Your cntp:', value=8.70, min_value=0.00, step=0.01)
vcn = container_col_4.number_input(label='Your vcn:', value=74.30, min_value=0.00, step=0.01)
elif sample_options_8 == 'Sample 2 (Medium)':
ttp = container_col_1.number_input(label='Your ttp:', value=385.80, min_value=0.00, step=0.01)
cl = container_col_2.number_input(label='Your cl:', value=13.60, min_value=0.00, step=0.01)
cnnp = container_col_3.number_input(label='Your cnnp:', value=8.80, min_value=0.00, step=0.01)
vn = container_col_4.number_input(label='Your vn:', value=83.20, min_value=0.00, step=0.01)
vtn = container_col_1.number_input(label='Your vtn: ', value=82.50, min_value=0.00, step=0.01)
ccnt = container_col_2.number_input(label='Your ccnt:', value=9.30, min_value=0.00, step=0.01)
cntp = container_col_3.number_input(label='Your cntp:', value=9.10, min_value=0.00, step=0.01)
vcn = container_col_4.number_input(label='Your vcn:', value=69.60, min_value=0.00, step=0.01)
else:
ttp = container_col_1.number_input(label='Your ttp:', value=453.30, min_value=0.00, step=0.01)
cl = container_col_2.number_input(label='Your cl:', value=13.00, min_value=0.00, step=0.01)
cnnp = container_col_3.number_input(label='Your cnnp:', value=12.50, min_value=0.00, step=0.01)
vn = container_col_4.number_input(label='Your vn:', value=85.30, min_value=0.00, step=0.01)
vtn = container_col_1.number_input(label='Your vtn: ', value=78.50, min_value=0.00, step=0.01)
ccnt = container_col_2.number_input(label='Your ccnt:', value=12.40, min_value=0.00, step=0.01)
cntp = container_col_3.number_input(label='Your cntp:', value=10.00, min_value=0.00, step=0.01)
vcn = container_col_4.number_input(label='Your vcn:', value=72.30, min_value=0.00, step=0.01)
else:
sample_options_21 = header_col_2.selectbox(label='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='Your h:', value=158.50, min_value=0.00, step=0.01)
w = container_col_2.number_input(label='Your w:', value=44.00, min_value=0.00, step=0.01)
bmi = container_col_3.number_input(label='Your bmi:', value=17.50, min_value=0.00, step=0.01)
vtn = container_col_4.number_input(label='Your vtn: ', value=75.40, min_value=0.00, step=0.01)
vn = container_col_5.number_input(label='Your vn:', value=81.10, min_value=0.00, step=0.01)
vcn = container_col_1.number_input(label='Your vcn:', value=74.80, min_value=0.00, step=0.01)
cn = container_col_2.number_input(label='Your cn:', value=14.50, min_value=0.00, step=0.01)
cnnp = container_col_3.number_input(label='Your cnnp:', value=13.80, min_value=0.00, step=0.01)
cnnt = container_col_4.number_input(label='Your cnnt:', value=14.40, min_value=0.00, step=0.01)
cntp = container_col_5.number_input(label='Your cntp:', value=8.60, min_value=0.00, step=0.01)
cntt = container_col_1.number_input(label='Your cntt:', value=8.40, min_value=0.00, step=0.01)
ccnp = container_col_2.number_input(label='Your ccnp:', value=21.50, min_value=0.00, step=0.01)
ccnt = container_col_3.number_input(label='Your ccnt:', value=21.20, min_value=0.00, step=0.01)
snt = container_col_4.number_input(label='Your snt:', value=8.90, min_value=0.00, step=0.01)
sndp = container_col_5.number_input(label='Your sndp:', value=6.50, min_value=0.00, step=0.01)
sndt = container_col_1.number_input(label='Your sndt:', value=6.50, min_value=0.00, step=0.01)
xup = container_col_2.number_input(label='Your xup:', value=21.80, min_value=0.00, step=0.01)
xut = container_col_3.number_input(label='Your xut:', value=21.10, min_value=0.00, step=0.01)
cl = container_col_4.number_input(label='Your cl:', value=6.30, min_value=0.00, step=0.01)
ttp = container_col_5.number_input(label='Your ttp:', value=325.10, min_value=0.00, step=0.01)
ttt = container_col_3.number_input(label='Your ttt:', value=335.70, min_value=0.00, step=0.01)
elif sample_options_21 == 'Sample 2 (Medium)':
h = container_col_1.number_input(label='Your h:', value=163.00, min_value=0.00, step=0.01)
w = container_col_2.number_input(label='Your w:', value=43.00, min_value=0.00, step=0.01)
bmi = container_col_3.number_input(label='Your bmi:', value=16.20, min_value=0.00, step=0.01)
vtn = container_col_4.number_input(label='Your vtn: ', value=76.00, min_value=0.00, step=0.01)
vn = container_col_5.number_input(label='Your vn:', value=79.00, min_value=0.00, step=0.01)
vcn = container_col_1.number_input(label='Your vcn:', value=64.00, min_value=0.00, step=0.01)
cn = container_col_2.number_input(label='Your cn:', value=16.50, min_value=0.00, step=0.01)
cnnp = container_col_3.number_input(label='Your cnnp:', value=13.10, min_value=0.00, step=0.01)
cnnt = container_col_4.number_input(label='Your cnnt:', value=12.60, min_value=0.00, step=0.01)
cntp = container_col_5.number_input(label='Your cntp:', value=9.20, min_value=0.00, step=0.01)
cntt = container_col_1.number_input(label='Your cntt:', value=9.10, min_value=0.00, step=0.01)
ccnp = container_col_2.number_input(label='Your ccnp:', value=19.80, min_value=0.00, step=0.01)
ccnt = container_col_3.number_input(label='Your ccnt:', value=18.20, min_value=0.00, step=0.01)
snt = container_col_4.number_input(label='Your snt:', value=8.40, min_value=0.00, step=0.01)
sndp = container_col_5.number_input(label='Your sndp:', value=3.50, min_value=0.00, step=0.01)
sndt = container_col_1.number_input(label='Your sndt:', value=3.70, min_value=0.00, step=0.01)
xup = container_col_2.number_input(label='Your xup:', value=21.00, min_value=0.00, step=0.01)
xut = container_col_3.number_input(label='Your xut:', value=20.50, min_value=0.00, step=0.01)
cl = container_col_4.number_input(label='Your cl:', value=15.00, min_value=0.00, step=0.01)
ttp = container_col_5.number_input(label='Your ttp:', value=521.60, min_value=0.00, step=0.01)
ttt = container_col_3.number_input(label='Your ttt:', value=513.50, min_value=0.00, step=0.01)
else:
h = container_col_1.number_input(label='Your h:', value=152.00, min_value=0.00, step=0.01)
w = container_col_2.number_input(label='Your w:', value=46.00, min_value=0.00, step=0.01)
bmi = container_col_3.number_input(label='Your bmi:', value=19.90, min_value=0.00, step=0.01)
vtn = container_col_4.number_input(label='Your vtn: ', value=77.50, min_value=0.00, step=0.01)
vn = container_col_5.number_input(label='Your vn:', value=85.50, min_value=0.00, step=0.01)
vcn = container_col_1.number_input(label='Your vcn:', value=70.40, min_value=0.00, step=0.01)
cn = container_col_2.number_input(label='Your cn:', value=18.90, min_value=0.00, step=0.01)
cnnp = container_col_3.number_input(label='Your cnnp:', value=13.50, min_value=0.00, step=0.01)
cnnt = container_col_4.number_input(label='Your cnnt:', value=12.50, min_value=0.00, step=0.01)
cntp = container_col_5.number_input(label='Your cntp:', value=10.30, min_value=0.00, step=0.01)
cntt = container_col_1.number_input(label='Your cntt:', value=10.50, min_value=0.00, step=0.01)
ccnp = container_col_2.number_input(label='Your ccnp:', value=20.40, min_value=0.00, step=0.01)
ccnt = container_col_3.number_input(label='Your ccnt:', value=20.10, min_value=0.00, step=0.01)
snt = container_col_4.number_input(label='Your snt:', value=8.50, min_value=0.00, step=0.01)
sndp = container_col_5.number_input(label='Your sndp:', value=5.50, min_value=0.00, step=0.01)
sndt = container_col_1.number_input(label='Your sndt:', value=4.20, min_value=0.00, step=0.01)
xup = container_col_2.number_input(label='Your xup:', value=19.50, min_value=0.00, step=0.01)
xut = container_col_3.number_input(label='Your xut:', value=20.50, min_value=0.00, step=0.01)
cl = container_col_4.number_input(label='Your cl:', value=15.10, min_value=0.00, step=0.01)
ttp = container_col_5.number_input(label='Your ttp:', value=625.80, min_value=0.00, step=0.01)
ttt = container_col_3.number_input(label='Your ttt:', 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 = [[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 {y_6} size!')
elif num_of_features == '8 measurements':
X_8 = [[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 {np.argmax(y_8, axis=1)} size!')
else:
X_21 = [[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 {np.argmax(y_21, axis=1)} size!')