File size: 1,262 Bytes
704fa80
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
"""Upload a prepared release folder atomically to main, preserving stable."""
import argparse
from pathlib import Path
from huggingface_hub import HfApi
from model import load_model

def main():
    p=argparse.ArgumentParser(__doc__)
    p.add_argument('--folder',default='release')
    p.add_argument('--repo',default='User-2468/mini-unet-colorizer')
    p.add_argument('--expected-main',default=None,help='Optional optimistic-concurrency commit SHA')
    a=p.parse_args()
    folder=Path(a.folder)
    model=load_model(folder)
    assert sum(p.numel() for p in model.parameters())<4_000_000
    api=HfApi()
    refs={x.name:x.target_commit for x in api.list_repo_refs(a.repo).branches}
    stable=refs.get('stable')
    result=api.upload_folder(repo_id=a.repo,revision='main',folder_path=folder,
        parent_commit=a.expected_main or refs['main'],
        commit_message='Update validated colorizer weights, spatial decoder and deployment artifacts',
        ignore_patterns=['__pycache__/**','*.pyc'])
    after={x.name:x.target_commit for x in api.list_repo_refs(a.repo).branches}
    if stable!=after.get('stable'):raise RuntimeError('Stable changed concurrently; inspect repository history')
    print(result.commit_url)

if __name__=='__main__':main()