|
|
|
|
| FROM python:3.10-slim
|
|
|
| WORKDIR /app
|
|
|
|
|
| RUN apt-get update && apt-get install -y --no-install-recommends \
|
| gcc \
|
| git \
|
| curl \
|
| && rm -rf /var/lib/apt/lists/*
|
|
|
|
|
|
|
| RUN pip install --no-cache-dir \
|
| torch==2.2.2+cpu \
|
| --index-url https://download.pytorch.org/whl/cpu
|
|
|
|
|
| COPY server/requirements.txt .
|
| RUN pip install --no-cache-dir -r requirements.txt
|
|
|
|
|
| COPY . .
|
|
|
|
|
| RUN pip install --no-cache-dir -e .
|
|
|
|
|
| RUN mkdir -p /tmp/halluguard_cache /tmp/transformers_cache /tmp/hf_cache
|
|
|
|
|
| EXPOSE 7860
|
|
|
|
|
| HEALTHCHECK --interval=30s --timeout=15s --start-period=300s --retries=10 \
|
| CMD curl -f http://localhost:7860/health || exit 1
|
|
|
| ENV PYTHONUNBUFFERED=1
|
| ENV HF_HOME=/tmp/hf_cache
|
| ENV HF_HUB_CACHE=/tmp/hf_cache
|
|
|
|
|
|
|
|
|
|
|
|
|
| RUN python -c "\
|
| from sentence_transformers import SentenceTransformer, CrossEncoder; \
|
| print('Preloading all-MiniLM-L6-v2...'); \
|
| SentenceTransformer('all-MiniLM-L6-v2'); \
|
| print('Preloading nli-deberta-v3-small...'); \
|
| CrossEncoder('cross-encoder/nli-deberta-v3-small'); \
|
| print('Models cached successfully!'); \
|
| "
|
|
|
| # Preload BERTScore model (roberta-base)
|
| # Note: deberta-v3-base crashes with transformers>=4.57 due to tokenizer bug,
|
| # so we use roberta-base which is compatible with all transformers versions.
|
| RUN python -c "\
|
| from bert_score import BERTScorer; \
|
| print('Preloading roberta-base for BERTScore...'); \
|
| scorer = BERTScorer(model_type='roberta-base', lang='en', device='cpu'); \
|
| print('BERTScore model cached!'); \
|
| " 2>/dev/null || echo "BERTScore preload completed (some warnings are expected)"
|
|
|
| CMD ["uvicorn", "server.app:app", "--host", "0.0.0.0", "--port", "7860"] |