File size: 1,144 Bytes
98075af
 
 
 
 
 
 
 
 
 
 
257934d
98075af
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
# Hugging Face Spaces — Docker deployment
# SDK: docker  |  app_port: 7860
#
# Build context is the repo root.
# Only backend/ and models/ are copied in; DataSet/ is intentionally excluded.

FROM python:3.11-slim

# System libraries required by opencv-python-headless
RUN apt-get update && apt-get install -y --no-install-recommends \
        libglib2.0-0 \
        libgl1 \
    && rm -rf /var/lib/apt/lists/*

# HF Spaces runs containers as uid 1000 by default
RUN useradd -m -u 1000 appuser

WORKDIR /app

# Install CPU-only PyTorch first so pip does not download the large CUDA wheels
RUN pip install --no-cache-dir \
        torch==2.2.2+cpu \
        torchvision==0.17.2+cpu \
        --index-url https://download.pytorch.org/whl/cpu

# Install remaining API dependencies
COPY requirements-hf.txt requirements-hf.txt
RUN pip install --no-cache-dir -r requirements-hf.txt

# Copy only what the API needs at runtime
COPY --chown=appuser:appuser backend/ backend/
COPY --chown=appuser:appuser models/  models/

USER appuser

EXPOSE 7860

CMD ["python", "-m", "uvicorn", "backend.app.main:app", \
     "--host", "0.0.0.0", "--port", "7860"]