Spaces:
Sleeping
Sleeping
Commit
·
be921ab
1
Parent(s):
8d3606f
update
Browse files
app.py
CHANGED
@@ -306,7 +306,6 @@ with gr.Blocks() as demo:
|
|
306 |
os.mkdir(rootpath+'/'+stage1_id+'/')
|
307 |
|
308 |
stage1_info = {
|
309 |
-
"id" : stage1_id,
|
310 |
"filePath" : rootpath+'/'+stage1_id+'/',
|
311 |
"fileNames" : {
|
312 |
"inputLocation" : in_loc,
|
@@ -435,17 +434,16 @@ with gr.Blocks() as demo:
|
|
435 |
currently indicated in red.
|
436 |
"""
|
437 |
# initialize the progress indication label
|
438 |
-
step2 = {
|
439 |
"count" : 1,
|
440 |
"totalNum" : len(stage1_info["missingTemplates"])
|
441 |
}
|
442 |
name = stage1_info["missingTemplates"][0]
|
443 |
-
label = '{} (1/{})'.format(name, step2["totalNum"])
|
444 |
|
445 |
-
stage1_info["step2"] = step2
|
446 |
stage1_info["state"] = "step2-selecting"
|
447 |
# determine which button to display
|
448 |
-
if step2["totalNum"] == 1:
|
449 |
yield {stage1_json : stage1_info,
|
450 |
desc_md : gr.Markdown(md),
|
451 |
tpl_img : gr.Image(visible=False),
|
@@ -479,11 +477,10 @@ with gr.Blocks() as demo:
|
|
479 |
|
480 |
# ========================================step2=========================================
|
481 |
elif stage1_info["state"] == "step2-selecting":
|
482 |
-
|
483 |
-
# --------------------store information before the button click---------------------
|
484 |
# if the user has selected an in_channel to forward to the previous target tpl_channel
|
485 |
if selected_radio != []:
|
486 |
-
prev_target_name = stage1_info["missingTemplates"][step2["count"]-1]
|
487 |
prev_target_idx = channel_info["templateDict"][prev_target_name]["index"]
|
488 |
selected_idx = channel_info["inputDict"][selected_radio]["index"]
|
489 |
|
@@ -493,7 +490,7 @@ with gr.Blocks() as demo:
|
|
493 |
channel_info["inputDict"][selected_radio]["assigned"] = True
|
494 |
#print(prev_target_name, '<-', selected_radio)
|
495 |
|
496 |
-
#
|
497 |
# exclude the selected in_channel of the previous round
|
498 |
stage1_info["unassignedInputs"] = app_utils.get_unassigned_inputs(channel_info["inputOrder"],
|
499 |
channel_info["inputDict"])
|
@@ -568,21 +565,20 @@ with gr.Blocks() as demo:
|
|
568 |
stage1_info["missingTemplates"],
|
569 |
stage1_info["mappingResults"][0]["newOrder"])
|
570 |
# initialize the progress indication label
|
571 |
-
step3 = {
|
572 |
"count" : 1,
|
573 |
"totalNum" : len(stage1_info["missingTemplates"])
|
574 |
}
|
575 |
target_name = stage1_info["missingTemplates"][0]
|
576 |
-
chkbox_label = '{} (1/{})'.format(target_name, step3["totalNum"])
|
577 |
|
578 |
target_idx = channel_info["templateDict"][target_name]["index"]
|
579 |
chkbox_value = stage1_info["mappingResults"][0]["newOrder"][target_idx]
|
580 |
chkbox_value = [channel_info["inputOrder"][i] for i in chkbox_value]
|
581 |
|
582 |
-
stage1_info["step3"] = step3
|
583 |
stage1_info["state"] = "step3-2-selecting"
|
584 |
# determine which button to display
|
585 |
-
if step3["totalNum"] == 1:
|
586 |
yield {stage1_json : stage1_info,
|
587 |
desc_md : gr.Markdown(md),
|
588 |
in_fillmode : gr.Dropdown(visible=False),
|
@@ -602,9 +598,8 @@ with gr.Blocks() as demo:
|
|
602 |
# =======================================step3-2========================================
|
603 |
# step3-2 to step4
|
604 |
elif stage1_info["state"] == "step3-2-selecting":
|
605 |
-
|
606 |
-
|
607 |
-
prev_target_name = stage1_info["missingTemplates"][step3["count"]-1]
|
608 |
prev_target_idx = channel_info["templateDict"][prev_target_name]["index"]
|
609 |
selected_indices = [channel_info["inputDict"][channel]["index"] for channel in selected_chkbox]
|
610 |
stage1_info["mappingResults"][0]["newOrder"][prev_target_idx] = selected_indices
|
@@ -658,7 +653,6 @@ with gr.Blocks() as demo:
|
|
658 |
# +========================================================================================+
|
659 |
# | Stage1-step2 |
|
660 |
# +========================================================================================+
|
661 |
-
# determine which button to display based on the current state
|
662 |
@radio_group.select(inputs = stage1_json, outputs = [step2_btn, next_btn])
|
663 |
def determine_button(stage1_info):
|
664 |
if len(stage1_info["unassignedInputs"]) == 1:
|
@@ -679,7 +673,7 @@ with gr.Blocks() as demo:
|
|
679 |
|
680 |
def update_radio(stage1_info, channel_info, selected):
|
681 |
step2 = stage1_info["step2"]
|
682 |
-
#
|
683 |
# if the user has selected an in_channel to forward to the previous target tpl_channel
|
684 |
if selected != []:
|
685 |
prev_target_name = stage1_info["missingTemplates"][step2["count"]-1]
|
@@ -692,7 +686,7 @@ with gr.Blocks() as demo:
|
|
692 |
channel_info["inputDict"][selected]["assigned"] = True
|
693 |
#print(prev_target_name, '<-', selected)
|
694 |
|
695 |
-
#
|
696 |
step2["count"] += 1
|
697 |
|
698 |
# exclude the selected in_channel of the previous round
|
@@ -715,7 +709,6 @@ with gr.Blocks() as demo:
|
|
715 |
channel_json : channel_info,
|
716 |
radio_group : gr.Radio(choices=stage1_info["unassignedInputs"],
|
717 |
value=[], label=radio_label)}
|
718 |
-
|
719 |
step2_btn.click(
|
720 |
fn = update_radio,
|
721 |
inputs = [stage1_json, channel_json, radio_group],
|
@@ -733,14 +726,14 @@ with gr.Blocks() as demo:
|
|
733 |
# +========================================================================================+
|
734 |
def update_chkbox(stage1_info, channel_info, selected):
|
735 |
step3 = stage1_info["step3"]
|
736 |
-
#
|
737 |
prev_target_name = stage1_info["missingTemplates"][step3["count"]-1]
|
738 |
prev_target_idx = channel_info["templateDict"][prev_target_name]["index"]
|
739 |
selected_indices = [channel_info["inputDict"][channel]["index"] for channel in selected]
|
740 |
stage1_info["mappingResults"][0]["newOrder"][prev_target_idx] = selected_indices
|
741 |
#print(f'{prev_target_name}({prev_target_idx}): {selected_indices}')
|
742 |
|
743 |
-
#
|
744 |
step3["count"] += 1
|
745 |
|
746 |
target_name = stage1_info["missingTemplates"][step3["count"]-1]
|
@@ -788,7 +781,6 @@ with gr.Blocks() as demo:
|
|
788 |
# +========================================================================================+
|
789 |
# | Stage2: decode data |
|
790 |
# +========================================================================================+
|
791 |
-
# verify that all required inputs have been provided
|
792 |
@gr.on(triggers = [in_data_file.upload, in_data_file.clear, in_samplerate.change, out_json_file.change],
|
793 |
inputs = [stage1_json, in_data_file, in_samplerate], outputs = run_btn)
|
794 |
def check_input(stage1_info, in_data, samplerate):
|
@@ -798,7 +790,7 @@ with gr.Blocks() as demo:
|
|
798 |
return gr.Button(interactive=False)
|
799 |
|
800 |
@cancel_btn.click(inputs = stage2_json, outputs = [stage2_json, cancel_btn, batch_md])
|
801 |
-
def
|
802 |
utils.dataDelete(stage2_info["filePath"])
|
803 |
stage2_info["state"] = "stopped"
|
804 |
return stage2_info, gr.Button(interactive=False), gr.Markdown(visible=False)
|
@@ -817,7 +809,6 @@ with gr.Blocks() as demo:
|
|
817 |
new_filename = modelname+'_'+os.path.splitext(filename)[0]+'.csv'
|
818 |
|
819 |
stage2_info = {
|
820 |
-
"id" : stage2_id,
|
821 |
"filePath" : rootpath+'/'+stage2_id+'/',
|
822 |
"fileNames" : {
|
823 |
"inputData" : in_data,
|
|
|
306 |
os.mkdir(rootpath+'/'+stage1_id+'/')
|
307 |
|
308 |
stage1_info = {
|
|
|
309 |
"filePath" : rootpath+'/'+stage1_id+'/',
|
310 |
"fileNames" : {
|
311 |
"inputLocation" : in_loc,
|
|
|
434 |
currently indicated in red.
|
435 |
"""
|
436 |
# initialize the progress indication label
|
437 |
+
stage1_info["step2"] = {
|
438 |
"count" : 1,
|
439 |
"totalNum" : len(stage1_info["missingTemplates"])
|
440 |
}
|
441 |
name = stage1_info["missingTemplates"][0]
|
442 |
+
label = '{} (1/{})'.format(name, stage1_info["step2"]["totalNum"])
|
443 |
|
|
|
444 |
stage1_info["state"] = "step2-selecting"
|
445 |
# determine which button to display
|
446 |
+
if stage1_info["step2"]["totalNum"] == 1:
|
447 |
yield {stage1_json : stage1_info,
|
448 |
desc_md : gr.Markdown(md),
|
449 |
tpl_img : gr.Image(visible=False),
|
|
|
477 |
|
478 |
# ========================================step2=========================================
|
479 |
elif stage1_info["state"] == "step2-selecting":
|
480 |
+
# --------------------------------store information---------------------------------
|
|
|
481 |
# if the user has selected an in_channel to forward to the previous target tpl_channel
|
482 |
if selected_radio != []:
|
483 |
+
prev_target_name = stage1_info["missingTemplates"][stage1_info["step2"]["count"]-1]
|
484 |
prev_target_idx = channel_info["templateDict"][prev_target_name]["index"]
|
485 |
selected_idx = channel_info["inputDict"][selected_radio]["index"]
|
486 |
|
|
|
490 |
channel_info["inputDict"][selected_radio]["assigned"] = True
|
491 |
#print(prev_target_name, '<-', selected_radio)
|
492 |
|
493 |
+
# -------------------------------update the next step-------------------------------
|
494 |
# exclude the selected in_channel of the previous round
|
495 |
stage1_info["unassignedInputs"] = app_utils.get_unassigned_inputs(channel_info["inputOrder"],
|
496 |
channel_info["inputDict"])
|
|
|
565 |
stage1_info["missingTemplates"],
|
566 |
stage1_info["mappingResults"][0]["newOrder"])
|
567 |
# initialize the progress indication label
|
568 |
+
stage1_info["step3"] = {
|
569 |
"count" : 1,
|
570 |
"totalNum" : len(stage1_info["missingTemplates"])
|
571 |
}
|
572 |
target_name = stage1_info["missingTemplates"][0]
|
573 |
+
chkbox_label = '{} (1/{})'.format(target_name, stage1_info["step3"]["totalNum"])
|
574 |
|
575 |
target_idx = channel_info["templateDict"][target_name]["index"]
|
576 |
chkbox_value = stage1_info["mappingResults"][0]["newOrder"][target_idx]
|
577 |
chkbox_value = [channel_info["inputOrder"][i] for i in chkbox_value]
|
578 |
|
|
|
579 |
stage1_info["state"] = "step3-2-selecting"
|
580 |
# determine which button to display
|
581 |
+
if stage1_info["step3"]["totalNum"] == 1:
|
582 |
yield {stage1_json : stage1_info,
|
583 |
desc_md : gr.Markdown(md),
|
584 |
in_fillmode : gr.Dropdown(visible=False),
|
|
|
598 |
# =======================================step3-2========================================
|
599 |
# step3-2 to step4
|
600 |
elif stage1_info["state"] == "step3-2-selecting":
|
601 |
+
# --------------------------------store information---------------------------------
|
602 |
+
prev_target_name = stage1_info["missingTemplates"][stage1_info["step3"]["count"]-1]
|
|
|
603 |
prev_target_idx = channel_info["templateDict"][prev_target_name]["index"]
|
604 |
selected_indices = [channel_info["inputDict"][channel]["index"] for channel in selected_chkbox]
|
605 |
stage1_info["mappingResults"][0]["newOrder"][prev_target_idx] = selected_indices
|
|
|
653 |
# +========================================================================================+
|
654 |
# | Stage1-step2 |
|
655 |
# +========================================================================================+
|
|
|
656 |
@radio_group.select(inputs = stage1_json, outputs = [step2_btn, next_btn])
|
657 |
def determine_button(stage1_info):
|
658 |
if len(stage1_info["unassignedInputs"]) == 1:
|
|
|
673 |
|
674 |
def update_radio(stage1_info, channel_info, selected):
|
675 |
step2 = stage1_info["step2"]
|
676 |
+
# ----------------------------------store information-----------------------------------
|
677 |
# if the user has selected an in_channel to forward to the previous target tpl_channel
|
678 |
if selected != []:
|
679 |
prev_target_name = stage1_info["missingTemplates"][step2["count"]-1]
|
|
|
686 |
channel_info["inputDict"][selected]["assigned"] = True
|
687 |
#print(prev_target_name, '<-', selected)
|
688 |
|
689 |
+
# ---------------------------------update the new round---------------------------------
|
690 |
step2["count"] += 1
|
691 |
|
692 |
# exclude the selected in_channel of the previous round
|
|
|
709 |
channel_json : channel_info,
|
710 |
radio_group : gr.Radio(choices=stage1_info["unassignedInputs"],
|
711 |
value=[], label=radio_label)}
|
|
|
712 |
step2_btn.click(
|
713 |
fn = update_radio,
|
714 |
inputs = [stage1_json, channel_json, radio_group],
|
|
|
726 |
# +========================================================================================+
|
727 |
def update_chkbox(stage1_info, channel_info, selected):
|
728 |
step3 = stage1_info["step3"]
|
729 |
+
# ----------------------------------store information-----------------------------------
|
730 |
prev_target_name = stage1_info["missingTemplates"][step3["count"]-1]
|
731 |
prev_target_idx = channel_info["templateDict"][prev_target_name]["index"]
|
732 |
selected_indices = [channel_info["inputDict"][channel]["index"] for channel in selected]
|
733 |
stage1_info["mappingResults"][0]["newOrder"][prev_target_idx] = selected_indices
|
734 |
#print(f'{prev_target_name}({prev_target_idx}): {selected_indices}')
|
735 |
|
736 |
+
# ---------------------------------update the new round---------------------------------
|
737 |
step3["count"] += 1
|
738 |
|
739 |
target_name = stage1_info["missingTemplates"][step3["count"]-1]
|
|
|
781 |
# +========================================================================================+
|
782 |
# | Stage2: decode data |
|
783 |
# +========================================================================================+
|
|
|
784 |
@gr.on(triggers = [in_data_file.upload, in_data_file.clear, in_samplerate.change, out_json_file.change],
|
785 |
inputs = [stage1_json, in_data_file, in_samplerate], outputs = run_btn)
|
786 |
def check_input(stage1_info, in_data, samplerate):
|
|
|
790 |
return gr.Button(interactive=False)
|
791 |
|
792 |
@cancel_btn.click(inputs = stage2_json, outputs = [stage2_json, cancel_btn, batch_md])
|
793 |
+
def stop_stage2(stage2_info):
|
794 |
utils.dataDelete(stage2_info["filePath"])
|
795 |
stage2_info["state"] = "stopped"
|
796 |
return stage2_info, gr.Button(interactive=False), gr.Markdown(visible=False)
|
|
|
809 |
new_filename = modelname+'_'+os.path.splitext(filename)[0]+'.csv'
|
810 |
|
811 |
stage2_info = {
|
|
|
812 |
"filePath" : rootpath+'/'+stage2_id+'/',
|
813 |
"fileNames" : {
|
814 |
"inputData" : in_data,
|