Spaces:
Sleeping
Sleeping
| # ================================================================ | |
| # PVD System β HuggingFace Spaces Dockerfile | |
| # CPU only β HuggingFace free tier | |
| # ================================================================ | |
| FROM python:3.10-slim | |
| # ββ Environment βββββββββββββββββββββββββββββββββββββββββββββββ | |
| ENV PYTHONDONTWRITEBYTECODE=1 | |
| ENV PYTHONUNBUFFERED=1 | |
| ENV PYTHONPATH=/app:/app/src:/app/backend | |
| WORKDIR /app | |
| # ββ Step 1: System dependencies βββββββββββββββββββββββββββββββ | |
| RUN apt-get update && apt-get install -y \ | |
| git \ | |
| wget \ | |
| curl \ | |
| ffmpeg \ | |
| libsm6 \ | |
| libxext6 \ | |
| libgl1 \ | |
| libglib2.0-0 \ | |
| libxrender-dev \ | |
| libgomp1 \ | |
| build-essential \ | |
| gcc \ | |
| g++ \ | |
| && rm -rf /var/lib/apt/lists/* | |
| # ββ Step 2: Fix pip + setuptools (pkg_resources fix) ββββββββββ | |
| RUN pip install --upgrade pip | |
| RUN pip install "setuptools==69.5.1" wheel --force-reinstall | |
| # ββ Step 3: NumPy FIRST before everything βββββββββββββββββββββ | |
| RUN pip install "numpy<2.0.0" | |
| # ββ Step 4: PyTorch CPU βββββββββββββββββββββββββββββββββββββββ | |
| RUN pip install \ | |
| torch==2.2.2+cpu \ | |
| torchvision==0.17.2+cpu \ | |
| --index-url https://download.pytorch.org/whl/cpu | |
| # ββ Step 5: Force numpy back after torch ββββββββββββββββββββββ | |
| # torch sometimes pulls numpy 2.x β force it back to 1.x | |
| RUN pip install "numpy<2.0.0" --force-reinstall | |
| # ββ Step 6: Verify numpy is correct βββββββββββββββββββββββββββ | |
| RUN python -c "import numpy; print('numpy version:', numpy.__version__); assert numpy.__version__ < '2', 'NumPy 2.x detected!'" | |
| # ββ Step 7: OpenMIM βββββββββββββββββββββββββββββββββββββββββββ | |
| RUN pip install openmim==0.3.9 | |
| # ββ Step 8: mmengine first ββββββββββββββββββββββββββββββββββββ | |
| RUN mim install mmengine==0.10.4 | |
| # ββ Step 9: Full mmcv with C++ extensions βββββββββββββββββββββ | |
| # Use pip with find-links to get pre-built wheel (no source build) | |
| # This avoids pkg_resources error from building from source | |
| RUN pip install mmcv==2.1.0 \ | |
| -f https://download.openmmlab.com/mmcv/dist/cpu/torch2.2/index.html \ | |
| --no-build-isolation | |
| # ββ Step 10: Verify mmcv._ext is available ββββββββββββββββββββ | |
| RUN python -c "from mmcv.ops import roi_align; print('mmcv._ext loaded successfully β ')" | |
| # ββ Step 11: mmdet ββββββββββββββββββββββββββββββββββββββββββββ | |
| RUN mim install mmdet==3.3.0 | |
| # ββ Step 12: chumpy fix then mmpose βββββββββββββββββββββββββββ | |
| RUN pip install chumpy --no-build-isolation | |
| RUN mim install mmpose==1.3.1 | |
| # ββ Step 13: OpenCV headless ββββββββββββββββββββββββββββββββββ | |
| RUN pip install opencv-python-headless==4.8.1.78 | |
| # ββ Step 15: Install remaining pip packages βββββββββββββββββββ | |
| COPY requirements.txt . | |
| RUN grep -viE \ | |
| "torch|torchvision|mmcv|mmpose|mmdet|mmengine|opencv|insightface|facenet|numpy|gdown" \ | |
| requirements.txt > requirements_clean.txt && \ | |
| pip install -r requirements_clean.txt | |
| # ββ Step 16: gdown for Google Drive βββββββββββββββββββββββββββ | |
| RUN pip install gdown | |
| # ββ Step 17: Copy all project files ββββββββββββββββββββββββββ | |
| COPY artifacts/ ./artifacts/ | |
| COPY backend/ ./backend/ | |
| COPY configs/ ./configs/ | |
| COPY scripts/ ./scripts/ | |
| COPY src/ ./src/ | |
| # ββ Step 18: Download large model from Google Drive βββββββββββ | |
| RUN gdown "https://drive.google.com/uc?id=1P9KxRKiJ-_bX5b_IGsYOmwEPXIgyPUbV" \ | |
| -O ./artifacts/posture_classifier/weights/best_posture_model.pth && \ | |
| echo "best_posture_model.pth downloaded successfully β " | |
| # ββ Step 19: Verify all model files exist ββββββββββββββββββββ | |
| RUN python -c "\ | |
| import os; \ | |
| models = [ \ | |
| 'artifacts/mmpose/checkpoints/rtmdet_nano_8xb32-100e_coco-obj365-person-05d8511e.pth', \ | |
| 'artifacts/mmpose/checkpoints/rtmpose-tiny_simcc-aic-coco_pt-aic-coco_420e-256x192-cfc8f33d_20230126.pth', \ | |
| 'artifacts/phone_detector/pretrained/yolo11n.pt', \ | |
| 'artifacts/phone_detector/weights/best.pt', \ | |
| 'artifacts/posture_classifier/weights/best_posture_model.pth', \ | |
| ]; \ | |
| [print(f'β {m}') if os.path.exists(m) else print(f'β MISSING: {m}') for m in models]" | |
| WORKDIR /app/backend | |
| EXPOSE 7860 | |
| HEALTHCHECK --interval=30s --timeout=15s --start-period=120s --retries=3 \ | |
| CMD curl -f http://localhost:7860/health || exit 1 | |
| CMD ["python", "-m", "uvicorn", "app.main:app", \ | |
| "--host", "0.0.0.0", \ | |
| "--port", "7860", \ | |
| "--workers", "1"] |