Spaces:
Sleeping
Sleeping
| #!/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() | |