Spaces:
Running
Running
| # Use a Python base image | |
| FROM python:3.11-slim | |
| # Install system dependencies (Tesseract, OpenCV support, Redis server, poppler for pdf2image) | |
| RUN apt-get update && apt-get install -y \ | |
| tesseract-ocr \ | |
| tesseract-ocr-amh \ | |
| libgl1 \ | |
| libglib2.0-0 \ | |
| libgomp1 \ | |
| redis-server \ | |
| poppler-utils \ | |
| && rm -rf /var/lib/apt/lists/* | |
| # Create a non-root user (Hugging Face Spaces runs containers 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 \ | |
| TRANSFORMERS_CACHE=/home/user/.cache/huggingface \ | |
| PADDLE_HOME=/home/user/.paddleocr \ | |
| REDIS_URL=redis://127.0.0.1:6379/0 | |
| WORKDIR $HOME/app | |
| # Copy requirements and install as the non-root user. | |
| # Install requirements.txt first (full deps), then requirements_paddle.txt (lower-bound paddle pins). | |
| COPY --chown=user requirements.txt requirements_paddle.txt ./ | |
| RUN pip install --no-cache-dir --user --upgrade pip && \ | |
| pip install --no-cache-dir --user -r requirements.txt && \ | |
| pip install --no-cache-dir --user -r requirements_paddle.txt | |
| # Copy the rest of the code | |
| COPY --chown=user . . | |
| EXPOSE 8000 | |
| # Start redis-server in the background (writes pid/log to /tmp so non-root user can write), | |
| # then launch uvicorn. HF Spaces sets $PORT to the app_port declared in README.md (8000). | |
| CMD ["sh", "-c", "redis-server --port 6379 --dir /tmp --pidfile /tmp/redis.pid --logfile /tmp/redis.log --daemonize yes && exec uvicorn app.main:app --host 0.0.0.0 --port ${PORT:-8000} --workers 1 --timeout-keep-alive 60"] | |