LiangLabUMB commited on
Commit
5b3958c
·
verified ·
1 Parent(s): 98a07a0

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +9 -4
app.py CHANGED
@@ -142,6 +142,13 @@ def classify_cells_by_blueness(image_np, masks, blue_threshold):
142
  final_overlay = np.clip(final_overlay, 0, 255).astype(np.uint8)
143
 
144
  return len(dead_cells), len(alive_cells), final_overlay
 
 
 
 
 
 
 
145
 
146
  @spaces.GPU
147
  def run_segmentation_editor(editor_data, model_choice):
@@ -176,7 +183,6 @@ def run_segmentation_editor(editor_data, model_choice):
176
  masks, flows, styles = model.eval(processed_image_np, diameter=None, channels=[0, 0])
177
 
178
  cell_count = len(np.unique(masks)) - 1
179
-
180
  # Create a basic segmentation overlay (without viability)
181
  segmentation_overlay = processed_image_np.copy().astype(np.float32)
182
  if masks.max() > 0:
@@ -249,8 +255,7 @@ def run_segmentation_manual(image, model_choice, crop_coords):
249
  # Run Cellpose
250
  masks, flows, styles = model.eval(processed_image_np, diameter=None, channels=[0, 0])
251
 
252
- cell_count = len(np.unique(masks)) - 1
253
-
254
  # Create a basic segmentation overlay
255
  segmentation_overlay = processed_image_np.copy().astype(np.float32)
256
  if masks.max() > 0:
@@ -427,7 +432,7 @@ with gr.Blocks(title="Cell Viability Counter with Trypan Blue Analysis", theme=g
427
  outputs=[cell_count_output2, overlay_output2, info_output2, viability_section2, masks_state, image_state]
428
  ).then( # Chain the initial viability assessment after segmentation
429
  fn=update_viability_realtime,
430
- inputs=[blue_threshold2, masks_state, image_state],
431
  outputs=[viability_overlay2, live_count_output2, dead_count_output2, viability_percent_output2, viability_info2]
432
  )
433
 
 
142
  final_overlay = np.clip(final_overlay, 0, 255).astype(np.uint8)
143
 
144
  return len(dead_cells), len(alive_cells), final_overlay
145
+
146
+ def measure_confluency(masks, image_np):
147
+ tot_pixels = image_np.shape[0] * image_np.shape[1]
148
+ cell_pixels = np.count_nonzero(masks)
149
+ confluency = cell_pixels / tot_pixels * 100
150
+ return confluency
151
+
152
 
153
  @spaces.GPU
154
  def run_segmentation_editor(editor_data, model_choice):
 
183
  masks, flows, styles = model.eval(processed_image_np, diameter=None, channels=[0, 0])
184
 
185
  cell_count = len(np.unique(masks)) - 1
 
186
  # Create a basic segmentation overlay (without viability)
187
  segmentation_overlay = processed_image_np.copy().astype(np.float32)
188
  if masks.max() > 0:
 
255
  # Run Cellpose
256
  masks, flows, styles = model.eval(processed_image_np, diameter=None, channels=[0, 0])
257
 
258
+ cell_count = len(np.unique(masks)) - 1
 
259
  # Create a basic segmentation overlay
260
  segmentation_overlay = processed_image_np.copy().astype(np.float32)
261
  if masks.max() > 0:
 
432
  outputs=[cell_count_output2, overlay_output2, info_output2, viability_section2, masks_state, image_state]
433
  ).then( # Chain the initial viability assessment after segmentation
434
  fn=update_viability_realtime,
435
+ inputs=[blue_threshold2, masks_state, image_state],
436
  outputs=[viability_overlay2, live_count_output2, dead_count_output2, viability_percent_output2, viability_info2]
437
  )
438