Update app.py
Browse files
app.py
CHANGED
|
@@ -8,7 +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"
|
| 14 |
MODEL_OPTIONS = {
|
|
@@ -342,10 +342,10 @@ def run_segmentation_manual(image, model_choice, crop_coords):
|
|
| 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 |
-
|
| 347 |
-
|
| 348 |
-
|
| 349 |
if stored_masks is None or stored_image_np is None:
|
| 350 |
return None, 0, 0, 0.0, "Please run segmentation first."
|
| 351 |
|
|
@@ -389,8 +389,16 @@ if ('serviceWorker' in navigator) {
|
|
| 389 |
}
|
| 390 |
</script>
|
| 391 |
"""
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 392 |
|
| 393 |
-
#
|
| 394 |
with gr.Blocks(
|
| 395 |
title="CellposeCellCounter",
|
| 396 |
theme=gr.themes.Soft(),
|
|
@@ -403,6 +411,9 @@ with gr.Blocks(
|
|
| 403 |
masks_state = gr.State(value=None)
|
| 404 |
image_state = gr.State(value=None)
|
| 405 |
|
|
|
|
|
|
|
|
|
|
| 406 |
with gr.Tab("Image Editor (Draw Selection)"):
|
| 407 |
gr.Markdown("### Draw selection and run segmentation")
|
| 408 |
|
|
|
|
| 8 |
from PIL import Image
|
| 9 |
import io
|
| 10 |
from huggingface_hub import hf_hub_download
|
| 11 |
+
|
| 12 |
|
| 13 |
HF_REPO_ID = "myang4218/cellposemodel"
|
| 14 |
MODEL_OPTIONS = {
|
|
|
|
| 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)
|
| 348 |
+
|
| 349 |
if stored_masks is None or stored_image_np is None:
|
| 350 |
return None, 0, 0, 0.0, "Please run segmentation first."
|
| 351 |
|
|
|
|
| 389 |
}
|
| 390 |
</script>
|
| 391 |
"""
|
| 392 |
+
def pack_array(arr):
|
| 393 |
+
pil = Image.fromarray(arr.astype(np.uint8))
|
| 394 |
+
buf = io.BytesIO()
|
| 395 |
+
pil.save(buf, format="PNG")
|
| 396 |
+
return buf.getvalue()
|
| 397 |
+
|
| 398 |
+
def unpack_array(data):
|
| 399 |
+
return np.array(Image.open(io.BytesIO(data)))
|
| 400 |
|
| 401 |
+
# Gradio interface
|
| 402 |
with gr.Blocks(
|
| 403 |
title="CellposeCellCounter",
|
| 404 |
theme=gr.themes.Soft(),
|
|
|
|
| 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 |
+
|
| 417 |
with gr.Tab("Image Editor (Draw Selection)"):
|
| 418 |
gr.Markdown("### Draw selection and run segmentation")
|
| 419 |
|