Spaces:
Running
Running
| # Use an official Python runtime as a parent image | |
| FROM python:3.10-slim | |
| # Install necessary system dependencies for OpenCV/EasyOCR (e.g. libgl) | |
| RUN apt-get update && apt-get install -y --no-install-recommends \ | |
| libglib2.0-0 \ | |
| libgl1 \ | |
| && rm -rf /var/lib/apt/lists/* | |
| # Hugging Face Spaces requires port 7860 | |
| EXPOSE 7860 | |
| # Create a non-root user with UID 1000 (required by HF Spaces) | |
| RUN useradd -m -u 1000 user | |
| WORKDIR /home/user/app | |
| # Copy the requirements file and install dependencies | |
| # Note: Use --extra-index-url for CPU-only torch to save space in the image | |
| COPY --chown=user requirements.txt . | |
| RUN pip install --no-cache-dir -r requirements.txt | |
| # Copy the application code (routers, dependencies, core services) | |
| COPY --chown=user dependencies.py . | |
| COPY --chown=user searchworks.py . | |
| COPY --chown=user ocr_service.py . | |
| COPY --chown=user routers/ ./routers/ | |
| # Switch to the non-root user first so caches go to /home/user | |
| USER user | |
| # Pre-download the EasyOCR model weights at build time | |
| # English ('en') is required for our identity and address verification. | |
| RUN python -c "import easyocr; reader = easyocr.Reader(['en'], gpu=False); print('--- [BUILD] EasyOCR Model Cached ---')" | |
| # Command to run the application on the port required by HF Spaces | |
| CMD ["uvicorn", "ocr_service:app", "--host", "0.0.0.0", "--port", "7860"] | |