Spaces:
Sleeping
Sleeping
zerogpu hooks
Browse files
app.py
CHANGED
|
@@ -4,6 +4,7 @@ import numpy as np
|
|
| 4 |
import pandas as pd
|
| 5 |
from PIL import Image
|
| 6 |
import torch
|
|
|
|
| 7 |
|
| 8 |
from mussel.utils import get_features, segment_tissue
|
| 9 |
from mussel.models import ModelType
|
|
@@ -11,21 +12,11 @@ from aeon import run_aeon
|
|
| 11 |
from paladin import run_paladin
|
| 12 |
|
| 13 |
NUM_WORKERS = int(os.getenv("NUM_WORKERS", 2))
|
| 14 |
-
USE_GPU = torch.cuda.is_available()
|
| 15 |
|
| 16 |
-
|
| 17 |
-
|
| 18 |
-
|
| 19 |
-
|
| 20 |
-
segment_threshold=15,
|
| 21 |
-
median_blur_ksize=11,
|
| 22 |
-
morphology_ex_kernel=2,
|
| 23 |
-
tissue_area_threshold=2,
|
| 24 |
-
hole_area_threshold=1,
|
| 25 |
-
max_num_holes=2
|
| 26 |
-
)
|
| 27 |
-
|
| 28 |
-
features, _ = get_features(coords, slide_path, attrs, model_type=ModelType.OPTIMUS, use_gpu=USE_GPU, batch_size=64, num_workers=NUM_WORKERS)
|
| 29 |
|
| 30 |
# Step 3: Run Aeon to predict histology
|
| 31 |
aeon_results, _ = run_aeon(
|
|
@@ -33,8 +24,8 @@ def analyze_slide(slide_path, site_type):
|
|
| 33 |
model_path="data/aeon_model.pkl",
|
| 34 |
metastatic=(site_type == "Metastatic"),
|
| 35 |
batch_size=8,
|
| 36 |
-
num_workers=
|
| 37 |
-
use_cpu=not
|
| 38 |
)
|
| 39 |
|
| 40 |
# Step 4: Run Paladin to predict biomarkers
|
|
@@ -45,11 +36,27 @@ def analyze_slide(slide_path, site_type):
|
|
| 45 |
metastatic=(site_type == "Metastatic"),
|
| 46 |
batch_size=8,
|
| 47 |
num_workers=NUM_WORKERS,
|
| 48 |
-
use_cpu=not
|
| 49 |
)
|
| 50 |
|
| 51 |
return aeon_results, paladin_results
|
| 52 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 53 |
if __name__ == "__main__":
|
| 54 |
input_slide = gr.File(
|
| 55 |
label="Upload H&E Whole Slide Image",
|
|
|
|
| 4 |
import pandas as pd
|
| 5 |
from PIL import Image
|
| 6 |
import torch
|
| 7 |
+
import spaces
|
| 8 |
|
| 9 |
from mussel.utils import get_features, segment_tissue
|
| 10 |
from mussel.models import ModelType
|
|
|
|
| 12 |
from paladin import run_paladin
|
| 13 |
|
| 14 |
NUM_WORKERS = int(os.getenv("NUM_WORKERS", 2))
|
|
|
|
| 15 |
|
| 16 |
+
@spaces.GPU
|
| 17 |
+
def get_features_and_infer(coords, slide_path, attrs, site_type):
|
| 18 |
+
use_gpu = torch.cuda.is_available()
|
| 19 |
+
features, _ = get_features(coords, slide_path, attrs, model_type=ModelType.OPTIMUS, use_gpu=use_gpu, batch_size=64, num_workers=NUM_WORKERS)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 20 |
|
| 21 |
# Step 3: Run Aeon to predict histology
|
| 22 |
aeon_results, _ = run_aeon(
|
|
|
|
| 24 |
model_path="data/aeon_model.pkl",
|
| 25 |
metastatic=(site_type == "Metastatic"),
|
| 26 |
batch_size=8,
|
| 27 |
+
num_workers=NUM_WORKERS,
|
| 28 |
+
use_cpu=not use_gpu,
|
| 29 |
)
|
| 30 |
|
| 31 |
# Step 4: Run Paladin to predict biomarkers
|
|
|
|
| 36 |
metastatic=(site_type == "Metastatic"),
|
| 37 |
batch_size=8,
|
| 38 |
num_workers=NUM_WORKERS,
|
| 39 |
+
use_cpu=not use_gpu,
|
| 40 |
)
|
| 41 |
|
| 42 |
return aeon_results, paladin_results
|
| 43 |
|
| 44 |
+
|
| 45 |
+
def analyze_slide(slide_path, site_type):
|
| 46 |
+
_, _, coords, attrs = segment_tissue(
|
| 47 |
+
slide_path=slide_path,
|
| 48 |
+
patch_size=224,
|
| 49 |
+
segment_threshold=15,
|
| 50 |
+
median_blur_ksize=11,
|
| 51 |
+
morphology_ex_kernel=2,
|
| 52 |
+
tissue_area_threshold=2,
|
| 53 |
+
hole_area_threshold=1,
|
| 54 |
+
max_num_holes=2
|
| 55 |
+
)
|
| 56 |
+
aeon_results, paladin_results = get_features_and_infer(coords, slide_path, attrs, site_type)
|
| 57 |
+
return aeon_results, paladin_results
|
| 58 |
+
|
| 59 |
+
|
| 60 |
if __name__ == "__main__":
|
| 61 |
input_slide = gr.File(
|
| 62 |
label="Upload H&E Whole Slide Image",
|