Upload folder using huggingface_hub
Browse files
sync.py
ADDED
@@ -0,0 +1,29 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
from huggingface_hub import HfApi
|
2 |
+
import os
|
3 |
+
|
4 |
+
REPO_ID = "MintplexLabs/multilingual-e5-small"
|
5 |
+
LOCAL_PATH = "." # your local directory
|
6 |
+
|
7 |
+
api = HfApi()
|
8 |
+
|
9 |
+
# Get list of files in repo
|
10 |
+
remote_files = {f for f in api.list_repo_files(repo_id=REPO_ID)}
|
11 |
+
|
12 |
+
# Get list of files locally (recursively)
|
13 |
+
local_files = set()
|
14 |
+
for root, _, files in os.walk(LOCAL_PATH):
|
15 |
+
for file in files:
|
16 |
+
full_path = os.path.join(root, file)
|
17 |
+
relative_path = os.path.relpath(full_path, LOCAL_PATH)
|
18 |
+
local_files.add(relative_path.replace("\\", "/"))
|
19 |
+
|
20 |
+
# Find files that exist remotely but not locally
|
21 |
+
files_to_delete = remote_files - local_files
|
22 |
+
|
23 |
+
# Delete them
|
24 |
+
for file in files_to_delete:
|
25 |
+
print(f"Deleting {file} from repo...")
|
26 |
+
api.delete_file(path_in_repo=file, repo_id=REPO_ID)
|
27 |
+
|
28 |
+
# Now re-upload local files using the CLI
|
29 |
+
os.system(f"huggingface-cli upload {REPO_ID} {LOCAL_PATH}")
|