# Use Python 3.11 to support Pandas 3.x and newer libraries FROM python:3.11-slim # Set the working directory in the container WORKDIR /app # Install system dependencies # libgl1 and libglib2.0-0 are often needed for CV/PDF libraries RUN apt-get update && apt-get install -y --no-install-recommends \ git \ libgl1 \ libglib2.0-0 \ build-essential \ && rm -rf /var/lib/apt/lists/* # Copy the requirements file COPY requirements.txt requirements.txt # Install Python packages with timeout increase RUN pip install --no-cache-dir --timeout=1000 -r requirements.txt # Copy application code COPY . /app # Create a non-root user (Security Best Practice) RUN useradd -m -u 1000 user # Change ownership of the app directory and the temp directories RUN chown -R user:user /app # Create temp directories for HuggingFace/Torch cache and set permissions RUN mkdir -p /tmp/transformers_cache /tmp/hf_home /tmp/torch_home && \ chown -R user:user /tmp/transformers_cache /tmp/hf_home /tmp/torch_home # Switch to the non-root user USER user # Expose the port (Standard for HF Spaces) EXPOSE 7861 # Set environment variables ENV FLASK_HOST=0.0.0.0 ENV FLASK_PORT=7861 ENV FLASK_DEBUG=False # CRITICAL: Set HF-specific env vars to writable directories ENV TRANSFORMERS_CACHE=/tmp/transformers_cache ENV HF_HOME=/tmp/hf_home ENV TORCH_HOME=/tmp/torch_home # Command to run the app CMD ["python", "app.py"]