Spaces:
Running
Running
File size: 2,094 Bytes
6cbe52d fda48ab 6cbe52d 00e4d88 6cbe52d 10f0914 1f836a4 00e4d88 7ec84bf 00e4d88 6cbe52d 2b4a83e a738230 00e4d88 6cbe52d fed888a 6cbe52d 3da8763 6cbe52d ebba6b8 cd71264 6cbe52d ebba6b8 6cbe52d a738230 | 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 48 49 50 51 52 | # Shape2Force (S2F) - Hugging Face Spaces
FROM python:3.10-slim
# Create user for HF Spaces (runs as UID 1000)
RUN useradd -m -u 1000 user
WORKDIR /app
# Install system deps for OpenCV
RUN apt-get update && apt-get install -y --no-install-recommends \
libgl1 \
libglib2.0-0 \
&& rm -rf /var/lib/apt/lists/*
# Copy requirements first for better caching
COPY requirements.txt requirements-docker.txt ./
# Install Python dependencies - CPU-only PyTorch to fit Space memory limits (avoids OOM)
# (psutil removed from requirements-docker.txt — optional CPU/RAM widget not used in app)
# PyTorch 2.2 + torchvision 0.17 (CPU) - match requirements.txt torch>=2.0
# Install numpy first with compatible version (<2) so torch.from_numpy works
RUN pip install --no-cache-dir "numpy>=1.20.0,<2.0" && \
pip install --no-cache-dir torch==2.2.0 torchvision==0.17.0 --index-url https://download.pytorch.org/whl/cpu && \
pip install --no-cache-dir -r requirements-docker.txt
# Copy app code (chown for HF Spaces permissions)
COPY --chown=user:user app.py predictor.py download_ckp.py ./
COPY --chown=user:user .streamlit/ .streamlit/
COPY --chown=user:user static/ static/
COPY --chown=user:user models/ models/
COPY --chown=user:user ui/ ui/
COPY --chown=user:user utils/ utils/
COPY --chown=user:user config/ config/
COPY --chown=user:user samples/ samples/
RUN mkdir -p ckp && chown user:user ckp
# Download checkpoints from Hugging Face if ckp is empty (for Space deployment)
# Requires HF_TOKEN secret in Space Settings (https://huggingface.co/settings/tokens)
# for private model repos. Set HF_MODEL_REPO to your model repo, e.g. Angione-Lab/Shape2Force
ARG HF_MODEL_REPO=Angione-Lab/Shape2Force
ENV HF_MODEL_REPO=${HF_MODEL_REPO}
RUN --mount=type=secret,id=HF_TOKEN,mode=0444,required=true \
HF_TOKEN=$(cat /run/secrets/HF_TOKEN) python download_ckp.py
# Ensure ckp contents are readable by user
RUN chown -R user:user ckp
USER user
EXPOSE 8501
CMD ["streamlit", "run", "app.py", "--server.port=8501", "--server.address=0.0.0.0", "--server.enableXsrfProtection=false"]
|