Spaces:
Runtime error
Runtime error
Download scripts/set_hf_secrets.py from fongci/slack_url_bot: direct link, hf CLI and curl.
- Browser
- Download file 1.31 kB
-
https://huggingface.co/spaces/fongci/slack_url_bot/resolve/main/scripts/set_hf_secrets.py
- Command line
-
hf download hf://spaces/fongci/slack_url_bot/scripts/set_hf_secrets.py
-
curl -L -o set_hf_secrets.py https://huggingface.co/spaces/fongci/slack_url_bot/resolve/main/scripts/set_hf_secrets.py
1.31 kB
| import os | |
| from huggingface_hub import HfApi | |
| from dotenv import dotenv_values | |
| import argparse | |
| def main(): | |
| parser = argparse.ArgumentParser(description="Upload .env secrets to Hugging Face Space") | |
| parser.add_argument("--repo-id", default="fongci/slack_url_bot", help="Hugging Face Space ID (username/space-name)") | |
| parser.add_argument("--env-file", default=".env", help="Path to the .env file") | |
| args = parser.parse_args() | |
| if not os.path.exists(args.env_file): | |
| print(f"Error: {args.env_file} not found.") | |
| return | |
| # Read .env file | |
| config = dotenv_values(args.env_file) | |
| # Use explicit token if provided via environment variable | |
| token = os.getenv("HF_TOKEN") | |
| api = HfApi(token=token) | |
| # If no token, we rely on ambient authentication (huggingface-cli login) | |
| print(f"Updating secrets for {args.repo_id}...") | |
| for key, value in config.items(): | |
| if not value: | |
| print(f"Skipping empty value for: {key}") | |
| continue | |
| try: | |
| api.add_space_secret(repo_id=args.repo_id, key=key, value=value) | |
| print(f"✅ Added secret: {key}") | |
| except Exception as e: | |
| print(f"❌ Failed to add secret {key}: {e}") | |
| if __name__ == "__main__": | |
| main() | |