File size: 2,239 Bytes
ae4e18e 0f4c5ac 395ecbb 0f4c5ac 395ecbb 0f4c5ac 395ecbb 0f4c5ac ae4e18e d756fb7 ae4e18e 395ecbb ae4e18e 395ecbb ae4e18e 395ecbb ae4e18e 395ecbb ae4e18e 395ecbb 0f94f39 395ecbb b87b3a7 395ecbb 0f94f39 0f4c5ac ae4e18e 395ecbb 0f4c5ac |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 |
# Use official Python 3.12 image with slim variant
FROM python:3.12-slim as builder
# Set working directory
WORKDIR /app
# Install system dependencies
RUN apt-get update && apt-get install -y \
build-essential \
curl \
git \
&& rm -rf /var/lib/apt/lists/*
# Create model cache directory
RUN mkdir -p /tmp/huggingface && chmod -R 777 /tmp/huggingface
# Set environment variables for Hugging Face cache
ENV TRANSFORMERS_CACHE=/tmp/huggingface
ENV HF_HOME=/tmp/huggingface
# Copy only requirements first to leverage Docker cache
COPY requirements.txt .
# Install Python dependencies
RUN pip install --no-cache-dir -r requirements.txt
# Install spaCy model
RUN python -m spacy download en_core_web_sm
# Pre-download models and tokenizers (both deberta and distilbert)
RUN python -c "\
from transformers import AutoTokenizer, AutoModel; \
print('Downloading deepset/deberta-v3-base-squad2...'); \
AutoTokenizer.from_pretrained('deepset/deberta-v3-base-squad2'); \
AutoModel.from_pretrained('deepset/deberta-v3-base-squad2'); \
print('Downloading distilbert-base-uncased...'); \
AutoTokenizer.from_pretrained('distilbert-base-uncased'); \
AutoModel.from_pretrained('distilbert-base-uncased')"
# --- Runtime stage ---
FROM python:3.12-slim
WORKDIR /app
# Copy only necessary files from builder
COPY --from=builder /tmp/huggingface /tmp/huggingface
COPY --from=builder /usr/local/lib/python3.12/site-packages /usr/local/lib/python3.12/site-packages
COPY --from=builder /usr/local/bin /usr/local/bin
# Create required directories
RUN mkdir -p /tmp/uploads && chmod -R 777 /tmp/uploads /tmp/huggingface
# Set environment variables
ENV PYTHONUNBUFFERED=1
ENV UPLOAD_FOLDER=/tmp/uploads
ENV TRANSFORMERS_CACHE=/tmp/huggingface
ENV HF_HOME=/tmp/huggingface
# Streamlit config
RUN mkdir -p .streamlit && \
echo '[server]\n\
enableCORS=false\n\
enableXsrfProtection=false\n' > .streamlit/config.toml
# Copy application code
COPY . .
# Expose port
EXPOSE 7860
# Health check
HEALTHCHECK --interval=30s --timeout=30s --start-period=5s --retries=3 \
CMD curl -f http://localhost:7860/_stcore/health || exit 1
# Run the application
CMD ["streamlit", "run", "app.py", "--server.port=7860", "--server.address=0.0.0.0"] |