@@ -127,6 +127,8 @@ async function deleteConnection(sending_object) {
127127function uploadRequest ( ) {
128128 if ( data_upload . files . length == 0 ) return
129129 const file = data_upload . files [ 0 ]
130+ const button_wrapper = document . getElementById ( "train-button" )
131+ const train_button = button_wrapper . children [ 0 ]
130132
131133 fetch ( `http://${ py_server_address } /${ user_id } /${ model_id } ` , {
132134 method : "PATCH" ,
@@ -142,6 +144,8 @@ function uploadRequest() {
142144 timer : 1500 ,
143145 } )
144146 console . error ( `Failed to upload data for ${ file . name } ` )
147+ button_wrapper . setAttribute ( "disabled" , true )
148+ train_button . setAttribute ( "disabled" , true )
145149 return
146150 }
147151 Swal . fire ( {
@@ -151,29 +155,31 @@ function uploadRequest() {
151155 showConfirmButton : false ,
152156 timer : 1500 ,
153157 } )
158+ // allow user to press a train button from now on
159+ button_wrapper . removeAttribute ( "disabled" )
160+ train_button . removeAttribute ( "disabled" )
154161 } )
155162 setModelView ( "irrelevant" )
156- // allow user to press a train button from now on
157- button_wrapper = document . getElementById ( "train-button" )
158- button_wrapper . getElementsByTy
159- train_button = button_wrapper . children [ 0 ]
160- button_wrapper . removeAttribute ( "disabled" )
161- train_button . removeAttribute ( "disabled" )
162163}
163164
164165function trainRequest ( ) {
165166 fetch ( `http://${ py_server_address } /train/${ user_id } /${ model_id } /0` , {
166167 method : "PUT" ,
167168 mode : "cors" ,
168- } ) . then ( response => {
169- showBuildNotification ( response . ok )
170- onTrainShowPredict ( response . ok )
171- if ( response . ok ) {
172- setModelView ( "success" )
173- } else {
174- setModelView ( "error" )
175- }
176169 } )
170+ . then ( response => {
171+ showBuildNotification ( response . ok , response )
172+ onTrainShowPredict ( response . ok )
173+ if ( response . ok ) {
174+ setModelView ( "success" )
175+ } else {
176+ setModelView ( "error" )
177+ }
178+ } )
179+ . catch ( reason => {
180+ showBuildNotification ( false )
181+ setModelView ( "error" )
182+ } )
177183}
178184
179185async function predictRequest ( ) {
@@ -219,5 +225,8 @@ async function predictRequest() {
219225 return
220226 }
221227 hideResult ( ) // hide previous predict result
222- onPredictShowResult ( responseJson )
228+ const extension = file . name . split ( "." ) . pop ( )
229+ if ( extension == "png" )
230+ onPredictShowResult ( responseJson == 0 ? "It's a cat!" : "It's a dog!" )
231+ else onPredictShowResult ( responseJson )
223232}
0 commit comments