wogh2012 commited on
Commit
264a97c
·
1 Parent(s): 6e3fc64

refactor: remove textbox of thresholds

Browse files
Files changed (1) hide show
  1. app.py +8 -48
app.py CHANGED
@@ -55,7 +55,7 @@ def remove_short_duration(seg, th):
55
  return np.concatenate(seg_groups)
56
 
57
 
58
- def gen_each_image(input, seg, image_path, ths, pp=False):
59
  fig = plt.figure(figsize=(15, 18))
60
  plt.subplots_adjust(left=0.02, right=0.98, top=0.98, bottom=0.02, hspace=0.2)
61
  for idx, (in_by_lead, seg_by_lead) in enumerate(zip(input, seg)):
@@ -98,11 +98,11 @@ def gen_each_image(input, seg, image_path, ths, pp=False):
98
  plt.close()
99
 
100
 
101
- def gen_image(subject_id, image_path, pp_image_path, ths):
102
  try:
103
  input, seg = gen_seg(subject_id)
104
- gen_each_image(input, seg, image_path, ths)
105
- gen_each_image(input, seg, pp_image_path, ths, True)
106
  return True
107
  except Exception:
108
  print(tb.format_exc())
@@ -113,7 +113,7 @@ with gr.Blocks() as demo:
113
  with gr.Tab("App"):
114
  with gr.Row():
115
  gr.Textbox(
116
- "Welcome to visit ECG-Delineation space",
117
  label="Information",
118
  lines=1,
119
  )
@@ -148,45 +148,11 @@ with gr.Blocks() as demo:
148
  )
149
  )
150
 
151
- with gr.Row():
152
- gr_ths = [
153
- gr.Textbox(
154
- label="Interval Threshold of P (ms)",
155
- lines=1,
156
- value="10",
157
- ),
158
- gr.Textbox(
159
- label="Duration Threshold of P (ms)",
160
- lines=1,
161
- value="50",
162
- ),
163
- gr.Textbox(
164
- label="Interval Threshold of QRS (ms)",
165
- lines=1,
166
- value="50",
167
- ),
168
- gr.Textbox(
169
- label="Duration Threshold of QRS (ms)",
170
- lines=1,
171
- value="50",
172
- ),
173
- gr.Textbox(
174
- label="Interval Threshold of T (ms)",
175
- lines=1,
176
- value="30",
177
- ),
178
- gr.Textbox(
179
- label="Duration Threshold of T (ms)",
180
- lines=1,
181
- value="50",
182
- ),
183
- ]
184
-
185
  with gr.Row():
186
  gr_image = gr.Image(type="filepath", label="Output")
187
  gr_pp_image = gr.Image(type="filepath", label="PostProcessed Output")
188
 
189
- def show_image(df: pd.DataFrame, evt: gr.SelectData, *ths):
190
  subject_id = evt.row_value[0]
191
 
192
  image_path = f"{tempfile.gettempdir()}/ludb_{subject_id}.png"
@@ -196,17 +162,11 @@ with gr.Blocks() as demo:
196
  ):
197
  return [image_path, pp_image_path]
198
 
199
- gen_image(
200
- subject_id, image_path, pp_image_path, [int(th) / 2 for th in ths]
201
- )
202
 
203
  return [image_path, pp_image_path]
204
 
205
  for gr_df in gr_dfs:
206
- gr_df.select(
207
- fn=show_image,
208
- inputs=[gr_df, *gr_ths],
209
- outputs=[gr_image, gr_pp_image],
210
- )
211
 
212
  demo.launch()
 
55
  return np.concatenate(seg_groups)
56
 
57
 
58
+ def gen_each_image(input, seg, image_path, ths=[5, 25, 25, 25, 15, 25], pp=False):
59
  fig = plt.figure(figsize=(15, 18))
60
  plt.subplots_adjust(left=0.02, right=0.98, top=0.98, bottom=0.02, hspace=0.2)
61
  for idx, (in_by_lead, seg_by_lead) in enumerate(zip(input, seg)):
 
98
  plt.close()
99
 
100
 
101
+ def gen_image(subject_id, image_path, pp_image_path):
102
  try:
103
  input, seg = gen_seg(subject_id)
104
+ gen_each_image(input, seg, image_path)
105
+ gen_each_image(input, seg, pp_image_path, pp=True)
106
  return True
107
  except Exception:
108
  print(tb.format_exc())
 
113
  with gr.Tab("App"):
114
  with gr.Row():
115
  gr.Textbox(
116
+ "Welcome to visit ECG-Delineation space.",
117
  label="Information",
118
  lines=1,
119
  )
 
148
  )
149
  )
150
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
151
  with gr.Row():
152
  gr_image = gr.Image(type="filepath", label="Output")
153
  gr_pp_image = gr.Image(type="filepath", label="PostProcessed Output")
154
 
155
+ def show_image(df: pd.DataFrame, evt: gr.SelectData):
156
  subject_id = evt.row_value[0]
157
 
158
  image_path = f"{tempfile.gettempdir()}/ludb_{subject_id}.png"
 
162
  ):
163
  return [image_path, pp_image_path]
164
 
165
+ gen_image(subject_id, image_path, pp_image_path)
 
 
166
 
167
  return [image_path, pp_image_path]
168
 
169
  for gr_df in gr_dfs:
170
+ gr_df.select(fn=show_image, inputs=[gr_df], outputs=[gr_image, gr_pp_image])
 
 
 
 
171
 
172
  demo.launch()