Akshay4506 commited on
Commit
6135d1e
Β·
1 Parent(s): 8193db9

fix: pre-download SAP model weights and unify HF login

Browse files
Files changed (3) hide show
  1. Dockerfile +4 -0
  2. webapp/benchmark.py +0 -2
  3. webapp/main.py +10 -1
Dockerfile CHANGED
@@ -37,6 +37,10 @@ RUN pip install --no-cache-dir -r webapp/requirements.txt
37
  # Install SAP-RPT-1 OSS directly from GitHub (needed for the real model)
38
  RUN pip install --no-cache-dir git+https://github.com/SAP-samples/sap-rpt-1-oss.git
39
 
 
 
 
 
40
  # Expose port 7860 (Hugging Face Spaces default port)
41
  EXPOSE 7860
42
 
 
37
  # Install SAP-RPT-1 OSS directly from GitHub (needed for the real model)
38
  RUN pip install --no-cache-dir git+https://github.com/SAP-samples/sap-rpt-1-oss.git
39
 
40
+ # Pre-download Sentence Transformers weights to avoid runtime hangs
41
+ # This specific model is used by the SAP RPT-1 OSS model.
42
+ RUN python -c "from sentence_transformers import SentenceTransformer; SentenceTransformer('all-MiniLM-L6-v2')"
43
+
44
  # Expose port 7860 (Hugging Face Spaces default port)
45
  EXPOSE 7860
46
 
webapp/benchmark.py CHANGED
@@ -88,8 +88,6 @@ class _SAPModel:
88
  self._model = _SAPModel._shared_model._model
89
  self._real = True
90
  else:
91
- from huggingface_hub import login
92
- login(token=HF_TOKEN, add_to_git_credential=False)
93
  from sap_rpt_oss import SAP_RPT_OSS_Classifier, SAP_RPT_OSS_Regressor
94
  if task == "classification":
95
  self._model = SAP_RPT_OSS_Classifier(max_context_size=2048, bagging=1)
 
88
  self._model = _SAPModel._shared_model._model
89
  self._real = True
90
  else:
 
 
91
  from sap_rpt_oss import SAP_RPT_OSS_Classifier, SAP_RPT_OSS_Regressor
92
  if task == "classification":
93
  self._model = SAP_RPT_OSS_Classifier(max_context_size=2048, bagging=1)
webapp/main.py CHANGED
@@ -21,8 +21,17 @@ BASE_DIR = Path(__file__).resolve().parent.parent
21
  load_dotenv(BASE_DIR / "webapp" / ".env")
22
 
23
  # Verify Secrets on startup
 
24
  logger.info(f"TABPFN_TOKEN status: {'SET' if os.environ.get('TABPFN_TOKEN') else 'MISSING'}")
25
- logger.info(f"HF_TOKEN status: {'SET' if os.environ.get('HUGGING_FACE_HUB_TOKEN') else 'MISSING'}")
 
 
 
 
 
 
 
 
26
 
27
  # ── Config ─────────────────────────────────────────────────────────────────────
28
  MAX_FILE_BYTES = int(os.getenv("MAX_FILE_SIZE_MB", "5")) * 1024 * 1024
 
21
  load_dotenv(BASE_DIR / "webapp" / ".env")
22
 
23
  # Verify Secrets on startup
24
+ hf_token = os.environ.get('HUGGING_FACE_HUB_TOKEN')
25
  logger.info(f"TABPFN_TOKEN status: {'SET' if os.environ.get('TABPFN_TOKEN') else 'MISSING'}")
26
+ logger.info(f"HF_TOKEN status: {'SET' if hf_token else 'MISSING'}")
27
+
28
+ if hf_token:
29
+ try:
30
+ from huggingface_hub import login
31
+ login(token=hf_token, add_to_git_credential=False)
32
+ logger.info("Successfully logged into Hugging Face Hub.")
33
+ except Exception as e:
34
+ logger.warning(f"Hugging Face login failed: {e}")
35
 
36
  # ── Config ─────────────────────────────────────────────────────────────────────
37
  MAX_FILE_BYTES = int(os.getenv("MAX_FILE_SIZE_MB", "5")) * 1024 * 1024