Spaces:
Sleeping
Sleeping
Commit
·
32b85fc
1
Parent(s):
fcafb9d
update
Browse files
app.py
CHANGED
@@ -146,10 +146,11 @@ update_js = """
|
|
146 |
channel_info = JSON.parse(JSON.stringify(channel_info));
|
147 |
|
148 |
let selector;
|
149 |
-
let channel, left, bottom;
|
150 |
|
151 |
if(stage1_info.state == "step2-selecting"){
|
152 |
selector = "#radio-group > div:nth-of-type(2)";
|
|
|
153 |
|
154 |
// update the radios
|
155 |
let all_elem = document.querySelectorAll(selector+" > label");
|
@@ -164,10 +165,11 @@ update_js = """
|
|
164 |
});
|
165 |
}else if(stage1_info.state == "step3-2-selecting"){
|
166 |
selector = "#chkbox-group > div:nth-of-type(2)";
|
|
|
167 |
}else return;
|
168 |
|
169 |
// update the indication
|
170 |
-
channel = stage1_info.missingTemplates[
|
171 |
left = channel_info.templateDict[channel].css_position[0];
|
172 |
bottom = channel_info.templateDict[channel].css_position[1];
|
173 |
|
@@ -313,8 +315,14 @@ with gr.Blocks() as demo:
|
|
313 |
"output_json" : rootpath+'/'+stage1_id+'/mapping_result.json'
|
314 |
},
|
315 |
"state" : "step1-initializing",
|
316 |
-
|
317 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
318 |
"unassignedInputs" : None,
|
319 |
"missingTemplates" : None,
|
320 |
"totalBatchNum" : None,
|
@@ -427,16 +435,17 @@ with gr.Blocks() as demo:
|
|
427 |
currently indicated in red.
|
428 |
"""
|
429 |
# initialize the progress indication label
|
430 |
-
|
431 |
"fillingCount" : 1,
|
432 |
"totalFillingNum" : len(stage1_info["missingTemplates"])
|
433 |
-
}
|
434 |
name = stage1_info["missingTemplates"][0]
|
435 |
-
label = '{} (1/{})'.format(name,
|
436 |
|
|
|
437 |
stage1_info["state"] = "step2-selecting"
|
438 |
# determine which button to display
|
439 |
-
if
|
440 |
yield {stage1_json : stage1_info,
|
441 |
desc_md : gr.Markdown(md),
|
442 |
tpl_img : gr.Image(visible=False),
|
@@ -470,11 +479,11 @@ with gr.Blocks() as demo:
|
|
470 |
|
471 |
# ========================================step2=========================================
|
472 |
elif stage1_info["state"] == "step2-selecting":
|
473 |
-
|
474 |
# --------------------store information before the button click---------------------
|
475 |
# if the user has selected an in_channel to forward to the previous target tpl_channel
|
476 |
if selected_radio != []:
|
477 |
-
prev_target_name = stage1_info["missingTemplates"][
|
478 |
prev_target_idx = channel_info["templateDict"][prev_target_name]["index"]
|
479 |
selected_idx = channel_info["inputDict"][selected_radio]["index"]
|
480 |
|
@@ -559,20 +568,21 @@ with gr.Blocks() as demo:
|
|
559 |
stage1_info["missingTemplates"],
|
560 |
stage1_info["mappingData"][0]["newOrder"])
|
561 |
# initialize the progress indication label
|
562 |
-
|
563 |
"fillingCount" : 1,
|
564 |
"totalFillingNum" : len(stage1_info["missingTemplates"])
|
565 |
-
}
|
566 |
target_name = stage1_info["missingTemplates"][0]
|
567 |
-
chkbox_label = '{} (1/{})'.format(target_name,
|
568 |
|
569 |
target_idx = channel_info["templateDict"][target_name]["index"]
|
570 |
chkbox_value = stage1_info["mappingData"][0]["newOrder"][target_idx]
|
571 |
chkbox_value = [channel_info["inputOrder"][i] for i in chkbox_value]
|
572 |
|
|
|
573 |
stage1_info["state"] = "step3-2-selecting"
|
574 |
# determine which button to display
|
575 |
-
if
|
576 |
yield {stage1_json : stage1_info,
|
577 |
desc_md : gr.Markdown(md),
|
578 |
in_fillmode : gr.Dropdown(visible=False),
|
@@ -592,9 +602,9 @@ with gr.Blocks() as demo:
|
|
592 |
# =======================================step3-2========================================
|
593 |
# step3-2 to step4
|
594 |
elif stage1_info["state"] == "step3-2-selecting":
|
595 |
-
|
596 |
# --------------------store information before the button click---------------------
|
597 |
-
prev_target_name = stage1_info["missingTemplates"][
|
598 |
prev_target_idx = channel_info["templateDict"][prev_target_name]["index"]
|
599 |
selected_indices = [channel_info["inputDict"][channel]["index"] for channel in selected_chkbox]
|
600 |
stage1_info["mappingData"][0]["newOrder"][prev_target_idx] = selected_indices
|
@@ -659,7 +669,8 @@ with gr.Blocks() as demo:
|
|
659 |
# clear the selected value and reset the buttons
|
660 |
@clear_btn.click(inputs = stage1_json, outputs = [radio_group, step2_btn, next_btn])
|
661 |
def clear_value(stage1_info):
|
662 |
-
|
|
|
663 |
return {radio_group : gr.Radio(value=[]),
|
664 |
step2_btn : gr.Button(visible=True),
|
665 |
next_btn : gr.Button(visible=False)}
|
@@ -667,10 +678,11 @@ with gr.Blocks() as demo:
|
|
667 |
return {radio_group : gr.Radio(value=[])}
|
668 |
|
669 |
def update_radio(stage1_info, channel_info, selected):
|
|
|
670 |
# ----------------------store information before the button click-----------------------
|
671 |
# if the user has selected an in_channel to forward to the previous target tpl_channel
|
672 |
if selected != []:
|
673 |
-
prev_target_name = stage1_info["missingTemplates"][
|
674 |
prev_target_idx = channel_info["templateDict"][prev_target_name]["index"]
|
675 |
selected_idx = channel_info["inputDict"][selected]["index"]
|
676 |
|
@@ -681,16 +693,17 @@ with gr.Blocks() as demo:
|
|
681 |
#print(prev_target_name, '<-', selected)
|
682 |
|
683 |
# ------------------------update information for the new round--------------------------
|
684 |
-
|
685 |
|
686 |
# exclude the selected in_channel of the previous round
|
687 |
stage1_info["unassignedInputs"] = app_utils.get_unassigned_inputs(channel_info["inputOrder"], channel_info["inputDict"])
|
688 |
|
689 |
-
target_name = stage1_info["missingTemplates"][
|
690 |
-
radio_label = '{} ({}/{})'.format(target_name,
|
691 |
|
|
|
692 |
# determine which button to display
|
693 |
-
if
|
694 |
return {stage1_json : stage1_info,
|
695 |
channel_json : channel_info,
|
696 |
radio_group : gr.Radio(choices=stage1_info["unassignedInputs"],
|
@@ -719,25 +732,27 @@ with gr.Blocks() as demo:
|
|
719 |
# | Stage1-step3 |
|
720 |
# +========================================================================================+
|
721 |
def update_chkbox(stage1_info, channel_info, selected):
|
|
|
722 |
# ----------------------store information before the button click-----------------------
|
723 |
-
prev_target_name = stage1_info["missingTemplates"][
|
724 |
prev_target_idx = channel_info["templateDict"][prev_target_name]["index"]
|
725 |
selected_indices = [channel_info["inputDict"][channel]["index"] for channel in selected]
|
726 |
stage1_info["mappingData"][0]["newOrder"][prev_target_idx] = selected_indices
|
727 |
#print(f'{prev_target_name}({prev_target_idx}): {selected_indices}')
|
728 |
|
729 |
# ------------------------update information for the new round--------------------------
|
730 |
-
|
731 |
|
732 |
-
target_name = stage1_info["missingTemplates"][
|
733 |
-
chkbox_label = '{} ({}/{})'.format(target_name,
|
734 |
|
735 |
target_idx = channel_info["templateDict"][target_name]["index"]
|
736 |
chkbox_value = stage1_info["mappingData"][0]["newOrder"][target_idx]
|
737 |
chkbox_value = [channel_info["inputOrder"][i] for i in chkbox_value]
|
738 |
|
|
|
739 |
# determine which button to display
|
740 |
-
if
|
741 |
return {stage1_json : stage1_info,
|
742 |
chkbox_group : gr.CheckboxGroup(value=chkbox_value, label=chkbox_label),
|
743 |
step3_btn : gr.Button(visible=False),
|
|
|
146 |
channel_info = JSON.parse(JSON.stringify(channel_info));
|
147 |
|
148 |
let selector;
|
149 |
+
let cnt, channel, left, bottom;
|
150 |
|
151 |
if(stage1_info.state == "step2-selecting"){
|
152 |
selector = "#radio-group > div:nth-of-type(2)";
|
153 |
+
cnt = stage1_info.step2.fillingCount
|
154 |
|
155 |
// update the radios
|
156 |
let all_elem = document.querySelectorAll(selector+" > label");
|
|
|
165 |
});
|
166 |
}else if(stage1_info.state == "step3-2-selecting"){
|
167 |
selector = "#chkbox-group > div:nth-of-type(2)";
|
168 |
+
cnt = stage1_info.step3.fillingCount
|
169 |
}else return;
|
170 |
|
171 |
// update the indication
|
172 |
+
channel = stage1_info.missingTemplates[cnt-1];
|
173 |
left = channel_info.templateDict[channel].css_position[0];
|
174 |
bottom = channel_info.templateDict[channel].css_position[1];
|
175 |
|
|
|
315 |
"output_json" : rootpath+'/'+stage1_id+'/mapping_result.json'
|
316 |
},
|
317 |
"state" : "step1-initializing",
|
318 |
+
"step2" : {
|
319 |
+
"fillingCount" : None,
|
320 |
+
"totalFillingNum" : None
|
321 |
+
},
|
322 |
+
"step3" : {
|
323 |
+
"fillingCount" : None,
|
324 |
+
"totalFillingNum" : None
|
325 |
+
},
|
326 |
"unassignedInputs" : None,
|
327 |
"missingTemplates" : None,
|
328 |
"totalBatchNum" : None,
|
|
|
435 |
currently indicated in red.
|
436 |
"""
|
437 |
# initialize the progress indication label
|
438 |
+
step2 = {
|
439 |
"fillingCount" : 1,
|
440 |
"totalFillingNum" : len(stage1_info["missingTemplates"])
|
441 |
+
}
|
442 |
name = stage1_info["missingTemplates"][0]
|
443 |
+
label = '{} (1/{})'.format(name, step2["totalFillingNum"])
|
444 |
|
445 |
+
stage1_info["step2"] = step2
|
446 |
stage1_info["state"] = "step2-selecting"
|
447 |
# determine which button to display
|
448 |
+
if step2["totalFillingNum"] == 1:
|
449 |
yield {stage1_json : stage1_info,
|
450 |
desc_md : gr.Markdown(md),
|
451 |
tpl_img : gr.Image(visible=False),
|
|
|
479 |
|
480 |
# ========================================step2=========================================
|
481 |
elif stage1_info["state"] == "step2-selecting":
|
482 |
+
step2 = stage1_info["step2"]
|
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["fillingCount"]-1]
|
487 |
prev_target_idx = channel_info["templateDict"][prev_target_name]["index"]
|
488 |
selected_idx = channel_info["inputDict"][selected_radio]["index"]
|
489 |
|
|
|
568 |
stage1_info["missingTemplates"],
|
569 |
stage1_info["mappingData"][0]["newOrder"])
|
570 |
# initialize the progress indication label
|
571 |
+
step3 = {
|
572 |
"fillingCount" : 1,
|
573 |
"totalFillingNum" : len(stage1_info["missingTemplates"])
|
574 |
+
}
|
575 |
target_name = stage1_info["missingTemplates"][0]
|
576 |
+
chkbox_label = '{} (1/{})'.format(target_name, step3["totalFillingNum"])
|
577 |
|
578 |
target_idx = channel_info["templateDict"][target_name]["index"]
|
579 |
chkbox_value = stage1_info["mappingData"][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["totalFillingNum"] == 1:
|
586 |
yield {stage1_json : stage1_info,
|
587 |
desc_md : gr.Markdown(md),
|
588 |
in_fillmode : gr.Dropdown(visible=False),
|
|
|
602 |
# =======================================step3-2========================================
|
603 |
# step3-2 to step4
|
604 |
elif stage1_info["state"] == "step3-2-selecting":
|
605 |
+
step3 = stage1_info["step3"]
|
606 |
# --------------------store information before the button click---------------------
|
607 |
+
prev_target_name = stage1_info["missingTemplates"][step3["fillingCount"]-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["mappingData"][0]["newOrder"][prev_target_idx] = selected_indices
|
|
|
669 |
# clear the selected value and reset the buttons
|
670 |
@clear_btn.click(inputs = stage1_json, outputs = [radio_group, step2_btn, next_btn])
|
671 |
def clear_value(stage1_info):
|
672 |
+
step2 = stage1_info["step2"]
|
673 |
+
if len(stage1_info["unassignedInputs"])==1 and step2["fillingCount"]<step2["totalFillingNum"]:
|
674 |
return {radio_group : gr.Radio(value=[]),
|
675 |
step2_btn : gr.Button(visible=True),
|
676 |
next_btn : gr.Button(visible=False)}
|
|
|
678 |
return {radio_group : gr.Radio(value=[])}
|
679 |
|
680 |
def update_radio(stage1_info, channel_info, selected):
|
681 |
+
step2 = stage1_info["step2"]
|
682 |
# ----------------------store information before the button click-----------------------
|
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["fillingCount"]-1]
|
686 |
prev_target_idx = channel_info["templateDict"][prev_target_name]["index"]
|
687 |
selected_idx = channel_info["inputDict"][selected]["index"]
|
688 |
|
|
|
693 |
#print(prev_target_name, '<-', selected)
|
694 |
|
695 |
# ------------------------update information for the new round--------------------------
|
696 |
+
step2["fillingCount"] += 1
|
697 |
|
698 |
# exclude the selected in_channel of the previous round
|
699 |
stage1_info["unassignedInputs"] = app_utils.get_unassigned_inputs(channel_info["inputOrder"], channel_info["inputDict"])
|
700 |
|
701 |
+
target_name = stage1_info["missingTemplates"][step2["fillingCount"]-1]
|
702 |
+
radio_label = '{} ({}/{})'.format(target_name, step2["fillingCount"], step2["totalFillingNum"])
|
703 |
|
704 |
+
stage1_info["step2"] = step2
|
705 |
# determine which button to display
|
706 |
+
if step2["fillingCount"] == step2["totalFillingNum"]:
|
707 |
return {stage1_json : stage1_info,
|
708 |
channel_json : channel_info,
|
709 |
radio_group : gr.Radio(choices=stage1_info["unassignedInputs"],
|
|
|
732 |
# | Stage1-step3 |
|
733 |
# +========================================================================================+
|
734 |
def update_chkbox(stage1_info, channel_info, selected):
|
735 |
+
step3 = stage1_info["step3"]
|
736 |
# ----------------------store information before the button click-----------------------
|
737 |
+
prev_target_name = stage1_info["missingTemplates"][step3["fillingCount"]-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["mappingData"][0]["newOrder"][prev_target_idx] = selected_indices
|
741 |
#print(f'{prev_target_name}({prev_target_idx}): {selected_indices}')
|
742 |
|
743 |
# ------------------------update information for the new round--------------------------
|
744 |
+
step3["fillingCount"] += 1
|
745 |
|
746 |
+
target_name = stage1_info["missingTemplates"][step3["fillingCount"]-1]
|
747 |
+
chkbox_label = '{} ({}/{})'.format(target_name, step3["fillingCount"], step3["totalFillingNum"])
|
748 |
|
749 |
target_idx = channel_info["templateDict"][target_name]["index"]
|
750 |
chkbox_value = stage1_info["mappingData"][0]["newOrder"][target_idx]
|
751 |
chkbox_value = [channel_info["inputOrder"][i] for i in chkbox_value]
|
752 |
|
753 |
+
stage1_info["step3"] = step3
|
754 |
# determine which button to display
|
755 |
+
if step3["fillingCount"] == step3["totalFillingNum"]:
|
756 |
return {stage1_json : stage1_info,
|
757 |
chkbox_group : gr.CheckboxGroup(value=chkbox_value, label=chkbox_label),
|
758 |
step3_btn : gr.Button(visible=False),
|