import os import shutil from huggingface_hub import HfApi from dotenv import load_dotenv load_dotenv() REPO_ID = "hisham-cmd/VortexCommerceBackend" HF_TOKEN = os.environ.get("HF_TOKEN") api = HfApi(token=HF_TOKEN) def prepare_assets(): """Prepare any assets like fonts before uploading.""" print(">>> [PREPARE] Preparing assets...") font_src = os.path.join("..", "frontend", "public", "ArbFONTS-cocon-next-arabic.ttf") font_dest_dir = "fonts" font_dest = os.path.join(font_dest_dir, "ArbFONTS-cocon-next-arabic.ttf") if os.path.exists(font_src): os.makedirs(font_dest_dir, exist_ok=True) shutil.copy(font_src, font_dest) print(f"[*] Copied font: {font_dest}") else: print(f"[!] Warning: Font source not found at {font_src}") def upload(): # 1. Prepare assets prepare_assets() print(f"\n>>> [SYNC] Uploading to Hugging Face: https://huggingface.co/spaces/{REPO_ID}") print("[*] Using DIFFERENTIAL SYNC (fastest) - only changed files will be uploaded.") try: # Ensure repo exists api.create_repo(repo_id=REPO_ID, repo_type="space", space_sdk="docker", private=False, exist_ok=True) # Upload folder using both .hfignore and explicit ignore patterns for speed api.upload_folder( repo_id=REPO_ID, folder_path=".", repo_type="space", commit_message="Optimized Sync: Differential Upload & Performance Tweak", ignore_patterns=[ ".git/*", ".venv/*", "venv/*", "__pycache__/*", "*.db", "*.sqlite*", ".env*", "*.env", "scripts/*", "tests/*", "node_modules/*", ".pytest_cache/*", "*.pyc", "*.pyo" ], delete_patterns=["*.pyc", "__pycache__/*"], # Extra cleanup ) print("\n" + "="*50) print(f"[OK] SUCCESS!") print(f"[SYS] Differential sync complete.") print(f"[LINK] https://huggingface.co/spaces/{REPO_ID}") print("="*50) except Exception as e: print(f"\n[ERROR] {e}") if __name__ == "__main__": upload()