Spaces:
Sleeping
Sleeping
| # upload_to_space_recursive.py | |
| import os | |
| from huggingface_hub import HfApi, upload_file, create_repo | |
| # === CONFIGURATION === | |
| HF_TOKEN = os.environ.get("HF_TOKEN") # export HF_TOKEN="hf_xxx..." | |
| REPO_ID = "Pingsz/hack-nation-3rd1" # your Hugging Face Space | |
| REPO_TYPE = "space" | |
| LOCAL_DIR = "geo-risk-space" # folder to upload | |
| api = HfApi(token=HF_TOKEN) | |
| # Create repo if doesn't exist | |
| try: | |
| api.create_repo(repo_id=REPO_ID, repo_type=REPO_TYPE, private=False) | |
| print(f"✅ Created Space: {REPO_ID}") | |
| except Exception as e: | |
| print(f"ℹ️ Space may already exist: {e}") | |
| # Walk directory recursively | |
| for root, _, files in os.walk(LOCAL_DIR): | |
| for file in files: | |
| # Skip cache, compiled pyc, and secret keys | |
| if file.endswith(".pyc") or "gee_service_account" in file or "theta-decker" in file: | |
| print(f"⏩ Skipping secret or cache file: {file}") | |
| continue | |
| local_path = os.path.join(root, file) | |
| # target path inside repo: preserve folder structure under geo-risk-space/ | |
| rel_path = os.path.relpath(local_path, LOCAL_DIR).replace("\\", "/") | |
| print(f"⬆️ Uploading {rel_path} ...") | |
| try: | |
| upload_file( | |
| path_or_fileobj=local_path, | |
| path_in_repo=rel_path, | |
| repo_id=REPO_ID, | |
| repo_type=REPO_TYPE, | |
| token=HF_TOKEN, | |
| ) | |
| except Exception as e: | |
| print(f"❌ Upload failed for {file}: {e}") | |
| print("✅ Upload complete.") | |
| print(f"🔗 Check your Space at: https://huggingface.co/spaces/{REPO_ID}") | |