File size: 1,382 Bytes
25eb9f7
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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

# Set environment variables
ENV PYTHONUNBUFFERED=1 \
    PYTHONDONTWRITEBYTECODE=1 \
    HF_HOME=/home/user/.cache/huggingface \
    VISUALIZER_CONFIG=visualizer.hf.toml \
    HOME=/home/user

# Install system dependencies (git for compphoto/Intrinsic installation, ffmpeg, glib for OpenCV)
RUN apt-get update && \
    apt-get install -y --no-install-recommends \
        git \
        ffmpeg \
        libglib2.0-0 \
        libgomp1 \
        build-essential && \
    rm -rf /var/lib/apt/lists/*

# Set up a new user named "user" with UID 1000 for Hugging Face permissions
RUN useradd -m -u 1000 user

WORKDIR /app

# Copy requirements files first
COPY requirements-base.txt ./

# Install CPU PyTorch/Torchvision first, then other base requirements
RUN pip install --no-cache-dir --upgrade pip && \
    pip install --no-cache-dir torch torchvision --extra-index-url https://download.pytorch.org/whl/cpu && \
    pip install --no-cache-dir -r requirements-base.txt

# Copy the rest of the application files
COPY --chown=user:1000 . .

# Create writable data directories and change ownership
RUN mkdir -p data/uploads data/jobs && \
    chown -R user:1000 /app

# Switch to the non-root user
USER user

# Hugging Face Spaces expects the application on port 7860
EXPOSE 7860

CMD ["uvicorn", "app:app", "--host", "0.0.0.0", "--port", "7860", "--workers", "1"]