fariedalfarizi commited on
Commit
de7ca56
Β·
1 Parent(s): 2195b13

Fix model caching - use HF_HOME for all models to prevent re-download on restart

Browse files
Files changed (2) hide show
  1. Dockerfile +5 -5
  2. app/services/keywords.py +4 -1
Dockerfile CHANGED
@@ -35,11 +35,11 @@ RUN python -c "from transformers import AutoTokenizer, AutoModelForSequenceClass
35
  AutoModelForSequenceClassification.from_pretrained('Cyberlace/swara-structure-model', cache_dir='/.cache'); \
36
  print('βœ… Structure Model cached!')" && chmod -R 777 /.cache
37
 
38
- # 2. Whisper will be downloaded on first use (lazy loading to avoid OOM during build)
39
- # RUN python -c "import whisper; \
40
- # print('πŸ“₯ Downloading Whisper medium model...'); \
41
- # whisper.load_model('medium', download_root='/.cache'); \
42
- # print('βœ… Whisper medium cached!')"
43
 
44
  # 3. Download Sentence Transformer for Keywords (~420MB)
45
  RUN python -c "from sentence_transformers import SentenceTransformer; \
 
35
  AutoModelForSequenceClassification.from_pretrained('Cyberlace/swara-structure-model', cache_dir='/.cache'); \
36
  print('βœ… Structure Model cached!')" && chmod -R 777 /.cache
37
 
38
+ # 2. Download Whisper medium model (~1.5GB) - with memory optimization
39
+ RUN python -c "import whisper; \
40
+ print('πŸ“₯ Downloading Whisper medium model (1.5GB)...'); \
41
+ whisper.load_model('medium', download_root='/.cache'); \
42
+ print('βœ… Whisper medium cached!')" && chmod -R 777 /.cache
43
 
44
  # 3. Download Sentence Transformer for Keywords (~420MB)
45
  RUN python -c "from sentence_transformers import SentenceTransformer; \
app/services/keywords.py CHANGED
@@ -42,7 +42,10 @@ class KeywordService:
42
  if EMBEDDINGS_AVAILABLE:
43
  print(f"πŸ“¦ Loading BERT model: {model_name}...")
44
  device = get_device()
45
- self.model = SentenceTransformer(model_name, device=device)
 
 
 
46
  print("βœ… Model loaded!")
47
  else:
48
  self.model = None
 
42
  if EMBEDDINGS_AVAILABLE:
43
  print(f"πŸ“¦ Loading BERT model: {model_name}...")
44
  device = get_device()
45
+ # Use HF_HOME cache directory (set in Dockerfile)
46
+ import os
47
+ cache_dir = os.environ.get('HF_HOME', '/.cache')
48
+ self.model = SentenceTransformer(model_name, device=device, cache_folder=cache_dir)
49
  print("βœ… Model loaded!")
50
  else:
51
  self.model = None