Commit
Β·
de7ca56
1
Parent(s):
2195b13
Fix model caching - use HF_HOME for all models to prevent re-download on restart
Browse files- Dockerfile +5 -5
- 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
|
| 39 |
-
|
| 40 |
-
|
| 41 |
-
|
| 42 |
-
|
| 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 |
-
|
|
|
|
|
|
|
|
|
|
| 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
|