raylim commited on
Commit
b4fa8fa
Β·
1 Parent(s): 25f77c6

add aeon/paladin

Browse files
Files changed (2) hide show
  1. app.py +65 -11
  2. requirements.txt +1 -0
app.py CHANGED
@@ -1,3 +1,4 @@
 
1
  import gradio as gr
2
  import numpy as np
3
  import pandas as pd
@@ -5,8 +6,12 @@ from PIL import Image
5
 
6
  from mussel.utils import get_features, segment_tissue
7
  from mussel.models import ModelType
 
8
 
9
- def analyze_slide(slide_path, model_name="RESNET50"):
 
 
 
10
  _, _, coords, attrs = segment_tissue(
11
  slide_path=slide_path,
12
  patch_size=224,
@@ -18,25 +23,74 @@ def analyze_slide(slide_path, model_name="RESNET50"):
18
  max_num_holes=2
19
  )
20
 
21
- df_coords = pd.DataFrame(coords, columns=['x', 'y'])
22
- features, labels = get_features(coords, slide_path, attrs, model_type=ModelType.RESNET50, use_gpu=False)
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
23
 
24
- return df_coords
25
 
26
  with gr.Blocks() as demo:
27
- gr.Markdown("# Whole Slide Image Featurization & Inference")
28
  with gr.Row():
29
  with gr.Column():
30
- input_slide = gr.File(label="Upload Whole Slide Image (.svs, .tiff)")
31
- model_name = gr.Dropdown(choices=["RESNET50", "CTRANSPATH", "VIRCHOW", "VIRCHOW2", "OPTIMUS", "CLIP", "CONCH1_5"], label="Select Model", value="RESNET50")
32
- run_button = gr.Button("Analyze Slide")
 
 
 
 
 
 
 
33
  with gr.Column():
34
- coords_output = gr.Dataframe(headers=["X", "Y"], label="Extracted Patch Coordinates")
 
 
 
 
 
 
 
 
 
 
35
 
36
  run_button.click(
37
  analyze_slide,
38
- inputs=[input_slide, model_name],
39
- outputs=coords_output
 
40
  )
41
 
42
  if __name__ == "__main__":
 
1
+ import os
2
  import gradio as gr
3
  import numpy as np
4
  import pandas as pd
 
6
 
7
  from mussel.utils import get_features, segment_tissue
8
  from mussel.models import ModelType
9
+ from mosaic_ui.inference import run_aeon, run_paladin
10
 
11
+ NUM_WORKERS = int(os.getenv("NUM_WORKERS", 2))
12
+ USE_GPU = torch.cuda.is_available()
13
+
14
+ def analyze_slide(slide_path, site_type):
15
  _, _, coords, attrs = segment_tissue(
16
  slide_path=slide_path,
17
  patch_size=224,
 
23
  max_num_holes=2
24
  )
25
 
26
+ # features, _ = get_features(coords, slide_path, attrs, model_type=ModelType.OPTIMUS, use_gpu=USE_GPU, batch_size=64, num_workers=NUM_WORKERS)
27
+ #
28
+ # # Step 3: Run Aeon to predict histology
29
+ # aeon_results, _ = run_aeon(
30
+ # β”‚ features=features,
31
+ # β”‚ model_path="data/aeon_model.pkl",
32
+ # β”‚ metastatic=(site_type == "Metastatic"),
33
+ # β”‚ batch_size=8,
34
+ # β”‚ num_workers=NM_WORKERS,
35
+ # β”‚ use_cpu=not USE_GPU,
36
+ # )
37
+ #
38
+ # # Step 4: Run Paladin to predict biomarkers
39
+ # paladin_results = run_paladin(
40
+ # β”‚ features=features,
41
+ # β”‚ model_map_path="data/paladin_model_map.csv",
42
+ # β”‚ aeon_results=aeon_results,
43
+ # β”‚ metastatic=(site_type == "Metastatic"),
44
+ # β”‚ batch_size=8,
45
+ # β”‚ num_workers=NUM_WORKERS,
46
+ # β”‚ use_cpu=not USE_GPU,
47
+ # )
48
+ # Dummy results for demonstration purposes
49
+ # Replace these with actual model inference results
50
+ aeon_results = pd.DataFrame({
51
+ "Cancer Subtype": ["Subtype A", "Subtype B"],
52
+ "Confidence": [0.95, 0.85]
53
+ })
54
+ paladin_results = pd.DataFrame({
55
+ "Cancer Subtype": ["Subtype A", "Subtype A"],
56
+ "Biomarker": ["Biomarker 1", "Biomarker 2"],
57
+ "Score": [0.9, 0.8]
58
+ })
59
 
60
+ return aeon_results, paladin_results
61
 
62
  with gr.Blocks() as demo:
63
+ gr.Markdown("# Mosaic: H&E Whole Slide Image Cancer Subtype and Biomarker Inference")
64
  with gr.Row():
65
  with gr.Column():
66
+ input_image = gr.File(
67
+ label="Upload H&E Whole Slide Image",
68
+ file_types=[".svs", ".tiff", ".tif"],
69
+ )
70
+ input_dropdown = gr.Dropdown(
71
+ choices=["Primary", "Metastatic"],
72
+ label="Site Type",
73
+ value="Primary",
74
+ )
75
+ run_button = gr.Button("Run Inference")
76
  with gr.Column():
77
+ aeon_output_table = gr.Dataframe(
78
+ headers=["Cancer Subtype", "Confidence"],
79
+ label="Cancer Subtype Inference",
80
+ datatype=["str", "number"],
81
+ )
82
+ paladin_output_table = gr.Dataframe(
83
+ headers=["Cancer Subtype", "Biomarker", "Score"],
84
+ label="Biomarker Inference",
85
+ datatype=["str", "str", "number"],
86
+ )
87
+
88
 
89
  run_button.click(
90
  analyze_slide,
91
+ inputs=[input_slide, input_dropdown],
92
+ outputs=[aeon_output_table, paladin_output_table],
93
+
94
  )
95
 
96
  if __name__ == "__main__":
requirements.txt CHANGED
@@ -16,3 +16,4 @@ scikit-learn
16
  transpath@git+https://github.com/msk-mind/TransPath/
17
  timm_ctranspath@git+https://github.com/msk-mind/timm-ctranspath
18
  open-clip-torch
 
 
16
  transpath@git+https://github.com/msk-mind/TransPath/
17
  timm_ctranspath@git+https://github.com/msk-mind/timm-ctranspath
18
  open-clip-torch
19
+ git+https://{GH_TOKEN}@github.com/pathology-data-mining/paladin_webapp.git@dev