File size: 1,275 Bytes
8de5584
 
 
 
 
 
 
 
5e48a6b
8de5584
 
 
 
 
 
 
 
 
 
5e48a6b
8de5584
 
 
 
5e48a6b
 
 
 
8de5584
 
 
 
 
 
5e48a6b
 
8de5584
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
# Use official Python 3.10 slim image
FROM python:3.10-slim

# Set environment variables
ENV PYTHONUNBUFFERED=1 \
    DEBIAN_FRONTEND=noninteractive \
    PORT=7860

# Install system dependencies (Tesseract OCR & Poppler for PDF-to-image)
RUN apt-get update && apt-get install -y --no-install-recommends \
    build-essential \
    tesseract-ocr \
    tesseract-ocr-eng \
    poppler-utils \
    libpq-dev \
    curl \
    git \
    && rm -rf /var/lib/apt/lists/*

# Create a non-root user (Required by Hugging Face Spaces: user 1000)
RUN useradd -m -u 1000 user
ENV HOME=/home/user \
    PATH=/home/user/.local/bin:$PATH

# Set working directory and grant full ownership to user 1000
WORKDIR /app
RUN mkdir -p /app/uploads && chown -R user:user /app

# Copy requirements and install dependencies
COPY requirements.txt .
RUN pip install --no-cache-dir --upgrade pip && \
    pip install --no-cache-dir torch --index-url https://download.pytorch.org/whl/cpu && \
    pip install --no-cache-dir -r requirements.txt

# Copy backend code with user ownership
COPY --chown=user:user . /app

# Switch to non-root user
USER user

# Expose Hugging Face default port
EXPOSE 7860

# Run FastAPI server on port 7860
CMD ["uvicorn", "app.main:app", "--host", "0.0.0.0", "--port", "7860"]