File size: 1,395 Bytes
c54c1bf
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
FROM python:3.11-slim

# Install system dependencies
RUN apt-get update && apt-get install -y --no-install-recommends \
    curl \
    git \
    && rm -rf /var/lib/apt/lists/*

# Hugging Face Spaces requirement: user with UID 1000
RUN useradd -m -u 1000 user
USER user
ENV HOME=/home/user \
    PATH=/home/user/.local/bin:$PATH \
    PYTHONUNBUFFERED=1 \
    PORT=7860

WORKDIR $HOME/app

# Install PyTorch CPU wheels first (keeps container lightweight & builds fast)
RUN pip install --no-cache-dir torch==2.5.1 torchvision --index-url https://download.pytorch.org/whl/cpu

# Copy and install Python requirements
COPY --chown=user:user requirements.txt .
RUN pip install --no-cache-dir -r requirements.txt

# Copy application source code
COPY --chown=user:user . .

# Ensure internal dinov2 import symlink exists
RUN ln -sf FoMo4Wheat dinov2

# Auto-download the FoMo4Wheat foundation backbone during Docker build if not present
RUN python -c "from pathlib import Path; import urllib.request; p = Path('weight/FoMo4Wheat_base.pth'); p.parent.mkdir(parents=True, exist_ok=True); (not p.exists()) and (print('Downloading FoMo4Wheat_base.pth (~346MB)...'), urllib.request.urlretrieve('https://huggingface.co/PheniX-Lab/FoMo4Wheat/resolve/main/weight/FoMo4Wheat_base.pth', str(p)), print('Download finished!'))"

EXPOSE 7860

CMD ["uvicorn", "api.server:app", "--host", "0.0.0.0", "--port", "7860"]