Spaces:
Runtime error
Runtime error
Commit ·
67e6481
1
Parent(s): 4d2a44f
Fix: Set HF_HOME explicitly and add cache cleanup for model download permissions
Browse files- Dockerfile +22 -14
Dockerfile
CHANGED
|
@@ -1,14 +1,23 @@
|
|
| 1 |
# Dockerfile
|
| 2 |
|
| 3 |
-
# Use a base image with Python installed. Python 3.10
|
| 4 |
-
# We choose a Debian-based image for compatibility with apt_packages.
|
| 5 |
FROM python:3.10-slim-buster
|
| 6 |
|
|
|
|
|
|
|
|
|
|
|
|
|
| 7 |
# Set the working directory inside the container
|
| 8 |
WORKDIR /app
|
| 9 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 10 |
# Install system dependencies needed for pdf2image (Poppler) and pytesseract (Tesseract)
|
| 11 |
-
# These correspond to the apt_packages listed in your requirements.txt comments.
|
| 12 |
RUN apt-get update && apt-get install -y \
|
| 13 |
libpoppler-dev \
|
| 14 |
tesseract-ocr \
|
|
@@ -16,26 +25,25 @@ RUN apt-get update && apt-get install -y \
|
|
| 16 |
tesseract-ocr-tur \
|
| 17 |
tesseract-ocr-fra \
|
| 18 |
tesseract-ocr-ara \
|
| 19 |
-
# Add other languages if needed, e.g., tesseract-ocr-
|
| 20 |
-
# If you remove apt_packages from requirements.txt, ensure these are here.
|
| 21 |
&& rm -rf /var/lib/apt/lists/*
|
| 22 |
|
| 23 |
# Copy requirements.txt and install Python dependencies
|
| 24 |
-
COPY requirements.txt .
|
| 25 |
RUN pip install --no-cache-dir -r requirements.txt
|
| 26 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 27 |
# Copy the rest of your application code
|
| 28 |
-
|
| 29 |
-
COPY . .
|
| 30 |
|
| 31 |
-
# Set
|
| 32 |
-
# This might be needed if Tesseract's executable isn't directly on PATH inside the container.
|
| 33 |
-
# Tesseract is often installed to /usr/bin/tesseract or similar in Linux containers.
|
| 34 |
-
# It's good practice to explicitly tell pytesseract where to find it.
|
| 35 |
ENV TESSDATA_PREFIX=/usr/share/tesseract-ocr/4.00/tessdata
|
| 36 |
ENV TESSERACT_CMD=/usr/bin/tesseract
|
|
|
|
| 37 |
|
| 38 |
# Command to run your FastAPI application using Uvicorn
|
| 39 |
-
# 0.0.0.0 makes it accessible from outside the container
|
| 40 |
-
# 7860 is the default port Hugging Face Spaces expects for web applications
|
| 41 |
CMD ["uvicorn", "app:app", "--host", "0.0.0.0", "--port", "7860"]
|
|
|
|
| 1 |
# Dockerfile
|
| 2 |
|
| 3 |
+
# Use a base image with Python installed. Python 3.10 is fine.
|
|
|
|
| 4 |
FROM python:3.10-slim-buster
|
| 5 |
|
| 6 |
+
# Create the user and set it for subsequent commands
|
| 7 |
+
RUN useradd -m -u 1000 user
|
| 8 |
+
USER user
|
| 9 |
+
|
| 10 |
# Set the working directory inside the container
|
| 11 |
WORKDIR /app
|
| 12 |
|
| 13 |
+
# Set the Hugging Face cache directory to a path where the 'user' has write permissions.
|
| 14 |
+
# This prevents permission issues with /root/.cache and similar system paths.
|
| 15 |
+
ENV HF_HOME=/app/huggingface_cache
|
| 16 |
+
|
| 17 |
+
# Create the cache directory and ensure the 'user' owns it
|
| 18 |
+
RUN mkdir -p $HF_HOME && chown user:user $HF_HOME
|
| 19 |
+
|
| 20 |
# Install system dependencies needed for pdf2image (Poppler) and pytesseract (Tesseract)
|
|
|
|
| 21 |
RUN apt-get update && apt-get install -y \
|
| 22 |
libpoppler-dev \
|
| 23 |
tesseract-ocr \
|
|
|
|
| 25 |
tesseract-ocr-tur \
|
| 26 |
tesseract-ocr-fra \
|
| 27 |
tesseract-ocr-ara \
|
| 28 |
+
# Add other languages if needed, e.g., tesseract-ocr-ara tesseract-ocr-fra
|
|
|
|
| 29 |
&& rm -rf /var/lib/apt/lists/*
|
| 30 |
|
| 31 |
# Copy requirements.txt and install Python dependencies
|
| 32 |
+
COPY --chown=user:user requirements.txt .
|
| 33 |
RUN pip install --no-cache-dir -r requirements.txt
|
| 34 |
|
| 35 |
+
# Clean up any old Hugging Face Hub lock files before copying the application code.
|
| 36 |
+
# This helps prevent PermissionErrors if a previous download attempt was interrupted.
|
| 37 |
+
RUN rm -rf "${HF_HOME}/hub/tmp"
|
| 38 |
+
RUN find "${HF_HOME}/hub/models--" -name "*.lock" -type f -delete || true
|
| 39 |
+
|
| 40 |
# Copy the rest of your application code
|
| 41 |
+
COPY --chown=user:user . /app
|
|
|
|
| 42 |
|
| 43 |
+
# Set environment variables for Tesseract and potentially for Python's sqlite3 module
|
|
|
|
|
|
|
|
|
|
| 44 |
ENV TESSDATA_PREFIX=/usr/share/tesseract-ocr/4.00/tessdata
|
| 45 |
ENV TESSERACT_CMD=/usr/bin/tesseract
|
| 46 |
+
ENV PYTHON_IS_PYTESSERACT_ONLY=true
|
| 47 |
|
| 48 |
# Command to run your FastAPI application using Uvicorn
|
|
|
|
|
|
|
| 49 |
CMD ["uvicorn", "app:app", "--host", "0.0.0.0", "--port", "7860"]
|