LiangLabUMB commited on
Commit
3a3ecf8
·
verified ·
1 Parent(s): 241ad25

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +5 -5
app.py CHANGED
@@ -8,6 +8,7 @@ import tempfile
8
  from PIL import Image
9
  import io
10
  from huggingface_hub import hf_hub_download
 
11
 
12
 
13
  HF_REPO_ID = "myang4218/cellposemodel"
@@ -251,7 +252,7 @@ def run_segmentation_editor(editor_data, model_choice):
251
  info_msg += f"Now adjust the Blue Threshold for viability assessment."
252
 
253
  # Return initial segmentation display and state variables
254
- return cell_count, Image.fromarray(segmentation_overlay), info_msg, gr.update(visible=True), masks, processed_image_np, confluency
255
 
256
  except Exception as e:
257
  return 0, None, f"Error during segmentation: {str(e)}", gr.update(visible=False), None, None, 0.0
@@ -336,12 +337,14 @@ def run_segmentation_manual(image, model_choice, crop_coords):
336
  info_msg += f"Processed with coordinates: {crop_coords}\n"
337
  info_msg += f"Now adjust the Blue Threshold for viability assessment."
338
 
339
- return cell_count, Image.fromarray(segmentation_overlay), info_msg, gr.update(visible=True), masks, processed_image_np, confluency
340
 
341
  except Exception as e:
342
  return 0, None, f"Error during segmentation: {str(e)}", gr.update(visible=False), None, None, 0.0
343
 
344
  def update_viability_realtime(blue_threshold, stored_masks, stored_image_np):
 
 
345
 
346
  stored_masks = unpack_array(stored_masks)
347
  stored_image_np = unpack_array(stored_image_np)
@@ -408,9 +411,6 @@ with gr.Blocks(
408
  gr.Markdown("For accurate cell confluency, crop the image to display only desired area.")
409
 
410
  # Define State components to store masks and image data across function calls
411
- masks_state = gr.State(value=None)
412
- image_state = gr.State(value=None)
413
-
414
  masks_state = pack_array(masks)
415
  image_state = pack_array(processed_image_np)
416
 
 
8
  from PIL import Image
9
  import io
10
  from huggingface_hub import hf_hub_download
11
+ import base64
12
 
13
 
14
  HF_REPO_ID = "myang4218/cellposemodel"
 
252
  info_msg += f"Now adjust the Blue Threshold for viability assessment."
253
 
254
  # Return initial segmentation display and state variables
255
+ return cell_count, Image.fromarray(segmentation_overlay), info_msg, gr.update(visible=True), pack_array(masks), pack_array(processed_image_np), confluency
256
 
257
  except Exception as e:
258
  return 0, None, f"Error during segmentation: {str(e)}", gr.update(visible=False), None, None, 0.0
 
337
  info_msg += f"Processed with coordinates: {crop_coords}\n"
338
  info_msg += f"Now adjust the Blue Threshold for viability assessment."
339
 
340
+ return cell_count, Image.fromarray(segmentation_overlay), info_msg, gr.update(visible=True), pack_array(masks), pack_array(processed_image_np), confluency
341
 
342
  except Exception as e:
343
  return 0, None, f"Error during segmentation: {str(e)}", gr.update(visible=False), None, None, 0.0
344
 
345
  def update_viability_realtime(blue_threshold, stored_masks, stored_image_np):
346
+ if stored_masks is None or stored_image_np is None:
347
+ return None, 0, 0, 0.0, "Please run segmentation first."
348
 
349
  stored_masks = unpack_array(stored_masks)
350
  stored_image_np = unpack_array(stored_image_np)
 
411
  gr.Markdown("For accurate cell confluency, crop the image to display only desired area.")
412
 
413
  # Define State components to store masks and image data across function calls
 
 
 
414
  masks_state = pack_array(masks)
415
  image_state = pack_array(processed_image_np)
416