Delete upload_to_hf.py with huggingface_hub
Browse files- upload_to_hf.py +0 -87
upload_to_hf.py
DELETED
|
@@ -1,87 +0,0 @@
|
|
| 1 |
-
import os
|
| 2 |
-
from huggingface_hub import HfApi
|
| 3 |
-
from dotenv import load_dotenv
|
| 4 |
-
|
| 5 |
-
load_dotenv()
|
| 6 |
-
|
| 7 |
-
REPO_ID = "hisham-cmd/VortexCommerceBackend"
|
| 8 |
-
HF_TOKEN = os.environ.get("HF_TOKEN")
|
| 9 |
-
|
| 10 |
-
api = HfApi(token=HF_TOKEN)
|
| 11 |
-
|
| 12 |
-
def get_files_to_upload():
|
| 13 |
-
files = []
|
| 14 |
-
ignore_dirs = {".git", "__pycache__", ".venv", "venv", "env", "node_modules", ".pytest_cache"}
|
| 15 |
-
ignore_files = {".env", "vortex.db"}
|
| 16 |
-
ignore_extensions = {".db", ".sqlite", ".sqlite3", ".pyc"}
|
| 17 |
-
|
| 18 |
-
for root, dirs, files_list in os.walk("."):
|
| 19 |
-
# Modify dirs in-place to exclude ignored directories
|
| 20 |
-
for d in list(dirs):
|
| 21 |
-
if d in ignore_dirs:
|
| 22 |
-
dirs.remove(d)
|
| 23 |
-
|
| 24 |
-
for f in files_list:
|
| 25 |
-
if f in ignore_files or any(f.endswith(ext) for ext in ignore_extensions):
|
| 26 |
-
continue
|
| 27 |
-
|
| 28 |
-
file_path = os.path.join(root, f)
|
| 29 |
-
# Remove leading .\ or ./
|
| 30 |
-
prefix = f".{os.sep}"
|
| 31 |
-
if file_path.startswith(prefix):
|
| 32 |
-
repo_path = file_path[len(prefix):].replace("\\", "/")
|
| 33 |
-
else:
|
| 34 |
-
repo_path = file_path.replace("\\", "/")
|
| 35 |
-
|
| 36 |
-
files.append((file_path, repo_path))
|
| 37 |
-
|
| 38 |
-
return files
|
| 39 |
-
|
| 40 |
-
def upload():
|
| 41 |
-
import shutil
|
| 42 |
-
# Ensure font is copied to backend before upload
|
| 43 |
-
font_src = os.path.join("..", "frontend", "public", "ArbFONTS-cocon-next-arabic.ttf")
|
| 44 |
-
font_dest_dir = "fonts"
|
| 45 |
-
font_dest = os.path.join(font_dest_dir, "ArbFONTS-cocon-next-arabic.ttf")
|
| 46 |
-
if os.path.exists(font_src):
|
| 47 |
-
os.makedirs(font_dest_dir, exist_ok=True)
|
| 48 |
-
shutil.copy(font_src, font_dest)
|
| 49 |
-
print(f"[*] Copied font from {font_src} to {font_dest}")
|
| 50 |
-
|
| 51 |
-
print(f"\n>>> Preparing to upload backend files to: https://huggingface.co/{REPO_ID}")
|
| 52 |
-
|
| 53 |
-
files = get_files_to_upload()
|
| 54 |
-
print(f"[*] Found {len(files)} files to upload")
|
| 55 |
-
|
| 56 |
-
try:
|
| 57 |
-
print(f"[*] Creating repository...")
|
| 58 |
-
api.create_repo(repo_id=REPO_ID, repo_type="space", space_sdk="docker", private=False, exist_ok=True)
|
| 59 |
-
|
| 60 |
-
print(f"[*] Uploading current folder (backend contents)...")
|
| 61 |
-
api.upload_folder(
|
| 62 |
-
folder_path=".",
|
| 63 |
-
repo_id=REPO_ID,
|
| 64 |
-
repo_type="space",
|
| 65 |
-
commit_message="Update backend with high-quality catalog and fixes",
|
| 66 |
-
ignore_patterns=[
|
| 67 |
-
".git*", "__pycache__*", "venv*", "env*",
|
| 68 |
-
"*.db", "*.sqlite*", ".*", "*.pyc", "uploads/*"
|
| 69 |
-
]
|
| 70 |
-
)
|
| 71 |
-
|
| 72 |
-
print("\n" + "!"*50)
|
| 73 |
-
print("IMPORTANT: To ensure data persistence (Orders, Settings, etc.)")
|
| 74 |
-
print("Make sure you have a persistent volume mounted at /data")
|
| 75 |
-
print("and DATA_DIR=/data is set in your Space environment variables.")
|
| 76 |
-
print("!"*50)
|
| 77 |
-
|
| 78 |
-
print("\n" + "="*50)
|
| 79 |
-
print(f"[OK] SUCCESS!")
|
| 80 |
-
print(f"[LINK] https://huggingface.co/{REPO_ID}")
|
| 81 |
-
print("="*50)
|
| 82 |
-
|
| 83 |
-
except Exception as e:
|
| 84 |
-
print(f"\n[ERROR] {e}")
|
| 85 |
-
|
| 86 |
-
if __name__ == "__main__":
|
| 87 |
-
upload()
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|