nextgenyeild-api / Dockerfile
Hassan132's picture
Deploy NextGenYeild API to Hugging Face Spaces
c54c1bf
Raw History Blame Contribute Delete
1.4 kB
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"]