FROM python:3.9-slim # Install system dependencies for OpenCV and Tesseract ENV REFRESHED_AT=2024-01-10_V1 RUN apt-get update && apt-get install -y \ tesseract-ocr \ libtesseract-dev \ libgl1 \ libglib2.0-0 \ && rm -rf /var/lib/apt/lists/* # Set working directory WORKDIR /app # Copy requirements first to leverage cache COPY requirements.txt . RUN pip install --no-cache-dir -r requirements.txt # Create a user to run the app (Hugging Face Spaces requirement for security) RUN useradd -m -u 1000 user USER user ENV HOME=/home/user \ PATH=/home/user/.local/bin:$PATH # Copy the rest of the application COPY --chown=user . . # Expose the port (Hugging Face Spaces expects 7860) EXPOSE 7860 # Command to run the application CMD ["uvicorn", "app:app", "--host", "0.0.0.0", "--port", "7860"]