audrey06100 commited on
Commit
9361bcd
·
1 Parent(s): e7a030a
Files changed (1) hide show
  1. app.py +22 -22
app.py CHANGED
@@ -224,7 +224,7 @@ with gr.Blocks() as demo:
224
  gr.Markdown("# 1.Channel Mapping")
225
  # ---------------------input---------------------
226
  in_loc_file = gr.File(label="Channel locations (.loc, .locs, .xyz, .sfp, .txt)",
227
- file_types=[".loc", "locs", ".xyz", ".sfp", ".txt"])
228
  map_btn = gr.Button("Map")
229
  # ---------------------output--------------------
230
  desc_md = gr.Markdown(visible=False)
@@ -232,7 +232,7 @@ with gr.Blocks() as demo:
232
  # --------------------mapping--------------------
233
  # step1 : initial matching and scaling
234
  with gr.Row():
235
- tpl_img = gr.Image("./template_montage.png", label="Template montage", visible=False)
236
  mapped_img = gr.Image(label="Matching results", visible=False)
237
  # step2 : forward unmatched input channels to empty template channels
238
  radio_group = gr.Radio(elem_id="radio-group", visible=False)
@@ -301,17 +301,17 @@ with gr.Blocks() as demo:
301
  utils.dataDelete(folder)
302
  # establish a new folder
303
  stage1_id = uuid.uuid4().hex
304
- os.mkdir(rootpath+"/"+stage1_id+"/")
305
 
306
  # initialize stage1_info, stage2_info, channel_info
307
  stage1_info = {
308
  "id" : stage1_id,
309
- "filePath" : rootpath+"/"+stage1_id+"/",
310
  "fileNames" : {
311
  "input_loc" : in_loc,
312
- "input_montage" : rootpath+"/"+stage1_id+"/input_montage.png",
313
- "mapped_montage" : rootpath+"/"+stage1_id+"/mapped_montage.png",
314
- "output_json" : rootpath+"/"+stage1_id+"/mapping_result.json"
315
  },
316
  "state" : "step1-initializing",
317
  "fillingCount" : None,
@@ -343,7 +343,7 @@ with gr.Blocks() as demo:
343
  step2_btn : gr.Button(visible=False),
344
  in_fillmode : gr.Dropdown(value="mean", visible=False),
345
  fillmode_btn : gr.Button(visible=False),
346
- chkbox_group : gr.CheckboxGroup(choices=[], value=[], label="", visible=False),
347
  step3_btn : gr.Button(visible=False),
348
  out_json_file : gr.File(value=None, visible=False),
349
  # --------------------Stage2-------------------------
@@ -435,7 +435,7 @@ with gr.Blocks() as demo:
435
  "totalFillingNum" : len(stage1_info["missingTemplates"])
436
  })
437
  name = stage1_info["missingTemplates"][0]
438
- label = "{} (1/{})".format(name, stage1_info["totalFillingNum"])
439
 
440
  stage1_info["state"] = "step2-selecting"
441
  # determine which button to display
@@ -571,7 +571,7 @@ with gr.Blocks() as demo:
571
  "totalFillingNum" : len(stage1_info["missingTemplates"])
572
  })
573
  target_name = stage1_info["missingTemplates"][0]
574
- chkbox_label = "{} (1/{})".format(target_name, stage1_info["totalFillingNum"])
575
 
576
  target_idx = channel_info["templateDict"][target_name]["index"]
577
  chkbox_value = stage1_info["mappingData"][0]["newOrder"][target_idx]
@@ -695,7 +695,7 @@ with gr.Blocks() as demo:
695
  stage1_info["unassignedInputs"] = app_utils.get_unassigned_inputs(channel_info["inputOrder"], channel_info["inputDict"])
696
 
697
  target_name = stage1_info["missingTemplates"][stage1_info["fillingCount"]-1]
698
- radio_label = "{} ({}/{})".format(target_name, stage1_info["fillingCount"], stage1_info["totalFillingNum"])
699
 
700
  # determine which button to display
701
  if stage1_info["fillingCount"] == stage1_info["totalFillingNum"]:
@@ -738,7 +738,7 @@ with gr.Blocks() as demo:
738
  stage1_info["fillingCount"] += 1
739
 
740
  target_name = stage1_info["missingTemplates"][stage1_info["fillingCount"]-1]
741
- chkbox_label = "{} ({}/{})".format(target_name, stage1_info["fillingCount"], stage1_info["totalFillingNum"])
742
 
743
  target_idx = channel_info["templateDict"][target_name]["index"]
744
  chkbox_value = stage1_info["mappingData"][0]["newOrder"][target_idx]
@@ -804,17 +804,17 @@ with gr.Blocks() as demo:
804
  utils.dataDelete(folder)
805
  # establish a new folder
806
  stage2_id = uuid.uuid4().hex
807
- os.mkdir(rootpath+"/"+stage2_id+"/")
808
 
809
  filename = os.path.basename(str(in_data))
810
  new_filename = modelname+'_'+os.path.splitext(filename)[0]+'.csv'
811
 
812
  stage2_info = {
813
  "id" : stage2_id,
814
- "filePath" : rootpath+"/"+stage2_id+"/",
815
  "fileNames" : {
816
  "input_data" : in_data,
817
- "output_data" : rootpath+"/"+stage2_id+"/"+new_filename
818
  },
819
  "state" : "running",
820
  "sampleRate" : int(samplerate)
@@ -836,12 +836,12 @@ with gr.Blocks() as demo:
836
 
837
  break_flag = False # indicate if the process has been interrupted by the user
838
  for i in range(batch_num):
839
- md = "Running model({}/{})...".format(i+1, batch_num)
840
  yield {batch_md : gr.Markdown(md)}
841
 
842
  # establish a temp folder
843
  try:
844
- os.mkdir(filepath+"temp_data/")
845
  except FileNotFoundError:
846
  print('break1')
847
  break_flag = True
@@ -855,19 +855,19 @@ with gr.Blocks() as demo:
855
  d_filename = 'denoised_{:02d}.csv'.format(i+1)
856
  try:
857
  # step1: Reorder input data
858
- data_shape = app_utils.reorder_data(new_idx, fill_flags, filename, filepath+"temp_data/"+m_filename)
859
  # step2: Data preprocessing
860
- total_file_num = utils.preprocessing(filepath+"temp_data/", m_filename, samplerate)
861
  # step3: Signal reconstruction
862
- utils.reconstruct(modelname, total_file_num, filepath+"temp_data/", d_filename, samplerate)
863
  # step4: Restore original order
864
- app_utils.restore_order(i, data_shape, new_idx, fill_flags, filepath+"temp_data/"+d_filename, new_filename)
865
  except FileNotFoundError:
866
  print('break2')
867
  break_flag = True
868
  break
869
  # ----------------------------------------------------------------------------------
870
- utils.dataDelete(filepath+"temp_data/")
871
 
872
  if break_flag == True:
873
  yield {run_btn : gr.Button(visible=True),
 
224
  gr.Markdown("# 1.Channel Mapping")
225
  # ---------------------input---------------------
226
  in_loc_file = gr.File(label="Channel locations (.loc, .locs, .xyz, .sfp, .txt)",
227
+ file_types=['.loc', 'locs', '.xyz', '.sfp', '.txt'])
228
  map_btn = gr.Button("Map")
229
  # ---------------------output--------------------
230
  desc_md = gr.Markdown(visible=False)
 
232
  # --------------------mapping--------------------
233
  # step1 : initial matching and scaling
234
  with gr.Row():
235
+ tpl_img = gr.Image('./template_montage.png', label="Template montage", visible=False)
236
  mapped_img = gr.Image(label="Matching results", visible=False)
237
  # step2 : forward unmatched input channels to empty template channels
238
  radio_group = gr.Radio(elem_id="radio-group", visible=False)
 
301
  utils.dataDelete(folder)
302
  # establish a new folder
303
  stage1_id = uuid.uuid4().hex
304
+ os.mkdir(rootpath+'/'+stage1_id+'/')
305
 
306
  # initialize stage1_info, stage2_info, channel_info
307
  stage1_info = {
308
  "id" : stage1_id,
309
+ "filePath" : rootpath+'/'+stage1_id+'/',
310
  "fileNames" : {
311
  "input_loc" : in_loc,
312
+ "input_montage" : rootpath+'/'+stage1_id+'/input_montage.png',
313
+ "mapped_montage" : rootpath+'/'+stage1_id+'/mapped_montage.png',
314
+ "output_json" : rootpath+'/'+stage1_id+'/mapping_result.json'
315
  },
316
  "state" : "step1-initializing",
317
  "fillingCount" : None,
 
343
  step2_btn : gr.Button(visible=False),
344
  in_fillmode : gr.Dropdown(value="mean", visible=False),
345
  fillmode_btn : gr.Button(visible=False),
346
+ chkbox_group : gr.CheckboxGroup(choices=[], value=[], label='', visible=False),
347
  step3_btn : gr.Button(visible=False),
348
  out_json_file : gr.File(value=None, visible=False),
349
  # --------------------Stage2-------------------------
 
435
  "totalFillingNum" : len(stage1_info["missingTemplates"])
436
  })
437
  name = stage1_info["missingTemplates"][0]
438
+ label = '{} (1/{})'.format(name, stage1_info["totalFillingNum"])
439
 
440
  stage1_info["state"] = "step2-selecting"
441
  # determine which button to display
 
571
  "totalFillingNum" : len(stage1_info["missingTemplates"])
572
  })
573
  target_name = stage1_info["missingTemplates"][0]
574
+ chkbox_label = '{} (1/{})'.format(target_name, stage1_info["totalFillingNum"])
575
 
576
  target_idx = channel_info["templateDict"][target_name]["index"]
577
  chkbox_value = stage1_info["mappingData"][0]["newOrder"][target_idx]
 
695
  stage1_info["unassignedInputs"] = app_utils.get_unassigned_inputs(channel_info["inputOrder"], channel_info["inputDict"])
696
 
697
  target_name = stage1_info["missingTemplates"][stage1_info["fillingCount"]-1]
698
+ radio_label = '{} ({}/{})'.format(target_name, stage1_info["fillingCount"], stage1_info["totalFillingNum"])
699
 
700
  # determine which button to display
701
  if stage1_info["fillingCount"] == stage1_info["totalFillingNum"]:
 
738
  stage1_info["fillingCount"] += 1
739
 
740
  target_name = stage1_info["missingTemplates"][stage1_info["fillingCount"]-1]
741
+ chkbox_label = '{} ({}/{})'.format(target_name, stage1_info["fillingCount"], stage1_info["totalFillingNum"])
742
 
743
  target_idx = channel_info["templateDict"][target_name]["index"]
744
  chkbox_value = stage1_info["mappingData"][0]["newOrder"][target_idx]
 
804
  utils.dataDelete(folder)
805
  # establish a new folder
806
  stage2_id = uuid.uuid4().hex
807
+ os.mkdir(rootpath+'/'+stage2_id+'/')
808
 
809
  filename = os.path.basename(str(in_data))
810
  new_filename = modelname+'_'+os.path.splitext(filename)[0]+'.csv'
811
 
812
  stage2_info = {
813
  "id" : stage2_id,
814
+ "filePath" : rootpath+'/'+stage2_id+'/',
815
  "fileNames" : {
816
  "input_data" : in_data,
817
+ "output_data" : rootpath+'/'+stage2_id+'/'+new_filename
818
  },
819
  "state" : "running",
820
  "sampleRate" : int(samplerate)
 
836
 
837
  break_flag = False # indicate if the process has been interrupted by the user
838
  for i in range(batch_num):
839
+ md = 'Running model({}/{})...'.format(i+1, batch_num)
840
  yield {batch_md : gr.Markdown(md)}
841
 
842
  # establish a temp folder
843
  try:
844
+ os.mkdir(filepath+'temp_data/')
845
  except FileNotFoundError:
846
  print('break1')
847
  break_flag = True
 
855
  d_filename = 'denoised_{:02d}.csv'.format(i+1)
856
  try:
857
  # step1: Reorder input data
858
+ data_shape = app_utils.reorder_data(new_idx, fill_flags, filename, filepath+'temp_data/'+m_filename)
859
  # step2: Data preprocessing
860
+ total_file_num = utils.preprocessing(filepath+'temp_data/', m_filename, samplerate)
861
  # step3: Signal reconstruction
862
+ utils.reconstruct(modelname, total_file_num, filepath+'temp_data/', d_filename, samplerate)
863
  # step4: Restore original order
864
+ app_utils.restore_order(i, data_shape, new_idx, fill_flags, filepath+'temp_data/'+d_filename, new_filename)
865
  except FileNotFoundError:
866
  print('break2')
867
  break_flag = True
868
  break
869
  # ----------------------------------------------------------------------------------
870
+ utils.dataDelete(filepath+'temp_data/')
871
 
872
  if break_flag == True:
873
  yield {run_btn : gr.Button(visible=True),