Spaces:
Sleeping
Sleeping
| from huggingface_hub import HfApi | |
| import os | |
| TOKEN = os.environ.get("HF_TOKEN", "YOUR_TOKEN_HERE") | |
| REPO_ID = "joytheslothh/BacSense-API" | |
| REPO_TYPE = "space" | |
| # Files/dirs to skip (frontend, docs, git artifacts) | |
| SKIP_DIRS = {"frontend", ".git", "__pycache__", ".gitignore"} | |
| SKIP_FILES = {"push_log.txt", "push2.txt", "push_final.txt", "upload_to_hf.py", | |
| "render.yaml", "BacSense_v2_Technical_Documentation.docx", | |
| "BacSense_v2_Technical_Documentation.docx-1.pdf", | |
| "BacSense_v2_Technical_Documentation.docx.txt"} | |
| SKIP_EXTS = {".ps1"} | |
| api = HfApi(token=TOKEN) | |
| base = os.path.abspath(os.path.dirname(__file__)) | |
| files_to_upload = [] | |
| for root, dirs, files in os.walk(base): | |
| # Prune skip dirs in-place | |
| dirs[:] = [d for d in dirs if d not in SKIP_DIRS and not d.startswith('.')] | |
| for fname in files: | |
| if fname in SKIP_FILES: | |
| continue | |
| if any(fname.endswith(ext) for ext in SKIP_EXTS): | |
| continue | |
| full_path = os.path.join(root, fname) | |
| rel_path = os.path.relpath(full_path, base).replace("\\", "/") | |
| files_to_upload.append((full_path, rel_path)) | |
| print(f"Uploading {len(files_to_upload)} files to {REPO_ID}...\n") | |
| for i, (local, remote) in enumerate(files_to_upload, 1): | |
| size_mb = os.path.getsize(local) / (1024*1024) | |
| print(f"[{i}/{len(files_to_upload)}] {remote} ({size_mb:.2f} MB)") | |
| api.upload_file( | |
| path_or_fileobj=local, | |
| path_in_repo=remote, | |
| repo_id=REPO_ID, | |
| repo_type=REPO_TYPE, | |
| ) | |
| print("\n✅ All files uploaded successfully!") | |