File size: 1,428 Bytes
8fd2d1a
a04bb49
 
8fd2d1a
 
 
 
 
 
 
 
a04bb49
 
 
8fd2d1a
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
a04bb49
8fd2d1a
a04bb49
 
 
 
 
 
 
 
 
 
 
 
8fd2d1a
 
 
 
 
 
 
 
 
 
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
53
54
55
#!/bin/bash
# Usage: ./deploy.sh <path_to_latest_yolo_train_dir>
# Example: ./deploy.sh ../yolo-output/models/20250422.7/

set -e

if [ $# -lt 1 ]; then
  echo "Usage: $0 <path_to_latest_yolo_train_dir>"
  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."