|
|
|
|
|
""" |
|
|
Helper script to set Hugging Face Space secrets from the terminal. |
|
|
Requires `huggingface_hub` to be installed and logged in. |
|
|
""" |
|
|
|
|
|
import os |
|
|
import getpass |
|
|
from huggingface_hub import HfApi |
|
|
|
|
|
def set_secrets(): |
|
|
print("π Hugging Face Space Secrets Manager") |
|
|
print("-------------------------------------") |
|
|
|
|
|
|
|
|
default_repo = os.getenv("GITHUB_REPO") |
|
|
repo_id = input(f"Enter Space Repo ID (e.g., username/space-name): ").strip() |
|
|
|
|
|
if not repo_id: |
|
|
print("β Repo ID is required.") |
|
|
return |
|
|
|
|
|
api = HfApi() |
|
|
|
|
|
secrets_to_set = [ |
|
|
"ANTHROPIC_API_KEY", |
|
|
"OPENAI_API_KEY", |
|
|
"GOOGLE_API_KEY", |
|
|
"HF_TOKEN" |
|
|
] |
|
|
|
|
|
print(f"\nSetting secrets for: {repo_id}") |
|
|
print("Press Enter to skip a secret if you don't want to update it.\n") |
|
|
|
|
|
for secret in secrets_to_set: |
|
|
value = getpass.getpass(f"Enter value for {secret}: ").strip() |
|
|
if value: |
|
|
try: |
|
|
api.add_space_secret(repo_id=repo_id, key=secret, value=value) |
|
|
print(f"β
Set {secret}") |
|
|
except Exception as e: |
|
|
print(f"β Failed to set {secret}: {e}") |
|
|
else: |
|
|
print(f"βοΈ Skipped {secret}") |
|
|
|
|
|
print("\n⨠Done! Your secrets are updated.") |
|
|
|
|
|
if __name__ == "__main__": |
|
|
try: |
|
|
set_secrets() |
|
|
except ImportError: |
|
|
print("β 'huggingface_hub' library not found. Run: pip install huggingface_hub") |
|
|
except Exception as e: |
|
|
print(f"β An error occurred: {e}") |
|
|
|