File size: 2,154 Bytes
60470bc
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
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()