Spaces:
Build error
Build error
Commit
·
70ea6df
1
Parent(s):
3e96ee0
added time to loading bar
Browse files- app/static/demo/index/script.js +23 -3
- app/static/loader.css +9 -0
- app/static/user/dashboard.js +29 -5
- app/templates/loader.html +3 -1
app/static/demo/index/script.js
CHANGED
|
@@ -98,7 +98,10 @@ database_input.addEventListener("change", function(e){
|
|
| 98 |
const formdata = new FormData();
|
| 99 |
formdata.append("a",23);
|
| 100 |
formdata.append("image",e.target.files[0]);
|
| 101 |
-
|
|
|
|
|
|
|
|
|
|
| 102 |
fetch("/demo/add_crops/",
|
| 103 |
{
|
| 104 |
method:'POST',
|
|
@@ -114,6 +117,7 @@ database_input.addEventListener("change", function(e){
|
|
| 114 |
console.log(response);
|
| 115 |
if (response['message']=='successful')
|
| 116 |
{
|
|
|
|
| 117 |
hide_loading_bar();
|
| 118 |
var images_div=document.querySelector("#db_images_bar>#db_images");
|
| 119 |
var img_container_tag=document.createElement("div");
|
|
@@ -397,16 +401,20 @@ function face_recognition(elem)
|
|
| 397 |
return ;
|
| 398 |
}
|
| 399 |
// console.log(elem.files[0]);
|
| 400 |
-
show_loading_bar();
|
|
|
|
|
|
|
| 401 |
fetch("/demo/face_recognition/",{
|
| 402 |
method:"POST",
|
| 403 |
body:formdata
|
| 404 |
}).then(function(response){
|
| 405 |
return response.json();
|
| 406 |
}).then(function(response){
|
| 407 |
-
hide_loading_bar();
|
| 408 |
console.log(response);
|
| 409 |
document.querySelector("#face_rec_image").src="data:image/jpeg;base64,"+response['image'];
|
|
|
|
|
|
|
|
|
|
| 410 |
})
|
| 411 |
|
| 412 |
|
|
@@ -514,8 +522,20 @@ function reset_settings(){
|
|
| 514 |
|
| 515 |
var loader=document.querySelector(".loader");
|
| 516 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 517 |
function show_loading_bar(){
|
| 518 |
loader.classList.remove("hidden");
|
|
|
|
| 519 |
}
|
| 520 |
|
| 521 |
function hide_loading_bar(){
|
|
|
|
| 98 |
const formdata = new FormData();
|
| 99 |
formdata.append("a",23);
|
| 100 |
formdata.append("image",e.target.files[0]);
|
| 101 |
+
|
| 102 |
+
var loader_txt=show_loading_bar();
|
| 103 |
+
const myInterval=start_timer(loader_txt,0.2);
|
| 104 |
+
|
| 105 |
fetch("/demo/add_crops/",
|
| 106 |
{
|
| 107 |
method:'POST',
|
|
|
|
| 117 |
console.log(response);
|
| 118 |
if (response['message']=='successful')
|
| 119 |
{
|
| 120 |
+
clearInterval(myInterval);
|
| 121 |
hide_loading_bar();
|
| 122 |
var images_div=document.querySelector("#db_images_bar>#db_images");
|
| 123 |
var img_container_tag=document.createElement("div");
|
|
|
|
| 401 |
return ;
|
| 402 |
}
|
| 403 |
// console.log(elem.files[0]);
|
| 404 |
+
var loader_txt=show_loading_bar();
|
| 405 |
+
const myInterval=start_timer(loader_txt,0.2);
|
| 406 |
+
|
| 407 |
fetch("/demo/face_recognition/",{
|
| 408 |
method:"POST",
|
| 409 |
body:formdata
|
| 410 |
}).then(function(response){
|
| 411 |
return response.json();
|
| 412 |
}).then(function(response){
|
|
|
|
| 413 |
console.log(response);
|
| 414 |
document.querySelector("#face_rec_image").src="data:image/jpeg;base64,"+response['image'];
|
| 415 |
+
|
| 416 |
+
clearInterval(myInterval);
|
| 417 |
+
hide_loading_bar();
|
| 418 |
})
|
| 419 |
|
| 420 |
|
|
|
|
| 522 |
|
| 523 |
var loader=document.querySelector(".loader");
|
| 524 |
|
| 525 |
+
function start_timer(el,interval){
|
| 526 |
+
//interval in seconds
|
| 527 |
+
el.innerText="";
|
| 528 |
+
|
| 529 |
+
var time=0;
|
| 530 |
+
return setInterval(function () {
|
| 531 |
+
time+=interval;
|
| 532 |
+
el.innerText=time.toFixed(2)+"s";
|
| 533 |
+
}, interval*1000);
|
| 534 |
+
}
|
| 535 |
+
|
| 536 |
function show_loading_bar(){
|
| 537 |
loader.classList.remove("hidden");
|
| 538 |
+
return loader.querySelector("#loader_text");
|
| 539 |
}
|
| 540 |
|
| 541 |
function hide_loading_bar(){
|
app/static/loader.css
CHANGED
|
@@ -34,4 +34,13 @@
|
|
| 34 |
.loader.hidden{
|
| 35 |
display: none;
|
| 36 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 37 |
}
|
|
|
|
| 34 |
.loader.hidden{
|
| 35 |
display: none;
|
| 36 |
|
| 37 |
+
}
|
| 38 |
+
|
| 39 |
+
#loader_text{
|
| 40 |
+
margin: 0px;
|
| 41 |
+
z-index: 24;
|
| 42 |
+
position: absolute;
|
| 43 |
+
left:50%;
|
| 44 |
+
transform:translate(-50%,0);
|
| 45 |
+
background: transparent;
|
| 46 |
}
|
app/static/user/dashboard.js
CHANGED
|
@@ -191,7 +191,9 @@ function filterFunction() {
|
|
| 191 |
|
| 192 |
const formdata = new FormData();
|
| 193 |
formdata.append("image",e.target.files[0]);
|
| 194 |
-
|
|
|
|
|
|
|
| 195 |
|
| 196 |
fetch("get_crops/",
|
| 197 |
{
|
|
@@ -205,7 +207,9 @@ function filterFunction() {
|
|
| 205 |
).then(
|
| 206 |
function(response)
|
| 207 |
{
|
| 208 |
-
|
|
|
|
|
|
|
| 209 |
console.log(response);
|
| 210 |
|
| 211 |
if (response['message']=='successful')
|
|
@@ -278,7 +282,8 @@ function update_db_crops(elem)
|
|
| 278 |
alldata["person_name"]=document.querySelector("#database-form>.field>.person_name").value;
|
| 279 |
alldata["remarks"]=all_remarks;
|
| 280 |
console.log(alldata);
|
| 281 |
-
show_loading_bar();
|
|
|
|
| 282 |
|
| 283 |
|
| 284 |
fetch("set_crops/",{
|
|
@@ -288,6 +293,7 @@ function update_db_crops(elem)
|
|
| 288 |
}).then(function(response){
|
| 289 |
return response.json();
|
| 290 |
}).then(function(response){
|
|
|
|
| 291 |
hide_loading_bar();
|
| 292 |
console.log(response);
|
| 293 |
var person_ids=document.querySelectorAll("#db_people_table>tr>td:first-child");
|
|
@@ -317,17 +323,23 @@ function face_recoginization(elem){
|
|
| 317 |
if(elem.files[0]){
|
| 318 |
formdata=new FormData();
|
| 319 |
formdata.append("image",elem.files[0]);
|
| 320 |
-
|
|
|
|
|
|
|
|
|
|
| 321 |
fetch("face_recognize/",{
|
| 322 |
method:"POST",
|
| 323 |
body:formdata
|
| 324 |
}).then(function(response){
|
| 325 |
return response.json();
|
| 326 |
}).then(function(response){
|
| 327 |
-
|
| 328 |
console.log(response);
|
| 329 |
document.querySelector("#face_recognition_image").src="data:image/jpeg;base64,"+response["pred_image"];
|
| 330 |
document.querySelector("#face_recognition_image").style.width="unset";
|
|
|
|
|
|
|
|
|
|
| 331 |
})
|
| 332 |
}
|
| 333 |
}
|
|
@@ -499,8 +511,20 @@ function reset_settings(){
|
|
| 499 |
|
| 500 |
var loader=document.querySelector(".loader");
|
| 501 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 502 |
function show_loading_bar(){
|
| 503 |
loader.classList.remove("hidden");
|
|
|
|
| 504 |
}
|
| 505 |
|
| 506 |
function hide_loading_bar(){
|
|
|
|
| 191 |
|
| 192 |
const formdata = new FormData();
|
| 193 |
formdata.append("image",e.target.files[0]);
|
| 194 |
+
|
| 195 |
+
var loader_txt=show_loading_bar();
|
| 196 |
+
const myInterval=start_timer(loader_txt,0.2);
|
| 197 |
|
| 198 |
fetch("get_crops/",
|
| 199 |
{
|
|
|
|
| 207 |
).then(
|
| 208 |
function(response)
|
| 209 |
{
|
| 210 |
+
clearInterval(myInterval);
|
| 211 |
+
hide_loading_bar();
|
| 212 |
+
|
| 213 |
console.log(response);
|
| 214 |
|
| 215 |
if (response['message']=='successful')
|
|
|
|
| 282 |
alldata["person_name"]=document.querySelector("#database-form>.field>.person_name").value;
|
| 283 |
alldata["remarks"]=all_remarks;
|
| 284 |
console.log(alldata);
|
| 285 |
+
var loader_txt=show_loading_bar();
|
| 286 |
+
const myInterval=start_timer(loader_txt,0.2);
|
| 287 |
|
| 288 |
|
| 289 |
fetch("set_crops/",{
|
|
|
|
| 293 |
}).then(function(response){
|
| 294 |
return response.json();
|
| 295 |
}).then(function(response){
|
| 296 |
+
clearInterval(myInterval);
|
| 297 |
hide_loading_bar();
|
| 298 |
console.log(response);
|
| 299 |
var person_ids=document.querySelectorAll("#db_people_table>tr>td:first-child");
|
|
|
|
| 323 |
if(elem.files[0]){
|
| 324 |
formdata=new FormData();
|
| 325 |
formdata.append("image",elem.files[0]);
|
| 326 |
+
|
| 327 |
+
var loader_txt=show_loading_bar();
|
| 328 |
+
const myInterval=start_timer(loader_txt,0.2);
|
| 329 |
+
|
| 330 |
fetch("face_recognize/",{
|
| 331 |
method:"POST",
|
| 332 |
body:formdata
|
| 333 |
}).then(function(response){
|
| 334 |
return response.json();
|
| 335 |
}).then(function(response){
|
| 336 |
+
|
| 337 |
console.log(response);
|
| 338 |
document.querySelector("#face_recognition_image").src="data:image/jpeg;base64,"+response["pred_image"];
|
| 339 |
document.querySelector("#face_recognition_image").style.width="unset";
|
| 340 |
+
|
| 341 |
+
clearInterval(myInterval);
|
| 342 |
+
hide_loading_bar();
|
| 343 |
})
|
| 344 |
}
|
| 345 |
}
|
|
|
|
| 511 |
|
| 512 |
var loader=document.querySelector(".loader");
|
| 513 |
|
| 514 |
+
function start_timer(el,interval){
|
| 515 |
+
//interval in seconds
|
| 516 |
+
el.innerText="";
|
| 517 |
+
|
| 518 |
+
var time=0;
|
| 519 |
+
return setInterval(function () {
|
| 520 |
+
time+=interval;
|
| 521 |
+
el.innerText=time.toFixed(2)+"s";
|
| 522 |
+
}, interval*1000);
|
| 523 |
+
}
|
| 524 |
+
|
| 525 |
function show_loading_bar(){
|
| 526 |
loader.classList.remove("hidden");
|
| 527 |
+
return loader.querySelector("#loader_text");
|
| 528 |
}
|
| 529 |
|
| 530 |
function hide_loading_bar(){
|
app/templates/loader.html
CHANGED
|
@@ -1,2 +1,4 @@
|
|
| 1 |
<link type="text/css" rel="stylesheet" href="{{ url_for('static',filename='loader.css') }}">
|
| 2 |
-
<div class="loader hidden"
|
|
|
|
|
|
|
|
|
| 1 |
<link type="text/css" rel="stylesheet" href="{{ url_for('static',filename='loader.css') }}">
|
| 2 |
+
<div class="loader hidden">
|
| 3 |
+
<h4 id="loader_text">Choose an image for face recognition</h4>
|
| 4 |
+
</div>
|