File size: 1,306 Bytes
66a8853
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
# Push this folder to the Hugging Face Model Hub
# Usage:
#   pip install huggingface_hub
#   export HF_TOKEN=hf_xxx  # or run `huggingface-cli login`
#   python push_to_hub.py --repo jacopo22295/RESNET50-CORROSION_CLASSIFIER_V1

import argparse, os
from huggingface_hub import HfApi, create_repo, upload_file

def main():
    ap = argparse.ArgumentParser()
    ap.add_argument("--repo", required=True, help="repo id like user/name")
    ap.add_argument("--private", action="store_true", help="create as private")
    args = ap.parse_args()

    api = HfApi()
    create_repo(args.repo, repo_type="model", exist_ok=True, private=args.private)

    base = os.path.dirname(__file__)
    files = [
        "resnet50-corrosion-classifier-v1.pth",
        "README.md",
        "model_config.json",
        "preprocessor_config.json",
        "requirements.txt",
        "labels.json"
    ]

    for f in files:
        path = os.path.join(base, f)
        if not os.path.exists(path):
            raise FileNotFoundError(path)
        print("Uploading", f)
        upload_file(
            path_or_fileobj=path,
            path_in_repo=f,
            repo_id=args.repo,
            repo_type="model"
        )
    print("Done. Visit https://huggingface.co/" + args.repo)

if __name__ == "__main__":
    main()