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