File size: 2,033 Bytes
9128c01
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
#!/usr/bin/env python3
"""
Script to set up Firebase credentials secret on Hugging Face Spaces
Usage: python scripts/setup_hf_secret.py
"""

import json
import sys
from pathlib import Path
from huggingface_hub import HfApi

SPACE_NAME = "MCP-1st-Birthday/CuriousLearner"
SECRET_NAME = "FIREBASE_CREDENTIALS_JSON"
CREDENTIALS_FILE = "firebase-credentials.json"

def main():
    print("πŸ”§ Setting up Firebase credentials secret on HF Spaces...")

    # Check if credentials file exists
    creds_path = Path(CREDENTIALS_FILE)
    if not creds_path.exists():
        print(f"❌ Error: {CREDENTIALS_FILE} not found!")
        print("Please ensure the credentials file exists in the current directory.")
        sys.exit(1)

    # Read and validate JSON
    try:
        with open(creds_path, 'r') as f:
            credentials = json.load(f)
        credentials_str = json.dumps(credentials)
    except json.JSONDecodeError as e:
        print(f"❌ Error: Invalid JSON in {CREDENTIALS_FILE}: {e}")
        sys.exit(1)

    # Initialize HF API
    try:
        api = HfApi()
        # Test authentication
        api.whoami()
    except Exception as e:
        print("❌ Error: Not logged in to Hugging Face!")
        print("Please run: huggingface-cli login")
        print(f"Details: {e}")
        sys.exit(1)

    # Add secret to Space
    try:
        print(f"πŸ“€ Uploading secret to {SPACE_NAME}...")
        api.add_space_secret(
            repo_id=SPACE_NAME,
            key=SECRET_NAME,
            value=credentials_str
        )
        print(f"βœ… Secret {SECRET_NAME} successfully set on {SPACE_NAME}!")
        print("πŸš€ Your HF Space will now have access to Firebase credentials.")
        print("")
        print("⚠️  Note: You may need to restart the Space for changes to take effect.")
        print("Visit: https://huggingface.co/spaces/MCP-1st-Birthday/CuriousLearner")
    except Exception as e:
        print(f"❌ Error setting secret: {e}")
        sys.exit(1)

if __name__ == "__main__":
    main()