File size: 2,070 Bytes
4c8734f
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
#!/usr/bin/env python3
"""
Set HuggingFace Space repository secrets via API.
This configures the environment variables for Cain's data persistence.

Usage:
    export HF_TOKEN=your_token_here
    python3 scripts/set_secrets.py
"""

import sys
import os
from huggingface_hub import HfApi

# Get token from environment or git remote
GIT_REMOTE_TOKEN = os.environ.get("HF_TOKEN")
SPACE_ID = "tao-shen/HuggingClaw-Cain"

# Secrets to set
SECRETS = {
    "HF_TOKEN": None,  # Will be set from environment
    "OPENCLAW_DATASET_REPO": "tao-shen/HuggingClaw-Cain-data",  # Dataset repo for backup
    "AUTO_CREATE_DATASET": "true",  # Auto-create dataset if it doesn't exist
}

def main():
    token = GIT_REMOTE_TOKEN or os.environ.get("HF_TOKEN")

    if not token:
        print("[✗] Error: HF_TOKEN not found!")
        print("[*] Set HF_TOKEN environment variable:")
        print("    export HF_TOKEN=hf_your_token_here")
        sys.exit(1)

    print(f"[*] Setting repository secrets for Space: {SPACE_ID}")
    print(f"[*] Using HF token: {token[:20]}...")

    api = HfApi(token=token)

    # Set HF_TOKEN to the same token (for the Space to use)
    secrets_to_set = SECRETS.copy()
    secrets_to_set["HF_TOKEN"] = token

    for key, value in secrets_to_set.items():
        try:
            api.add_space_secret(
                repo_id=SPACE_ID,
                key=key,
                value=value
            )
            print(f"[✓] Set secret: {key}")
        except Exception as e:
            # Secret might already exist, try updating
            try:
                # HF API doesn't have update, so we just log if it exists
                print(f"[i] Secret {key} may already exist or error: {e}")
            except Exception as e2:
                print(f"[✗] Error setting {key}: {e2}")

    print("\n[*] Secrets configuration complete!")
    print("[*] Next step: Restart the Space to apply the new environment variables")
    print("[*] Visit: https://huggingface.co/spaces/tao-shen/HuggingClaw-Cain")

if __name__ == "__main__":
    main()