Spaces:
Sleeping
Sleeping
Upload scripts/push_to_hf_space.py with huggingface_hub
Browse files- scripts/push_to_hf_space.py +4 -40
scripts/push_to_hf_space.py
CHANGED
|
@@ -17,19 +17,7 @@ from huggingface_hub.errors import HfHubHTTPError
|
|
| 17 |
|
| 18 |
def main():
|
| 19 |
repo_id = os.environ.get("HF_SPACE_REPO_ID") or os.environ.get("HF_SPACE_REPO") or "Dyra1204/BiasGuard-Pro"
|
| 20 |
-
skip_dirs = {
|
| 21 |
-
"models",
|
| 22 |
-
"results",
|
| 23 |
-
".git",
|
| 24 |
-
"__pycache__",
|
| 25 |
-
".venv",
|
| 26 |
-
".cache",
|
| 27 |
-
".pytest_cache",
|
| 28 |
-
".mypy_cache",
|
| 29 |
-
".ruff_cache",
|
| 30 |
-
".vscode",
|
| 31 |
-
".idea",
|
| 32 |
-
}
|
| 33 |
|
| 34 |
# Auth: prefer explicit env var, otherwise use cached token from `hf auth login`.
|
| 35 |
token = os.environ.get("HF_TOKEN") or os.environ.get("HUGGINGFACE_HUB_TOKEN")
|
|
@@ -61,41 +49,17 @@ def main():
|
|
| 61 |
)
|
| 62 |
raise
|
| 63 |
|
| 64 |
-
# Cleanup: previous versions of this script could accidentally upload cache files
|
| 65 |
-
# into the Space root. Remove a small allowlist of known junk paths.
|
| 66 |
-
junk_paths = [
|
| 67 |
-
"CACHEDIR.TAG",
|
| 68 |
-
"nodeids",
|
| 69 |
-
"lastfailed",
|
| 70 |
-
"gitignore",
|
| 71 |
-
"certificate.pem",
|
| 72 |
-
"DS_Store",
|
| 73 |
-
".DS_Store",
|
| 74 |
-
]
|
| 75 |
-
for path in junk_paths:
|
| 76 |
-
try:
|
| 77 |
-
api.delete_file(
|
| 78 |
-
path_in_repo=path,
|
| 79 |
-
repo_id=repo_id,
|
| 80 |
-
repo_type="space",
|
| 81 |
-
token=token,
|
| 82 |
-
commit_message=f"Remove junk file: {path}",
|
| 83 |
-
)
|
| 84 |
-
except Exception:
|
| 85 |
-
pass
|
| 86 |
-
|
| 87 |
# Walk repository and upload files (skip ignored directories)
|
| 88 |
to_upload = []
|
| 89 |
for root, dirs, files in os.walk("."):
|
| 90 |
# mutate dirs in-place to skip unwanted directories
|
| 91 |
-
dirs[:] = [d for d in dirs if d not in skip_dirs
|
| 92 |
for fn in files:
|
| 93 |
-
if fn in {".DS_Store"}:
|
| 94 |
-
continue
|
| 95 |
if fn.endswith((".pyc", ".pyo", ".log")):
|
| 96 |
continue
|
|
|
|
| 97 |
rel_dir = os.path.relpath(root, ".")
|
| 98 |
-
if rel_dir
|
| 99 |
rel_dir = ""
|
| 100 |
local_path = os.path.join(root, fn)
|
| 101 |
# avoid uploading the uploader script itself twice when executed from repo
|
|
|
|
| 17 |
|
| 18 |
def main():
|
| 19 |
repo_id = os.environ.get("HF_SPACE_REPO_ID") or os.environ.get("HF_SPACE_REPO") or "Dyra1204/BiasGuard-Pro"
|
| 20 |
+
skip_dirs = {"models", "results", ".git", "__pycache__", ".venv", ".cache"}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 21 |
|
| 22 |
# Auth: prefer explicit env var, otherwise use cached token from `hf auth login`.
|
| 23 |
token = os.environ.get("HF_TOKEN") or os.environ.get("HUGGINGFACE_HUB_TOKEN")
|
|
|
|
| 49 |
)
|
| 50 |
raise
|
| 51 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 52 |
# Walk repository and upload files (skip ignored directories)
|
| 53 |
to_upload = []
|
| 54 |
for root, dirs, files in os.walk("."):
|
| 55 |
# mutate dirs in-place to skip unwanted directories
|
| 56 |
+
dirs[:] = [d for d in dirs if d not in skip_dirs]
|
| 57 |
for fn in files:
|
|
|
|
|
|
|
| 58 |
if fn.endswith((".pyc", ".pyo", ".log")):
|
| 59 |
continue
|
| 60 |
+
# skip hidden cache files in repo root
|
| 61 |
rel_dir = os.path.relpath(root, ".")
|
| 62 |
+
if rel_dir.startswith("."):
|
| 63 |
rel_dir = ""
|
| 64 |
local_path = os.path.join(root, fn)
|
| 65 |
# avoid uploading the uploader script itself twice when executed from repo
|