Spaces:
Sleeping
Sleeping
# Start from Python 3.9 image | |
FROM python:3.9 | |
# Switch to root to install system dependencies | |
USER root | |
# Set non-interactive mode | |
ENV DEBIAN_FRONTEND=noninteractive | |
# Fix permission issues by using --allow-releaseinfo-change | |
RUN apt-get update --allow-releaseinfo-change && \ | |
apt-get install -y --no-install-recommends \ | |
tesseract-ocr \ | |
libtesseract-dev \ | |
poppler-utils \ | |
wget && \ | |
rm -rf /var/lib/apt/lists/* # Clean up | |
# Ensure the tessdata directory exists | |
RUN mkdir -p /usr/share/tesseract-ocr/4.00/tessdata | |
# Download English trained data manually | |
RUN wget -O /usr/share/tesseract-ocr/4.00/tessdata/eng.traineddata \ | |
https://github.com/tesseract-ocr/tessdata_best/raw/main/eng.traineddata | |
# Add a non-root user | |
RUN useradd -m -u 1000 user | |
# Switch to the new user | |
USER user | |
ENV PATH="/home/user/.local/bin:$PATH" | |
# Set Tesseract OCR path | |
ENV TESSDATA_PREFIX="/usr/share/tesseract-ocr/4.00/tessdata" | |
# Set working directory | |
WORKDIR /app | |
# Copy requirements and install Python packages | |
COPY --chown=user ./requirements.txt requirements.txt | |
RUN pip install --no-cache-dir --upgrade -r requirements.txt | |
# Copy application files | |
COPY --chown=user . . | |
CMD ["uvicorn", "app:app", "--host", "0.0.0.0", "--port", "7860"] |