danush99 commited on
Commit
14836a6
·
verified ·
1 Parent(s): 7ded03b

Upload upload_weights_to_hub.py with huggingface_hub

Browse files
Files changed (1) hide show
  1. upload_weights_to_hub.py +61 -0
upload_weights_to_hub.py ADDED
@@ -0,0 +1,61 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ #!/usr/bin/env python3
2
+ """
3
+ Upload model files to Hugging Face Hub (danush99/Model_TrOCR-Sin-Normal-Text).
4
+
5
+ No git required: this uses the Hugging Face API (HTTP), not git push.
6
+
7
+ From this directory:
8
+ pip install huggingface_hub
9
+ export HF_TOKEN=your_token # get token from https://huggingface.co/settings/tokens
10
+ python upload_weights_to_hub.py
11
+ Or: python upload_weights_to_hub.py --token YOUR_TOKEN
12
+ """
13
+ import os
14
+ import argparse
15
+ from pathlib import Path
16
+
17
+ # All files to push to the model repo (missing files are skipped)
18
+ FILES_TO_UPLOAD = (
19
+ ".gitattributes",
20
+ "config.json",
21
+ "generation_config.json",
22
+ "model.safetensors",
23
+ "preprocessor_config.json",
24
+ "README.md",
25
+ "training_args.bin",
26
+ "upload_weights_to_hub.py",
27
+ )
28
+
29
+
30
+ def main():
31
+ p = argparse.ArgumentParser(description="Upload model files to danush99/Model_TrOCR-Sin-Normal-Text")
32
+ p.add_argument("--token", default=os.environ.get("HF_TOKEN"), help="Hugging Face token")
33
+ p.add_argument("--repo", default="danush99/Model_TrOCR-Sin-Normal-Text", help="Repo id")
34
+ args = p.parse_args()
35
+ if not args.token:
36
+ print("Set HF_TOKEN or pass --token=YOUR_TOKEN")
37
+ raise SystemExit(1)
38
+
39
+ try:
40
+ from huggingface_hub import HfApi
41
+ except ImportError:
42
+ print("Run: pip install huggingface_hub")
43
+ raise SystemExit(1)
44
+
45
+ api = HfApi(token=args.token)
46
+ repo_id = args.repo
47
+ folder = Path(__file__).resolve().parent
48
+
49
+ for name in FILES_TO_UPLOAD:
50
+ path = folder / name
51
+ if not path.is_file():
52
+ print("Skip (not found):", name)
53
+ continue
54
+ print("Uploading", name, "...")
55
+ api.upload_file(path_or_fileobj=str(path), path_in_repo=name, repo_id=repo_id, repo_type="model")
56
+ print("Done:", name)
57
+ print("All files uploaded to https://huggingface.co/" + repo_id)
58
+
59
+
60
+ if __name__ == "__main__":
61
+ main()