File size: 3,739 Bytes
6cd46f4
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1ea97a6
 
6cd46f4
 
 
 
 
 
 
 
1ea97a6
6cd46f4
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1ea97a6
6cd46f4
1ea97a6
 
 
 
 
 
 
 
 
6cd46f4
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
#!/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 <hf-namespace>"
    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 <build@localhost>" -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 "========================================"