File size: 2,113 Bytes
04477e7
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
66
67
68
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")