File size: 1,526 Bytes
dd2eba1
 
88a526c
 
 
 
 
 
 
 
0570951
dd2eba1
88a526c
 
 
 
dd2eba1
 
88a526c
dd2eba1
0570951
88a526c
dd2eba1
 
88a526c
 
 
 
 
 
dd2eba1
88a526c
 
 
 
 
 
dd2eba1
88a526c
dd2eba1
88a526c
 
dd2eba1
 
 
88a526c
 
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
47
FROM python:3.10-slim

ENV PYTHONDONTWRITEBYTECODE=1 \
    PYTHONUNBUFFERED=1 \
    PIP_NO_CACHE_DIR=1 \
    FLAGS_use_mkldnn=0 \
    OMP_NUM_THREADS=2

# Runtime libraries required by OpenCV, PaddlePaddle and Ultralytics.
RUN apt-get update && apt-get install -y --no-install-recommends \
    libgl1 \
    libglib2.0-0 \
    libgomp1 \
    libsm6 \
    libxext6 \
    libxrender1 \
    && rm -rf /var/lib/apt/lists/*

# Hugging Face Docker Spaces commonly run the application as UID 1000.
RUN useradd -m -u 1000 user

USER user
ENV HOME=/home/user \
    PATH=/home/user/.local/bin:$PATH \
    HF_HOME=/home/user/.cache/huggingface \
    YOLO_CONFIG_DIR=/home/user/.config/Ultralytics

WORKDIR /home/user/app

COPY --chown=user:user requirements.txt ./requirements.txt

# Install CPU-only PyTorch first, then the API/OCR dependencies.
RUN python -m pip install --user --upgrade pip setuptools wheel && \
    python -m pip install --user \
      torch==2.6.0 torchvision==0.21.0 \
      --index-url https://download.pytorch.org/whl/cpu && \
    python -m pip install --user -r requirements.txt

COPY --chown=user:user main.py ./main.py

# Download and cache YOLO, PAN detector and PaddleOCR models at build time.
RUN python -c "from main import PanKycEngine; PanKycEngine().load_models(); print('Models cached successfully')"

EXPOSE 7860

# One worker avoids loading a separate copy of every model into memory.
CMD ["uvicorn", "main:app", "--host", "0.0.0.0", "--port", "7860", "--workers", "1", "--timeout-keep-alive", "120"]