-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathupload_openclip.py
More file actions
51 lines (38 loc) · 1.38 KB
/
upload_openclip.py
File metadata and controls
51 lines (38 loc) · 1.38 KB
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
"""Upload exported OpenCLIP .pte files and metadata to HuggingFace Hub."""
import shutil
from pathlib import Path
from huggingface_hub import HfApi
REPO_ID = "mallman/openclip-vit-l14-coreml"
HF_REPO_DIR = Path("hf_repo_openclip")
OUTPUT_DIR = Path("output/openclip")
def main():
api = HfApi()
# Create the repo (no-op if it already exists)
api.create_repo(REPO_ID, repo_type="model", exist_ok=True)
print(f"Repo: https://huggingface.co/{REPO_ID}")
HF_REPO_DIR.mkdir(exist_ok=True)
# Copy config
config_src = OUTPUT_DIR / "config.json"
if config_src.exists():
shutil.copy(config_src, HF_REPO_DIR / "config.json")
# Copy .pte files
for pte in OUTPUT_DIR.glob("clip_vit_l14_*.pte"):
dest = HF_REPO_DIR / pte.name
if not dest.exists() or dest.stat().st_mtime < pte.stat().st_mtime:
print(f"Copying {pte.name} to staging dir...")
shutil.copy(pte, dest)
# Copy tokenizer files
for fname in ["vocab.json", "merges.txt"]:
src = OUTPUT_DIR / fname
if src.exists():
shutil.copy(src, HF_REPO_DIR / fname)
# Upload everything
print("Uploading to HuggingFace Hub...")
api.upload_folder(
folder_path=str(HF_REPO_DIR),
repo_id=REPO_ID,
repo_type="model",
)
print(f"Done! https://huggingface.co/{REPO_ID}")
if __name__ == "__main__":
main()