Spaces:
Running
Running
| FROM python:3.10-slim | |
| ENV PYTHONDONTWRITEBYTECODE=1 \ | |
| PYTHONUNBUFFERED=1 \ | |
| PIP_NO_CACHE_DIR=1 \ | |
| FLAGS_use_mkldnn=0 \ | |
| OMP_NUM_THREADS=2 | |
| # Runtime libraries required by OpenCV, PaddlePaddle and Ultralytics. | |
| RUN apt-get update && apt-get install -y --no-install-recommends \ | |
| libgl1 \ | |
| libglib2.0-0 \ | |
| libgomp1 \ | |
| libsm6 \ | |
| libxext6 \ | |
| libxrender1 \ | |
| && rm -rf /var/lib/apt/lists/* | |
| # Hugging Face Docker Spaces commonly run the application as UID 1000. | |
| RUN useradd -m -u 1000 user | |
| USER user | |
| ENV HOME=/home/user \ | |
| PATH=/home/user/.local/bin:$PATH \ | |
| HF_HOME=/home/user/.cache/huggingface \ | |
| YOLO_CONFIG_DIR=/home/user/.config/Ultralytics | |
| WORKDIR /home/user/app | |
| COPY --chown=user:user requirements.txt ./requirements.txt | |
| # Install CPU-only PyTorch first, then the API/OCR dependencies. | |
| RUN python -m pip install --user --upgrade pip setuptools wheel && \ | |
| python -m pip install --user \ | |
| torch==2.6.0 torchvision==0.21.0 \ | |
| --index-url https://download.pytorch.org/whl/cpu && \ | |
| python -m pip install --user -r requirements.txt | |
| COPY --chown=user:user main.py ./main.py | |
| # Download and cache YOLO, PAN detector and PaddleOCR models at build time. | |
| RUN python -c "from main import PanKycEngine; PanKycEngine().load_models(); print('Models cached successfully')" | |
| EXPOSE 7860 | |
| # One worker avoids loading a separate copy of every model into memory. | |
| CMD ["uvicorn", "main:app", "--host", "0.0.0.0", "--port", "7860", "--workers", "1", "--timeout-keep-alive", "120"] |