#!/bin/bash # Usage: ./deploy.sh # Example: ./deploy.sh ../yolo-output/models/20250422.7/ set -e if [ $# -lt 1 ]; then echo "Usage: $0 " exit 1 fi ml git-lfs/3.2.0 MODEL_DIR=$1 HF_SPACE_URL=git@hf.co:spaces/rayh/clusterflux MODEL_SERVER_DIR=$(dirname "$0") WEIGHTS_SRC="$MODEL_DIR/train/weights/best.pt" WEIGHTS_DST="$MODEL_SERVER_DIR/weights/best.pt" # Step 1: Copy model weights mkdir -p "$MODEL_SERVER_DIR/weights" cp "$WEIGHTS_SRC" "$WEIGHTS_DST" echo "Copied model weights from $WEIGHTS_SRC to $WEIGHTS_DST" # Step 2: Extract version (last part of model dir) VERSION=$(basename "$MODEL_DIR") echo "$VERSION" > "$MODEL_SERVER_DIR/VERSION" echo "Set VERSION to $VERSION" # Step 3: Setup Git LFS for .pt files cd "$MODEL_SERVER_DIR" if ! git lfs &> /dev/null; then echo "Git LFS not found! Please install git-lfs before running this script." exit 1 fi git lfs install if [ ! -f .gitattributes ] || ! grep -q "weights/*.pt" .gitattributes; then git lfs track "weights/*.pt" git add .gitattributes fi # Step 4: Deploy to Hugging Face Spaces echo "Pushing to Hugging Face Space..." if [ ! -d .git ]; then git init git remote add origin "$HF_SPACE_URL" fi git add . git commit -m "Deploy latest YOLO model and app (version $VERSION)" || echo "Nothing to commit" git branch -M main git push -u origin main --force echo "Deployment complete."