#!/bin/bash # Deploy SAM3 to HuggingFace Inference Endpoints set -e echo "🚀 Deploying SAM3 to HuggingFace..." echo "" # Configuration REGISTRY="sam3acr4hf.azurecr.io" IMAGE="sam3-hf:latest" ENDPOINT_NAME="sam3-segmentation" NAMESPACE="Logiroad" # Navigate to project root cd "$(dirname "$0")/../.." # Step 1: Build Docker image echo "[1/4] Building Docker image..." docker build -t ${REGISTRY}/${IMAGE} -f docker/Dockerfile . echo "✓ Build complete" echo "" # Step 2: Login to ACR echo "[2/4] Logging in to Azure Container Registry..." az acr login --name sam3acr4hf echo "✓ Login successful" echo "" # Step 3: Push image echo "[3/4] Pushing image to registry..." docker push ${REGISTRY}/${IMAGE} echo "✓ Push complete" echo "" # Step 4: Restart endpoint echo "[4/4] Restarting HuggingFace endpoint..." python3 << 'EOF' from huggingface_hub import HfApi import time api = HfApi() endpoint = api.get_inference_endpoint('sam3-segmentation', namespace='Logiroad') print(" Pausing endpoint...") endpoint.pause() time.sleep(5) print(" Resuming endpoint...") endpoint.resume() print(" Waiting for endpoint to be running...") for i in range(60): endpoint = api.get_inference_endpoint('sam3-segmentation', namespace='Logiroad') if endpoint.status == 'running': print(f" ✓ Endpoint running after {i*5}s") break time.sleep(5) else: print(" ⚠ Timeout waiting for endpoint") EOF echo "" echo "════════════════════════════════════════════════════════════" echo "✅ HuggingFace Deployment Complete" echo "════════════════════════════════════════════════════════════" echo "" echo "Endpoint: https://p6irm2x7y9mwp4l4.us-east-1.aws.endpoints.huggingface.cloud" echo "" echo "Test with:" echo " python3 scripts/test/test_api.py"