Truong-Phuc Nguyen commited on
Commit
d3bd4e5
1 Parent(s): 6ae349b
Files changed (1) hide show
  1. app.py +42 -34
app.py CHANGED
@@ -8,18 +8,26 @@ def load_essential_models(scaler_6_path, scaler_8_path, scaler_full_path, clf_6_
8
  scaler_8 = pickle.load(open(file=scaler_8_path, mode='rb'))
9
  scaler_21 = pickle.load(open(file=scaler_full_path, mode='rb'))
10
  clf_6 = pickle.load(open(file=clf_6_path, mode='rb'))
11
- clf_8 = load_model(clf_8_path)
12
- clf_21 = load_model(clf_full_path)
13
  return scaler_6, scaler_8, scaler_21, clf_6, clf_8, clf_21
14
 
15
- 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')
 
 
 
 
 
 
 
 
16
 
17
  st.title('Demo System for Vietnamese Woman Bra Size Classifier')
18
 
19
  header_col_1, header_col_2 = st.columns([3, 2])
20
  num_of_features = header_col_1.selectbox(label='Please select the number of measurements you have:', options=['6 measurements', '8 measurements', '21 measurements'])
21
 
22
- h, w, bmi, vtn, vn, vcn, cn, cnnp, cnnt, cntp, cntt, ccnp, ccnt, snt, sndp, sndt, xup, xut, cl, ttp, ttt = [0.0]*21
23
 
24
  if num_of_features == '6 measurements':
25
  sample_options_6 = header_col_2.selectbox(label='Sample options:', options=['Sample 1 (Small)', 'Sample 2 (Medium)', 'Sample 3 (Large)'])
@@ -50,32 +58,32 @@ elif num_of_features == '8 measurements':
50
  sample_options_8 = header_col_2.selectbox(label='Sample options:', options=['Sample 1 (Small)', 'Sample 2 (Medium)', 'Sample 3 (Large)'])
51
  container_col_1, container_col_2, container_col_3, container_col_4 = st.columns([1, 1, 1, 1])
52
  if sample_options_8 == 'Sample 1 (Small)':
53
- ttp = container_col_1.number_input(label='Your ttp:', value=325.10, min_value=0.00, step=0.01)
54
- cl = container_col_2.number_input(label='Your cl:', value=8.90, min_value=0.00, step=0.01)
55
- cnnp = container_col_3.number_input(label='Your cnnp:', value=12.30, min_value=0.00, step=0.01)
56
- vn = container_col_4.number_input(label='Your vn:', value=83.20, min_value=0.00, step=0.01)
57
- vtn = container_col_1.number_input(label='Your vtn: ', value=80.10, min_value=0.00, step=0.01)
58
- ccnt = container_col_2.number_input(label='Your ccnt:', value=11.10, min_value=0.00, step=0.01)
59
- cntp = container_col_3.number_input(label='Your cntp:', value=8.70, min_value=0.00, step=0.01)
60
- vcn = container_col_4.number_input(label='Your vcn:', value=74.30, min_value=0.00, step=0.01)
61
  elif sample_options_8 == 'Sample 2 (Medium)':
62
- ttp = container_col_1.number_input(label='Your ttp:', value=385.80, min_value=0.00, step=0.01)
63
- cl = container_col_2.number_input(label='Your cl:', value=13.60, min_value=0.00, step=0.01)
64
- cnnp = container_col_3.number_input(label='Your cnnp:', value=8.80, min_value=0.00, step=0.01)
65
- vn = container_col_4.number_input(label='Your vn:', value=83.20, min_value=0.00, step=0.01)
66
- vtn = container_col_1.number_input(label='Your vtn: ', value=82.50, min_value=0.00, step=0.01)
67
- ccnt = container_col_2.number_input(label='Your ccnt:', value=9.30, min_value=0.00, step=0.01)
68
- cntp = container_col_3.number_input(label='Your cntp:', value=9.10, min_value=0.00, step=0.01)
69
- vcn = container_col_4.number_input(label='Your vcn:', value=69.60, min_value=0.00, step=0.01)
70
- else:
71
- ttp = container_col_1.number_input(label='Your ttp:', value=453.30, min_value=0.00, step=0.01)
72
  cl = container_col_2.number_input(label='Your cl:', value=13.00, min_value=0.00, step=0.01)
73
- cnnp = container_col_3.number_input(label='Your cnnp:', value=12.50, min_value=0.00, step=0.01)
74
- vn = container_col_4.number_input(label='Your vn:', value=85.30, min_value=0.00, step=0.01)
75
- vtn = container_col_1.number_input(label='Your vtn: ', value=78.50, min_value=0.00, step=0.01)
76
- ccnt = container_col_2.number_input(label='Your ccnt:', value=12.40, min_value=0.00, step=0.01)
77
- cntp = container_col_3.number_input(label='Your cntp:', value=10.00, min_value=0.00, step=0.01)
78
- vcn = container_col_4.number_input(label='Your vcn:', value=72.30, min_value=0.00, step=0.01)
 
 
 
 
 
 
 
 
 
79
  else:
80
  sample_options_21 = header_col_2.selectbox(label='Sample options:', options=['Sample 1 (Small)', 'Sample 2 (Medium)', 'Sample 3 (Large)'])
81
  container_col_1, container_col_2, container_col_3, container_col_4, container_col_5 = st.columns([1, 1, 1, 1, 1])
@@ -153,17 +161,17 @@ with col_3:
153
 
154
  if predict:
155
  if num_of_features == '6 measurements':
156
- X_6 = [[vtn, vn, vcn, cl, ttp, ttt]]
157
  X_6 = scaler_6.transform(X_6)
158
  y_6 = clf_6.predict(X_6)
159
- st.success(f'We recommend you choosing {y_6} size!')
160
  elif num_of_features == '8 measurements':
161
- X_8 = [[ttp, cl, cnnp, vn, vtn, cnnt, cntp, vcn]]
162
  X_8 = scaler_8.transform(X_8)
163
  y_8 = clf_8.predict(X_8)
164
- st.success(f'We recommend you choosing {np.argmax(y_8, axis=1)} size!')
165
  else:
166
- X_21 = [[h, w, bmi, vtn, vn, vcn, cn, cnnp, cnnt, cntp, cntt, ccnp, ccnt, snt, sndp, sndt, xup, xut, cl, ttp, ttt]]
167
  X_21 = scaler_21.transform(X_21)
168
  y_21 = clf_21.predict(X_21)
169
- st.success(f'We recommend you choosing {np.argmax(y_21, axis=1)} size!')
 
8
  scaler_8 = pickle.load(open(file=scaler_8_path, mode='rb'))
9
  scaler_21 = pickle.load(open(file=scaler_full_path, mode='rb'))
10
  clf_6 = pickle.load(open(file=clf_6_path, mode='rb'))
11
+ clf_8 = load_model(clf_8_path, compile=False)
12
+ clf_21 = load_model(clf_full_path, compile=False)
13
  return scaler_6, scaler_8, scaler_21, clf_6, clf_8, clf_21
14
 
15
+ def convert_prediction(prediction):
16
+ if prediction == [0]:
17
+ return 'S'
18
+ elif prediction == [1]:
19
+ return 'M'
20
+ else:
21
+ return 'L'
22
+
23
+ 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')
24
 
25
  st.title('Demo System for Vietnamese Woman Bra Size Classifier')
26
 
27
  header_col_1, header_col_2 = st.columns([3, 2])
28
  num_of_features = header_col_1.selectbox(label='Please select the number of measurements you have:', options=['6 measurements', '8 measurements', '21 measurements'])
29
 
30
+ # h, w, bmi, vtn, vn, vcn, cn, cnnp, cnnt, cntp, cntt, ccnp, ccnt, snt, sndp, sndt, xup, xut, cl, ttp, ttt = [0.0]*21
31
 
32
  if num_of_features == '6 measurements':
33
  sample_options_6 = header_col_2.selectbox(label='Sample options:', options=['Sample 1 (Small)', 'Sample 2 (Medium)', 'Sample 3 (Large)'])
 
58
  sample_options_8 = header_col_2.selectbox(label='Sample options:', options=['Sample 1 (Small)', 'Sample 2 (Medium)', 'Sample 3 (Large)'])
59
  container_col_1, container_col_2, container_col_3, container_col_4 = st.columns([1, 1, 1, 1])
60
  if sample_options_8 == 'Sample 1 (Small)':
61
+ ttp = container_col_1.number_input(label='Your ttp:', value=287.50, min_value=0.00, step=0.01)
62
+ cl = container_col_2.number_input(label='Your cl:', value=7.00, min_value=0.00, step=0.01)
63
+ cnnp = container_col_3.number_input(label='Your cnnp:', value=8.50, min_value=0.00, step=0.01)
64
+ vn = container_col_4.number_input(label='Your vn:', value=74.50, min_value=0.00, step=0.01)
65
+ vtn = container_col_1.number_input(label='Your vtn: ', value=74.00, min_value=0.00, step=0.01)
66
+ cnnt = container_col_2.number_input(label='Your cnnt:', value=8.90, min_value=0.00, step=0.01)
67
+ cntp = container_col_3.number_input(label='Your cntp:', value=8.50, min_value=0.00, step=0.01)
68
+ vcn = container_col_4.number_input(label='Your vcn:', value=67.50, min_value=0.00, step=0.01)
69
  elif sample_options_8 == 'Sample 2 (Medium)':
70
+ ttp = container_col_1.number_input(label='Your ttp:', value=489.60, min_value=0.00, step=0.01)
 
 
 
 
 
 
 
 
 
71
  cl = container_col_2.number_input(label='Your cl:', value=13.00, min_value=0.00, step=0.01)
72
+ cnnp = container_col_3.number_input(label='Your cnnp:', value=12.40, min_value=0.00, step=0.01)
73
+ vn = container_col_4.number_input(label='Your vn:', value=78.30, min_value=0.00, step=0.01)
74
+ vtn = container_col_1.number_input(label='Your vtn: ', value=77.20, min_value=0.00, step=0.01)
75
+ cnnt = container_col_2.number_input(label='Your cnnt:', value=11.60, min_value=0.00, step=0.01)
76
+ cntp = container_col_3.number_input(label='Your cntp:', value=8.70, min_value=0.00, step=0.01)
77
+ vcn = container_col_4.number_input(label='Your vcn:', value=65.30, min_value=0.00, step=0.01)
78
+ else:
79
+ ttp = container_col_1.number_input(label='Your ttp:', value=568.2, min_value=0.00, step=0.01)
80
+ cl = container_col_2.number_input(label='Your cl:', value=13.7, min_value=0.00, step=0.01)
81
+ cnnp = container_col_3.number_input(label='Your cnnp:', value=14.0, min_value=0.00, step=0.01)
82
+ vn = container_col_4.number_input(label='Your vn:', value=88.7, min_value=0.00, step=0.01)
83
+ vtn = container_col_1.number_input(label='Your vtn: ', value=86.5, min_value=0.00, step=0.01)
84
+ cnnt = container_col_2.number_input(label='Your cnnt:', value=12.5, min_value=0.00, step=0.01)
85
+ cntp = container_col_3.number_input(label='Your cntp:', value=10.7, min_value=0.00, step=0.01)
86
+ vcn = container_col_4.number_input(label='Your vcn:', value=75.0, min_value=0.00, step=0.01)
87
  else:
88
  sample_options_21 = header_col_2.selectbox(label='Sample options:', options=['Sample 1 (Small)', 'Sample 2 (Medium)', 'Sample 3 (Large)'])
89
  container_col_1, container_col_2, container_col_3, container_col_4, container_col_5 = st.columns([1, 1, 1, 1, 1])
 
161
 
162
  if predict:
163
  if num_of_features == '6 measurements':
164
+ X_6 = np.array([[vtn, vn, vcn, cl, ttp, ttt]])
165
  X_6 = scaler_6.transform(X_6)
166
  y_6 = clf_6.predict(X_6)
167
+ st.success(f'We recommend you choosing {convert_prediction(y_6)} size!')
168
  elif num_of_features == '8 measurements':
169
+ X_8 = np.array([[ttp, cl, cnnp, vn, vtn, cnnt, cntp, vcn]])
170
  X_8 = scaler_8.transform(X_8)
171
  y_8 = clf_8.predict(X_8)
172
+ st.success(f'We recommend you choosing {convert_prediction(np.argmax(y_8, axis=1))} size!')
173
  else:
174
+ 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]])
175
  X_21 = scaler_21.transform(X_21)
176
  y_21 = clf_21.predict(X_21)
177
+ st.success(f'We recommend you choosing {convert_prediction(np.argmax(y_21, axis=1))} size!')