File size: 1,112 Bytes
1bb466c
 
 
03442f1
 
1bb466c
03442f1
1bb466c
 
 
 
 
03442f1
 
 
 
 
 
 
 
 
 
1bb466c
 
03442f1
 
 
1bb466c
03442f1
1bb466c
 
03442f1
1bb466c
 
03442f1
1bb466c
 
 
 
 
 
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
# Stage 1: Build React Frontend
FROM node:18-alpine AS frontend-builder
WORKDIR /app
COPY frontend/package.json ./
COPY frontend/package-lock.json ./
RUN npm install --legacy-peer-deps
COPY frontend/ ./
RUN npm run build

# Stage 2: Setup Python Backend
FROM python:3.10-slim

# Setup user 1000 for Hugging Face Spaces compatibility
RUN useradd -m -u 1000 user
USER user
ENV HOME=/home/user \
    PATH=/home/user/.local/bin:$PATH

WORKDIR $HOME/app

# Switch back to root to install system dependencies
USER root
RUN apt-get update && apt-get install -y tesseract-ocr && rm -rf /var/lib/apt/lists/*

# Install python dependencies as user
USER user
COPY --chown=user requirements.txt .
RUN pip install --no-cache-dir -r requirements.txt
RUN pip install --no-cache-dir fastapi uvicorn python-multipart

# Copy backend code
COPY --chown=user . .

# Copy built frontend from Stage 1
COPY --from=frontend-builder --chown=user /app/dist $HOME/app/frontend/dist

# Expose port 7860 for Hugging Face Spaces
EXPOSE 7860

# Run the API
CMD ["python", "-m", "uvicorn", "src.api:app", "--host", "0.0.0.0", "--port", "7860"]