audrey06100 commited on
Commit
efd7fc6
·
1 Parent(s): 32b85fc
Files changed (2) hide show
  1. app.py +29 -29
  2. app_utils.py +1 -1
app.py CHANGED
@@ -150,7 +150,7 @@ update_js = """
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,7 +165,7 @@ update_js = """
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
@@ -316,16 +316,16 @@ with gr.Blocks() as demo:
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,
329
  "mappingData" : [
330
  {
331
  "newOrder" : None,
@@ -436,16 +436,16 @@ with gr.Blocks() as demo:
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),
@@ -483,7 +483,7 @@ with gr.Blocks() as demo:
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
 
@@ -569,11 +569,11 @@ with gr.Blocks() as demo:
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]
@@ -582,7 +582,7 @@ with gr.Blocks() as demo:
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),
@@ -604,7 +604,7 @@ with gr.Blocks() as demo:
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
@@ -670,7 +670,7 @@ with gr.Blocks() as demo:
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)}
@@ -682,7 +682,7 @@ with gr.Blocks() as demo:
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,17 +693,17 @@ with gr.Blocks() as demo:
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"],
@@ -734,17 +734,17 @@ with gr.Blocks() as demo:
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]
@@ -752,7 +752,7 @@ with gr.Blocks() as demo:
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),
@@ -833,7 +833,7 @@ with gr.Blocks() as demo:
833
  out_data_file : gr.File(value=None, visible=False)}
834
 
835
  def run_model(stage1_info, stage2_info, modelname):
836
- batch_num = stage1_info["totalBatchNum"]
837
  mapping_data = stage1_info["mappingData"]
838
  samplerate = stage2_info["sampleRate"]
839
  filepath = stage2_info["filePath"]
 
150
 
151
  if(stage1_info.state == "step2-selecting"){
152
  selector = "#radio-group > div:nth-of-type(2)";
153
+ cnt = stage1_info.step2.count
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.count
169
  }else return;
170
 
171
  // update the indication
 
316
  },
317
  "state" : "step1-initializing",
318
  "step2" : {
319
+ "count" : None,
320
+ "totalNum" : None
321
  },
322
  "step3" : {
323
+ "count" : None,
324
+ "totalNum" : None
325
  },
326
  "unassignedInputs" : None,
327
  "missingTemplates" : None,
328
+ "batchNum" : None,
329
  "mappingData" : [
330
  {
331
  "newOrder" : None,
 
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),
 
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
 
 
569
  stage1_info["mappingData"][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["mappingData"][0]["newOrder"][target_idx]
 
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),
 
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["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["mappingData"][0]["newOrder"][prev_target_idx] = selected_indices
 
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["count"]<step2["totalNum"]:
674
  return {radio_group : gr.Radio(value=[]),
675
  step2_btn : gr.Button(visible=True),
676
  next_btn : gr.Button(visible=False)}
 
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["count"]-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["count"] += 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["count"]-1]
702
+ radio_label = '{} ({}/{})'.format(target_name, step2["count"], step2["totalNum"])
703
 
704
  stage1_info["step2"] = step2
705
  # determine which button to display
706
+ if step2["count"] == step2["totalNum"]:
707
  return {stage1_json : stage1_info,
708
  channel_json : channel_info,
709
  radio_group : gr.Radio(choices=stage1_info["unassignedInputs"],
 
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["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["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["count"] += 1
745
 
746
+ target_name = stage1_info["missingTemplates"][step3["count"]-1]
747
+ chkbox_label = '{} ({}/{})'.format(target_name, step3["count"], step3["totalNum"])
748
 
749
  target_idx = channel_info["templateDict"][target_name]["index"]
750
  chkbox_value = stage1_info["mappingData"][0]["newOrder"][target_idx]
 
752
 
753
  stage1_info["step3"] = step3
754
  # determine which button to display
755
+ if step3["count"] == step3["totalNum"]:
756
  return {stage1_json : stage1_info,
757
  chkbox_group : gr.CheckboxGroup(value=chkbox_value, label=chkbox_label),
758
  step3_btn : gr.Button(visible=False),
 
833
  out_data_file : gr.File(value=None, visible=False)}
834
 
835
  def run_model(stage1_info, stage2_info, modelname):
836
+ batch_num = stage1_info["batchNum"]
837
  mapping_data = stage1_info["mappingData"]
838
  samplerate = stage2_info["sampleRate"]
839
  filepath = stage2_info["filePath"]
app_utils.py CHANGED
@@ -352,7 +352,7 @@ def mapping_result(stage1_info, channel_info, filename):
352
  jsonfile.write(json.dumps(new_dict))
353
 
354
  stage1_info.update({
355
- "totalBatchNum" : batch_num,
356
  "mappingData" : all_mapping_data
357
  })
358
  return stage1_info, channel_info
 
352
  jsonfile.write(json.dumps(new_dict))
353
 
354
  stage1_info.update({
355
+ "batchNum" : batch_num,
356
  "mappingData" : all_mapping_data
357
  })
358
  return stage1_info, channel_info