Spaces:
Sleeping
Sleeping
| # Use official lightweight Python image | |
| FROM python:3.10-slim | |
| # Create a secure, non-root user (required by Hugging Face Spaces) | |
| RUN useradd -m -u 1000 user | |
| # Set up environment variables | |
| ENV HOME=/home/user \ | |
| PATH=/home/user/.local/bin:$PATH \ | |
| PYTHONUNBUFFERED=1 \ | |
| HF_HOME=/home/user/.cache/huggingface | |
| # Set working directory | |
| WORKDIR $HOME/app | |
| # Copy requirements | |
| COPY --chown=user requirements.txt . | |
| # Install dependencies using CPU-only extra index to prevent massive GPU CUDA installations | |
| RUN pip install --no-cache-dir --upgrade -r requirements.txt --extra-index-url https://download.pytorch.org/whl/cpu | |
| # Pre-cache the standard PyTorch DistilBERT model during the image build process | |
| # This guarantees instant startup times when the Space boots up. | |
| RUN python -c "from transformers import pipeline; pipeline('token-classification', model='samuelolubukun/pii-ner-finetuned-distilbert')" | |
| # Copy the rest of the application files | |
| COPY --chown=user . . | |
| # Switch to the non-root user | |
| USER user | |
| # Expose port 7860 | |
| EXPOSE 7860 | |
| # Start the application on port 7860 | |
| CMD ["uvicorn", "app:app", "--host", "0.0.0.0", "--port", "7860"] | |