File size: 789 Bytes
ddc8a59
 
3304f7d
ddc8a59
 
 
 
 
 
 
3304f7d
 
 
 
 
e548249
3304f7d
e548249
3304f7d
ddc8a59
 
3304f7d
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
from huggingface_hub import HfApi, create_repo


def push_to_hub(hf_token: str, push_dir: str, repo_prefix: None) -> str:
    try:
        if hf_token == "":
            return "No HF token provided. Model won't be pushed."
        else:
            hf_api = HfApi(token=hf_token)
            user = hf_api.whoami()["name"]
            repo_id = (
                f"{user}/{push_dir}"
                if repo_prefix == ""
                else f"{user}/{repo_prefix}-{push_dir}"
            )
            _ = create_repo(repo_id=repo_id, token=hf_token, exist_ok=True)
            url = hf_api.upload_folder(
                folder_path=push_dir, repo_id=repo_id
            )
            return f"Model successfully pushed: [{url}]({url})"
    except Exception as e:
        return f"{e}"