copilot-swe-agent[bot] raylim commited on
Commit
2a074d9
·
1 Parent(s): 7156083

Add Hugging Face Spaces Zero GPU support

Browse files

Co-authored-by: raylim <3074310+raylim@users.noreply.github.com>

Files changed (6) hide show
  1. .gitignore +2 -0
  2. README.md +12 -0
  3. app.py +20 -0
  4. pyproject.toml +1 -0
  5. requirements.txt +16 -0
  6. src/mosaic/analysis.py +12 -0
.gitignore CHANGED
@@ -15,3 +15,5 @@ data/
15
  .pytest_cache/
16
  .coverage
17
  htmlcov/
 
 
 
15
  .pytest_cache/
16
  .coverage
17
  htmlcov/
18
+ flagged/
19
+ gradio_cached_examples/
README.md CHANGED
@@ -1,3 +1,15 @@
 
 
 
 
 
 
 
 
 
 
 
 
1
  # Mosaic: H&E Whole Slide Image Cancer Subtype and Biomarker Inference
2
 
3
  Mosaic is a deep learning model designed for predicting cancer subtypes and biomarkers from Hematoxylin and Eosin (H&E) stained whole slide images (WSIs). This repository provides the code, pre-trained models, and instructions to use Mosaic for your own datasets.
 
1
+ ---
2
+ title: Mosaic
3
+ emoji: 🧬
4
+ colorFrom: blue
5
+ colorTo: purple
6
+ sdk: gradio
7
+ sdk_version: 5.49.0
8
+ app_file: app.py
9
+ pinned: false
10
+ license: apache-2.0
11
+ ---
12
+
13
  # Mosaic: H&E Whole Slide Image Cancer Subtype and Biomarker Inference
14
 
15
  Mosaic is a deep learning model designed for predicting cancer subtypes and biomarkers from Hematoxylin and Eosin (H&E) stained whole slide images (WSIs). This repository provides the code, pre-trained models, and instructions to use Mosaic for your own datasets.
app.py ADDED
@@ -0,0 +1,20 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ """Entry point for Hugging Face Spaces deployment.
2
+
3
+ This module serves as the main entry point when deploying Mosaic to
4
+ Hugging Face Spaces. It initializes the models and launches the Gradio interface.
5
+ """
6
+
7
+ from mosaic.gradio_app import download_and_process_models, main
8
+ from mosaic.ui import launch_gradio
9
+
10
+ if __name__ == "__main__":
11
+ # Download models and initialize cancer subtype mappings
12
+ download_and_process_models()
13
+
14
+ # Launch the Gradio interface
15
+ # Use default settings suitable for Hugging Face Spaces
16
+ launch_gradio(
17
+ server_name="0.0.0.0",
18
+ server_port=7860,
19
+ share=False,
20
+ )
pyproject.toml CHANGED
@@ -14,6 +14,7 @@ dependencies = [
14
  "memory-profiler>=0.61.0",
15
  "mussel[torch-gpu]",
16
  "paladin",
 
17
  ]
18
 
19
  [project.scripts]
 
14
  "memory-profiler>=0.61.0",
15
  "mussel[torch-gpu]",
16
  "paladin",
17
+ "spaces>=0.30.0",
18
  ]
19
 
20
  [project.scripts]
requirements.txt ADDED
@@ -0,0 +1,16 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ gradio>=5.49.0
2
+ loguru>=0.7.3
3
+ memory-profiler>=0.61.0
4
+ spaces>=0.30.0
5
+ torch>=2.0.0
6
+ torchvision>=0.15.0
7
+ pandas>=2.0.0
8
+ numpy>=1.24.0
9
+ pillow>=10.0.0
10
+ opencv-python-headless>=4.8.0
11
+ scikit-learn>=1.3.0
12
+ requests>=2.31.0
13
+ huggingface-hub>=0.20.0
14
+ openslide-python>=1.3.0
15
+ git+https://github.com/pathology-data-mining/Mussel.git@ray-dev
16
+ git+https://github.com/pathology-data-mining/paladin.git@dev
src/mosaic/analysis.py CHANGED
@@ -15,9 +15,21 @@ from mussel.utils.segment import draw_slide_mask
15
  from mussel.cli.tessellate import BiopsySegConfig, ResectionSegConfig, TcgaSegConfig
16
  from loguru import logger
17
 
 
 
 
 
 
 
 
 
 
 
 
18
  from mosaic.inference import run_aeon, run_paladin
19
 
20
 
 
21
  def analyze_slide(
22
  slide_path,
23
  seg_config,
 
15
  from mussel.cli.tessellate import BiopsySegConfig, ResectionSegConfig, TcgaSegConfig
16
  from loguru import logger
17
 
18
+ try:
19
+ import spaces
20
+ HAS_SPACES = True
21
+ except ImportError:
22
+ HAS_SPACES = False
23
+ # Create a no-op decorator if spaces is not available
24
+ class spaces:
25
+ @staticmethod
26
+ def GPU(fn):
27
+ return fn
28
+
29
  from mosaic.inference import run_aeon, run_paladin
30
 
31
 
32
+ @spaces.GPU
33
  def analyze_slide(
34
  slide_path,
35
  seg_config,