#!/bin/bash # Copyright (c) Delanoe Pirard / Aedelon # Licensed under the Apache License, Version 2.0 # # Deploy to HuggingFace Spaces with LFS for binary files # This script temporarily enables LFS, pushes to HF, then restores normal state set -e SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)" PROJECT_ROOT="$(dirname "$SCRIPT_DIR")" cd "$PROJECT_ROOT" # HuggingFace Spaces YAML front matter HF_YAML='--- title: Awesome Depth Anything 3 emoji: 🌊 colorFrom: blue colorTo: purple sdk: gradio sdk_version: 5.50.0 app_file: app.py pinned: false license: apache-2.0 short_description: Metric 3D reconstruction from images/video --- ' echo "=== HuggingFace Deployment Script ===" # Save current HEAD CURRENT_SHA=$(git rev-parse HEAD) echo "Current commit: $CURRENT_SHA" # Step 1: Configure LFS for binary files echo "" echo "Step 1: Configuring Git LFS..." cat > .gitattributes << 'EOF' *.png filter=lfs diff=lfs merge=lfs -text *.jpg filter=lfs diff=lfs merge=lfs -text *.jpeg filter=lfs diff=lfs merge=lfs -text *.gif filter=lfs diff=lfs merge=lfs -text *.mp4 filter=lfs diff=lfs merge=lfs -text *.webm filter=lfs diff=lfs merge=lfs -text EOF # Step 2: Create deployment branch echo "" echo "Step 2: Creating deployment branch..." git checkout --orphan hf-deploy-temp 2>/dev/null || git checkout hf-deploy-temp # Reset to get clean state git reset # Step 3: Add YAML to README echo "" echo "Step 3: Adding YAML front matter to README..." cp README.md README.md.original echo "$HF_YAML$(cat README.md.original)" > README.md # Step 4: Stage all files (LFS will handle binaries) echo "" echo "Step 4: Staging files with LFS..." git add .gitattributes git add -A # Step 5: Commit echo "" echo "Step 5: Committing..." git commit -m "Deploy to HuggingFace Spaces" --no-verify || true # Step 6: Push to HuggingFace echo "" echo "Step 6: Pushing to HuggingFace Spaces..." git push huggingface hf-deploy-temp:main --force # Step 7: Cleanup - return to main branch echo "" echo "Step 7: Cleaning up..." git checkout main --force git branch -D hf-deploy-temp 2>/dev/null || true # Restore original .gitattributes (no LFS) cat > .gitattributes << 'EOF' *.png !text !filter !merge !diff *.jpg !text !filter !merge !diff *.jpeg !text !filter !merge !diff *.gif !text !filter !merge !diff *.mp4 !text !filter !merge !diff *.webm !text !filter !merge !diff EOF echo "" echo "=== Done! ===" echo "HuggingFace updated with YAML metadata and LFS binaries." echo "Local repo restored to normal state (no LFS)."