# Build image for DocVerse FastAPI Backend on Hugging Face Spaces FROM python:3.10-slim # Set environment variables ENV PYTHONDONTWRITEBYTECODE=1 ENV PYTHONUNBUFFERED=1 # Install system dependencies (For EasyOCR & SciSpacy) RUN apt-get update && apt-get install -y \ build-essential \ libpq-dev \ gcc \ tesseract-ocr \ libtesseract-dev \ && rm -rf /var/lib/apt/lists/* # Hugging Face Spaces require running as a non-root user RUN useradd -m -u 1000 user USER user ENV PATH="/home/user/.local/bin:$PATH" # Set working directory WORKDIR /app # Install Python dependencies COPY --chown=user requirements.txt /app/ RUN pip install --upgrade pip RUN pip install --no-cache-dir -r requirements.txt # Download SciSpacy models (Example: en_core_sci_sm for biomedical lit) # RUN pip install https://s3-us-west-2.amazonaws.com/ai2-s2-scispacy/releases/v0.5.1/en_core_sci_sm-0.5.1.tar.gz # Copy application code with correct ownership COPY --chown=user ./app /app/app # Expose Hugging Face's required port EXPOSE 7860 # Start FastAPI application on port 7860 CMD ["uvicorn", "app.main:app", "--host", "0.0.0.0", "--port", "7860"]