sayakpaul's picture
sayakpaul HF staff
apply styling.
3304f7d
raw
history blame
789 Bytes
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)
url = hf_api.upload_folder(
folder_path=push_dir, repo_id=repo_id, exist_ok=True
)
return f"Model successfully pushed: [{url}]({url})"
except Exception as e:
return f"{e}"