Spaces:
Runtime error
Runtime error
| # 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"] |