#!/bin/bash set -euo pipefail # ============================================================================= # TinyCLAP CoreML — HuggingFace Upload Script # ============================================================================= # Usage: # export HF_TOKEN=hf_xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx # ./upload.sh [org/username] # # The optional argument is the HF namespace. Defaults to the current user's # namespace if omitted. # ============================================================================= REPO_NAME="tinyclap-coreml" NAMESPACE="${1:-}" if [ -z "$NAMESPACE" ]; then echo "Usage: $0 " echo "Example: $0 duhamelc" exit 1 fi FULL_REPO="$NAMESPACE/$REPO_NAME" echo "========================================" echo " TinyCLAP CoreML HF Upload" echo " Target: https://huggingface.co/$FULL_REPO" echo "========================================" echo # --- Check prerequisites ------------------------------------------------------ if [ -z "${HF_TOKEN:-}" ]; then echo "Error: HF_TOKEN environment variable is not set." echo "Get your token from https://huggingface.co/settings/tokens" exit 1 fi if ! command -v git &> /dev/null; then echo "Error: git is not installed." exit 1 fi if ! command -v git-lfs &> /dev/null; then echo "Error: git-lfs is not installed. Install it with: brew install git-lfs" exit 1 fi if ! command -v huggingface-cli &> /dev/null; then echo "Warning: huggingface-cli not found. Will use raw git + LFS instead." USE_CLI=false else USE_CLI=true fi # --- Verify files exist ------------------------------------------------------- FILES=( "TinyCLAP_AudioEncoder.mlpackage" "TinyCLAP_TextEncoder.mlpackage" "mel_filter_bank.json" "text_embeddings.json" "README.md" "LICENSE" ".gitattributes" ) for f in "${FILES[@]}"; do if [ ! -e "$f" ]; then echo "Error: Required file '$f' not found in current directory." exit 1 fi done # --- Initialize git repo if needed -------------------------------------------- if [ ! -d ".git" ]; then echo "→ Initializing git repository..." git init git lfs install fi # --- Create or use existing remote ------------------------------------------- if ! git remote get-url origin &> /dev/null; then echo "→ Adding remote origin..." git remote add origin "https://huggingface.co/$FULL_REPO" else echo "→ Updating remote origin..." git remote set-url origin "https://huggingface.co/$FULL_REPO" fi # --- Stage and commit --------------------------------------------------------- echo "→ Staging files..." git add -A if git diff --cached --quiet; then echo "Nothing to commit. Repository is up to date." else echo "→ Committing..." git commit --author="Velvox Builder " -m "Update TinyCLAP CoreML models — ANE/GPU enabled Changes: - Recompiled with compute_units=ALL (CPU + GPU + Apple Neural Engine) - Eliminates CPU-only fallback during inference - Numerically verified: audio cos_sim ≈ 1.0, text cos_sim ≈ 0.999996 Files: - TinyCLAP_AudioEncoder.mlmodel (~17 MB) - TinyCLAP_TextEncoder.mlmodel (~422 MB) - mel_filter_bank.json" fi # --- Push --------------------------------------------------------------------- echo "→ Pushing to HuggingFace..." if [ "$USE_CLI" = true ]; then huggingface-cli upload "$FULL_REPO" . . --repo-type model --token "$HF_TOKEN" else # Raw git push with token in URL git push "https://user:$HF_TOKEN@huggingface.co/$FULL_REPO" main --force fi echo echo "========================================" echo " Upload complete!" echo " https://huggingface.co/$FULL_REPO" echo "========================================"