Skip to content

Instantly share code, notes, and snippets.

@shahules786
Created May 6, 2023 05:08
Show Gist options
  • Save shahules786/5c8dd668f758efac0402dda5b28c1524 to your computer and use it in GitHub Desktop.
Save shahules786/5c8dd668f758efac0402dda5b28c1524 to your computer and use it in GitHub Desktop.
from huggingface_hub import HfApi
import os
import argparse
api = HfApi()
model_files = ["tokenizer.json","special_tokens_map.json","tokenizer_config.json","config.json","pytorch_model.bin"]
if __name__ == "__main__":
parser = argparse.ArgumentParser(description="")
parser.add_argument("--model_url", type=str, help="model url")
parser.add_argument("--root_dir", type=str, help="model url")
args = parser.parse_args().__dict__
root = args.get("root_dir")
files_upload = [os.path.join(root, name)
for root, dirs, files in os.walk(root)
for name in files
if name.split('/')[-1] in model_files ]
for file in files_upload:
api.upload_file(
path_or_fileobj=file,
repo_id=args.get("model_url"),
repo_type="model",
path_in_repo=file.split('/')[-1]
)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment