audrey06100 commited on
Commit
3e5ef51
·
1 Parent(s): 40b4459
Files changed (1) hide show
  1. app.py +32 -23
app.py CHANGED
@@ -20,6 +20,18 @@ quickstart = """
20
  Upload your data's channel locations in `.loc` format, which can be obtained using **EEGLAB**.
21
  >If you cannot obtain it, we recommend you to download the standard montage <a href="">here</a>. If the channels in those files doesn't match yours, you can use **EEGLAB** to modify them to your needed montage.
22
 
 
 
 
 
 
 
 
 
 
 
 
 
23
  ### Imputation
24
  The models was trained using the EEG signals of 30 channels, including: `Fp1, Fp2, F7, F3, Fz, F4, F8, FT7, FC3, FCz, FC4, FT8, T7, C3, Cz, C4, T8, TP7, CP3, CPz, CP4, TP8, P7, P3, Pz, P4, P8, O1, Oz, O2`.
25
  We expect your input data to include these channels as well.
@@ -53,10 +65,10 @@ init_js = """
53
  let channel, left, bottom;
54
 
55
  if(app_state.stage1State == "step2-selecting"){
56
- selector = "#radio> div:nth-of-type(2)";
57
  attribute = "value";
58
  }else if(app_state.stage1State == "step3-selecting"){
59
- selector = "#chkbox-group> div:nth-of-type(2)";
60
  attribute = "name";
61
  }else return;
62
 
@@ -70,7 +82,7 @@ init_js = """
70
 
71
 
72
  // move the radios/checkboxes
73
- let all_elem = document.querySelectorAll(selector+"> label");
74
  Array.from(all_elem).forEach((item) => {
75
  channel = item.querySelector("input").getAttribute(attribute);
76
  left = channel_info.inputByName[channel].css_position[0];
@@ -83,7 +95,7 @@ init_js = """
83
  bottom: ${bottom};
84
  `;
85
  item.className = "";
86
- item.querySelector(":scope> span").innerText = "";
87
  });
88
 
89
 
@@ -104,7 +116,6 @@ init_js = """
104
  bottom: ${bottom};
105
  }
106
  `;
107
-
108
  // check if indicator already exist
109
  let exist = 0;
110
  const styleSheet = document.styleSheets[0];
@@ -114,10 +125,10 @@ init_js = """
114
  //console.log('exist!');
115
  styleSheet.deleteRule(i);
116
  styleSheet.insertRule(rule, styleSheet.cssRules.length);
117
- break;
118
  }
119
  }
120
- if(exist == 0) styleSheet.insertRule(rule, styleSheet.cssRules.length);
 
121
  }
122
  """
123
 
@@ -130,10 +141,10 @@ update_js = """
130
  let channel, left, bottom;
131
 
132
  if(app_state.stage1State == "step2-selecting"){
133
- selector = "#radio> div:nth-of-type(2)";
134
 
135
  // update the radios
136
- let all_elem = document.querySelectorAll(selector+"> label");
137
  Array.from(all_elem).forEach((item) => {
138
  channel = item.querySelector("input").value;
139
  left = channel_info.inputByName[channel].css_position[0];
@@ -146,10 +157,10 @@ update_js = """
146
  bottom: ${bottom};
147
  `;
148
  item.className = "";
149
- item.querySelector(":scope> span").innerText = "";
150
  });
151
  }else if(app_state.stage1State == "step3-selecting"){
152
- selector = "#chkbox-group> div:nth-of-type(2)";
153
  }else return;
154
 
155
  // update indication
@@ -169,7 +180,6 @@ update_js = """
169
  bottom: ${bottom};
170
  }
171
  `;
172
-
173
  // check if indicator already exist
174
  let exist = 0;
175
  const styleSheet = document.styleSheets[0];
@@ -179,7 +189,6 @@ update_js = """
179
  //console.log('exist!');
180
  styleSheet.deleteRule(i);
181
  styleSheet.insertRule(rule, styleSheet.cssRules.length);
182
- break;
183
  }
184
  }
185
  if(exist == 0) styleSheet.insertRule(rule, styleSheet.cssRules.length);
@@ -217,7 +226,7 @@ with gr.Blocks() as demo:
217
  # stage1-1 : mapping result
218
  with gr.Row():
219
  tpl_montage = gr.Image("./template_montage.png", label="Template montage", visible=False)
220
- map_montage = gr.Image(label="Input channels", visible=False)
221
 
222
  # stage1-2 : assign unmatched input channels to empty template channels
223
  radio = gr.Radio(elem_id="radio", visible=False) #, label=""
@@ -315,7 +324,7 @@ with gr.Blocks() as demo:
315
  # ------------------Stage1-----------------------
316
  desc_md : gr.Markdown("### Step1: Mapping result", visible=False),
317
  tpl_montage : gr.Image(visible=False),
318
- map_montage : gr.Image(value=None, visible=False),
319
  radio : gr.Radio(choices=[], value=[], label="", visible=False),
320
  in_fill_mode : gr.Dropdown(visible=False),
321
  chkbox_group : gr.CheckboxGroup(choices=[], value=[], label="", visible=False),
@@ -353,7 +362,7 @@ with gr.Blocks() as demo:
353
  return {app_state_json : app_state,
354
  desc_md : gr.Markdown("### Step1: Mapping result", visible=True),
355
  tpl_montage : gr.Image(visible=True),
356
- map_montage : gr.Image(value=filename, visible=True),
357
  run_btn : gr.Button(interactive=True)}
358
 
359
  # if matched channels < 30, and there're still some unmatched input channels
@@ -369,13 +378,13 @@ with gr.Blocks() as demo:
369
  return {app_state_json : app_state,
370
  desc_md : gr.Markdown("### Step1: Mapping result", visible=True),
371
  tpl_montage : gr.Image(visible=True),
372
- map_montage : gr.Image(value=filename, visible=True),
373
  next_btn : gr.Button("Next step", visible=True)}
374
 
375
  map_btn.click(
376
  fn = reset_all,
377
  inputs = [in_raw_data, in_raw_loc, in_samplerate],
378
- outputs = [app_state_json, channel_info_json, desc_md, tpl_montage, map_montage, radio, in_fill_mode,
379
  chkbox_group, fillmode_btn, step2_btn, step3_btn, next_btn, run_btn, batch_md, out_denoised_data]
380
  ).success(
381
  fn = mapping_stage1,
@@ -385,7 +394,7 @@ with gr.Blocks() as demo:
385
  ).success(
386
  fn = mapping_result,
387
  inputs = [app_state_json, channel_info_json, in_raw_loc],
388
- outputs = [app_state_json, desc_md, tpl_montage, map_montage, next_btn, run_btn]
389
  )
390
 
391
 
@@ -410,7 +419,7 @@ with gr.Blocks() as demo:
410
  channel_info_json : channel_info,
411
  desc_md : gr.Markdown("### Step2"),
412
  tpl_montage : gr.Image(visible=False),
413
- map_montage : gr.Image(visible=False),
414
  radio : gr.Radio(choices=app_state["stage1UnassignedInputs"], value=[], label=label, visible=True),
415
  next_btn : gr.Button("Next step")}
416
  else:
@@ -418,7 +427,7 @@ with gr.Blocks() as demo:
418
  channel_info_json : channel_info,
419
  desc_md : gr.Markdown("### Step2"),
420
  tpl_montage : gr.Image(visible=False),
421
- map_montage : gr.Image(visible=False),
422
  radio : gr.Radio(choices=app_state["stage1UnassignedInputs"], value=[], label=label, visible=True),
423
  step2_btn : gr.Button(visible=True),
424
  next_btn : gr.Button(visible=False)}
@@ -437,7 +446,7 @@ with gr.Blocks() as demo:
437
  channel_info_json : channel_info,
438
  desc_md : gr.Markdown("### Step3"),
439
  tpl_montage : gr.Image(visible=False),
440
- map_montage : gr.Image(visible=False),
441
  in_fill_mode : gr.Dropdown(visible=True),
442
  fillmode_btn : gr.Button(visible=True),
443
  next_btn : gr.Button(visible=False)}
@@ -524,7 +533,7 @@ with gr.Blocks() as demo:
524
  next_btn.click(
525
  fn = init_next_step,
526
  inputs = [app_state_json, channel_info_json, radio, chkbox_group],
527
- outputs = [app_state_json, channel_info_json, desc_md, tpl_montage, map_montage, radio, in_fill_mode,
528
  chkbox_group, fillmode_btn, step2_btn, next_btn, run_btn]
529
  ).success(
530
  fn = None,
 
20
  Upload your data's channel locations in `.loc` format, which can be obtained using **EEGLAB**.
21
  >If you cannot obtain it, we recommend you to download the standard montage <a href="">here</a>. If the channels in those files doesn't match yours, you can use **EEGLAB** to modify them to your needed montage.
22
 
23
+ ### Mapping
24
+
25
+ - Step1: Mapping result
26
+
27
+ - Step2:
28
+
29
+ - Step3:
30
+
31
+ ### Model
32
+
33
+ ### Run model
34
+
35
  ### Imputation
36
  The models was trained using the EEG signals of 30 channels, including: `Fp1, Fp2, F7, F3, Fz, F4, F8, FT7, FC3, FCz, FC4, FT8, T7, C3, Cz, C4, T8, TP7, CP3, CPz, CP4, TP8, P7, P3, Pz, P4, P8, O1, Oz, O2`.
37
  We expect your input data to include these channels as well.
 
65
  let channel, left, bottom;
66
 
67
  if(app_state.stage1State == "step2-selecting"){
68
+ selector = "#radio > div:nth-of-type(2)";
69
  attribute = "value";
70
  }else if(app_state.stage1State == "step3-selecting"){
71
+ selector = "#chkbox-group > div:nth-of-type(2)";
72
  attribute = "name";
73
  }else return;
74
 
 
82
 
83
 
84
  // move the radios/checkboxes
85
+ let all_elem = document.querySelectorAll(selector+" > label");
86
  Array.from(all_elem).forEach((item) => {
87
  channel = item.querySelector("input").getAttribute(attribute);
88
  left = channel_info.inputByName[channel].css_position[0];
 
95
  bottom: ${bottom};
96
  `;
97
  item.className = "";
98
+ item.querySelector(":scope > span").innerText = "";
99
  });
100
 
101
 
 
116
  bottom: ${bottom};
117
  }
118
  `;
 
119
  // check if indicator already exist
120
  let exist = 0;
121
  const styleSheet = document.styleSheets[0];
 
125
  //console.log('exist!');
126
  styleSheet.deleteRule(i);
127
  styleSheet.insertRule(rule, styleSheet.cssRules.length);
 
128
  }
129
  }
130
+ if(exist == 0)
131
+ styleSheet.insertRule(rule, styleSheet.cssRules.length);
132
  }
133
  """
134
 
 
141
  let channel, left, bottom;
142
 
143
  if(app_state.stage1State == "step2-selecting"){
144
+ selector = "#radio > div:nth-of-type(2)";
145
 
146
  // update the radios
147
+ let all_elem = document.querySelectorAll(selector+" > label");
148
  Array.from(all_elem).forEach((item) => {
149
  channel = item.querySelector("input").value;
150
  left = channel_info.inputByName[channel].css_position[0];
 
157
  bottom: ${bottom};
158
  `;
159
  item.className = "";
160
+ item.querySelector(":scope > span").innerText = "";
161
  });
162
  }else if(app_state.stage1State == "step3-selecting"){
163
+ selector = "#chkbox-group > div:nth-of-type(2)";
164
  }else return;
165
 
166
  // update indication
 
180
  bottom: ${bottom};
181
  }
182
  `;
 
183
  // check if indicator already exist
184
  let exist = 0;
185
  const styleSheet = document.styleSheets[0];
 
189
  //console.log('exist!');
190
  styleSheet.deleteRule(i);
191
  styleSheet.insertRule(rule, styleSheet.cssRules.length);
 
192
  }
193
  }
194
  if(exist == 0) styleSheet.insertRule(rule, styleSheet.cssRules.length);
 
226
  # stage1-1 : mapping result
227
  with gr.Row():
228
  tpl_montage = gr.Image("./template_montage.png", label="Template montage", visible=False)
229
+ in_montage = gr.Image(elem_id="input-montage", label="Input channels", visible=False)
230
 
231
  # stage1-2 : assign unmatched input channels to empty template channels
232
  radio = gr.Radio(elem_id="radio", visible=False) #, label=""
 
324
  # ------------------Stage1-----------------------
325
  desc_md : gr.Markdown("### Step1: Mapping result", visible=False),
326
  tpl_montage : gr.Image(visible=False),
327
+ in_montage : gr.Image(value=None, visible=False),
328
  radio : gr.Radio(choices=[], value=[], label="", visible=False),
329
  in_fill_mode : gr.Dropdown(visible=False),
330
  chkbox_group : gr.CheckboxGroup(choices=[], value=[], label="", visible=False),
 
362
  return {app_state_json : app_state,
363
  desc_md : gr.Markdown("### Step1: Mapping result", visible=True),
364
  tpl_montage : gr.Image(visible=True),
365
+ in_montage : gr.Image(value=filename, visible=True),
366
  run_btn : gr.Button(interactive=True)}
367
 
368
  # if matched channels < 30, and there're still some unmatched input channels
 
378
  return {app_state_json : app_state,
379
  desc_md : gr.Markdown("### Step1: Mapping result", visible=True),
380
  tpl_montage : gr.Image(visible=True),
381
+ in_montage : gr.Image(value=filename, visible=True),
382
  next_btn : gr.Button("Next step", visible=True)}
383
 
384
  map_btn.click(
385
  fn = reset_all,
386
  inputs = [in_raw_data, in_raw_loc, in_samplerate],
387
+ outputs = [app_state_json, channel_info_json, desc_md, tpl_montage, in_montage, radio, in_fill_mode,
388
  chkbox_group, fillmode_btn, step2_btn, step3_btn, next_btn, run_btn, batch_md, out_denoised_data]
389
  ).success(
390
  fn = mapping_stage1,
 
394
  ).success(
395
  fn = mapping_result,
396
  inputs = [app_state_json, channel_info_json, in_raw_loc],
397
+ outputs = [app_state_json, desc_md, tpl_montage, in_montage, next_btn, run_btn]
398
  )
399
 
400
 
 
419
  channel_info_json : channel_info,
420
  desc_md : gr.Markdown("### Step2"),
421
  tpl_montage : gr.Image(visible=False),
422
+ in_montage : gr.Image(visible=False),
423
  radio : gr.Radio(choices=app_state["stage1UnassignedInputs"], value=[], label=label, visible=True),
424
  next_btn : gr.Button("Next step")}
425
  else:
 
427
  channel_info_json : channel_info,
428
  desc_md : gr.Markdown("### Step2"),
429
  tpl_montage : gr.Image(visible=False),
430
+ in_montage : gr.Image(visible=False),
431
  radio : gr.Radio(choices=app_state["stage1UnassignedInputs"], value=[], label=label, visible=True),
432
  step2_btn : gr.Button(visible=True),
433
  next_btn : gr.Button(visible=False)}
 
446
  channel_info_json : channel_info,
447
  desc_md : gr.Markdown("### Step3"),
448
  tpl_montage : gr.Image(visible=False),
449
+ in_montage : gr.Image(visible=False),
450
  in_fill_mode : gr.Dropdown(visible=True),
451
  fillmode_btn : gr.Button(visible=True),
452
  next_btn : gr.Button(visible=False)}
 
533
  next_btn.click(
534
  fn = init_next_step,
535
  inputs = [app_state_json, channel_info_json, radio, chkbox_group],
536
+ outputs = [app_state_json, channel_info_json, desc_md, tpl_montage, in_montage, radio, in_fill_mode,
537
  chkbox_group, fillmode_btn, step2_btn, next_btn, run_btn]
538
  ).success(
539
  fn = None,