Spaces:
Paused
Paused
| import os, sys, requests | |
| from huggingface_hub import HfApi | |
| TOKEN = "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" | |
| SPACE_NAME = "kpi-dashboard" | |
| USERNAME = "DEWgor" | |
| api = HfApi(token=TOKEN) | |
| # 1. Upload files | |
| print("Uploading files...") | |
| upload_path = os.path.dirname(os.path.abspath(__file__)) | |
| try: | |
| api.upload_folder( | |
| repo_id=f"{USERNAME}/{SPACE_NAME}", | |
| repo_type="space", | |
| folder_path=upload_path, | |
| path_in_repo=".", | |
| ignore_patterns=[ | |
| ".git/*", "__pycache__/*", "*.pyc", ".env", "instance/*", | |
| "uploads/*", "server_log*", "server_err*", "*.bat", "*.exe", | |
| "cf_*", "ngrok*", "cloudflared*", ".chrome_*/", "_archive/*", | |
| "backups/*", "deploy_hf.py", "test_*.py", "wsgi.py", "amvera.yaml", | |
| ".gitignore", "AGENTS.md", "Procfile", "runtime.txt", "backup.*", | |
| "*.zip", "*.db", ".gitattributes", | |
| ], | |
| ) | |
| print("Files uploaded successfully") | |
| except Exception as e: | |
| print(f"Upload error: {e}") | |
| sys.exit(1) | |
| # 2. Set secrets | |
| print("Setting secrets...") | |
| headers = {"Authorization": f"Bearer {TOKEN}"} | |
| secrets = { | |
| "SECRET_KEY": "kpi-hf-secret-2026", | |
| "SCHEDULER_ENABLED": "False", | |
| } | |
| for key, value in secrets.items(): | |
| r = requests.post( | |
| f"https://huggingface.co/api/spaces/{USERNAME}/{SPACE_NAME}/secrets", | |
| headers=headers, | |
| json={"key": key, "value": value}, | |
| ) | |
| if r.status_code in (200, 201): | |
| print(f" Secret {key}: OK") | |
| else: | |
| print(f" Secret {key}: {r.status_code} {r.text[:100]}") | |
| # 3. Enable persistent storage | |
| print("Enabling persistent storage...") | |
| r = requests.post( | |
| f"https://huggingface.co/api/spaces/{USERNAME}/{SPACE_NAME}/storage", | |
| headers=headers, | |
| json={"mountPoint": "/data", "size": 1}, | |
| ) | |
| if r.status_code in (200, 201, 409): | |
| print(f" Storage: {r.status_code} (OK or already exists)") | |
| else: | |
| print(f" Storage: {r.status_code} {r.text[:200]}") | |
| print(f"\nDone! Building at: https://huggingface.co/spaces/{USERNAME}/{SPACE_NAME}") | |
| print(f"App will be at: https://{USERNAME}-{SPACE_NAME}.hf.space") | |