sayakpaul's picture
sayakpaul HF staff
add: emojis.
1fd2466
raw
history blame
768 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, 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}"