Skip to content

Commit 4e8bf19

Browse files
committed
Seed XGBoost model cache from a bundled copy if present alongside the app
Lets a deployment (e.g. the HF Space) ship the model file directly and skip the runtime download from Zenodo entirely. No-op when no bundled file is present, so this doesn't change behavior for normal installs.
1 parent 35dd55f commit 4e8bf19

1 file changed

Lines changed: 14 additions & 0 deletions

File tree

scripts/protac_splitter_app.py

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@
1919

2020
import logging
2121
import os
22+
import shutil
2223
import tempfile
2324
from pathlib import Path
2425
from typing import Union
@@ -30,12 +31,25 @@
3031
from rdkit.Chem import Draw
3132

3233
from protac_splitter import split_protac
34+
from protac_splitter.config import get_cache_dir
3335
from protac_splitter.evaluation import split_prediction
3436

3537
# HF Spaces sets SPACE_ID automatically; cap parallelism on the (limited) free tier.
3638
IS_HF_SPACE = os.environ.get("SPACE_ID") is not None
3739
MAX_NUM_PROC = 2 if IS_HF_SPACE else 8
3840

41+
# Filename must match `_XGBOOST_MODEL_FILENAME` in protac_splitter/protac_splitter.py.
42+
# If a copy of the model is bundled alongside this script (as it is on the HF Space,
43+
# to avoid depending on a runtime download from Zenodo), seed the cache with it before
44+
# any request can trigger a download.
45+
_BUNDLED_XGBOOST_MODEL = Path(__file__).with_name("PROTAC-Splitter-XGBoost.joblib")
46+
if _BUNDLED_XGBOOST_MODEL.exists():
47+
_cached_model_path = get_cache_dir() / _BUNDLED_XGBOOST_MODEL.name
48+
if not _cached_model_path.exists():
49+
_cached_model_path.parent.mkdir(parents=True, exist_ok=True)
50+
shutil.copy(_BUNDLED_XGBOOST_MODEL, _cached_model_path)
51+
logging.info(f"Seeded XGBoost model cache from bundled file → {_cached_model_path}")
52+
3953
MODEL_CHOICES = [
4054
("Heuristic → XGBoost (recommended)", "heuristic->xgboost"),
4155
("XGBoost (fast)", "xgboost"),

0 commit comments

Comments
 (0)