Download code/scripts/upload.py from KeremTT/OPUS-5.5-DATABASE: direct link, hf CLI and curl.
- Browser
- Download file 2.37 kB
-
https://huggingface.co/datasets/KeremTT/OPUS-5.5-DATABASE/resolve/main/code/scripts/upload.py
- Command line
-
hf download hf://datasets/KeremTT/OPUS-5.5-DATABASE/code/scripts/upload.py
-
curl -L -o upload.py https://huggingface.co/datasets/KeremTT/OPUS-5.5-DATABASE/resolve/main/code/scripts/upload.py
2.37 kB
| """Publish OPUS-5.5-DATABASE to the Hugging Face Hub (public dataset repo). | |
| Uploads out/data/**, out/assets/*.png, out/stats/*.json, out/README.md and this library under code/. | |
| Uploads one commit per config, then the card, figures, statistics and code. | |
| """ | |
| import os | |
| import shutil | |
| import sys | |
| from huggingface_hub import HfApi | |
| OUT = os.environ.get("OPUSDB_OUT", "out") | |
| REPO = os.environ.get("OPUSDB_REPO", "KeremTT/OPUS-5.5-DATABASE") | |
| HERE = os.path.abspath(os.path.join(os.path.dirname(__file__), "..")) | |
| def stage_code(): | |
| dst = os.path.join(OUT, "code") | |
| shutil.rmtree(dst, ignore_errors=True) | |
| for sub in ("opusdb", "scripts", "train", "tests"): | |
| shutil.copytree(os.path.join(HERE, sub), os.path.join(dst, sub), | |
| ignore=shutil.ignore_patterns("__pycache__", "*.pyc")) | |
| for f in ("requirements.txt", "README.md"): | |
| shutil.copy(os.path.join(HERE, f), dst) | |
| def main(): | |
| api = HfApi() | |
| api.create_repo(REPO, repo_type="dataset", private=False, exist_ok=True) | |
| stage_code() | |
| only = sys.argv[1:] or None | |
| if only: # e.g. `upload.py README.md assets` for quick card refreshes | |
| for p in only: | |
| full = os.path.join(OUT, p) | |
| if os.path.isdir(full): | |
| api.upload_folder(repo_id=REPO, repo_type="dataset", folder_path=full, path_in_repo=p, | |
| commit_message=f"Update {p}") | |
| else: | |
| api.upload_file(repo_id=REPO, repo_type="dataset", path_or_fileobj=full, path_in_repo=p, | |
| commit_message=f"Update {p}") | |
| return | |
| # one commit per config keeps each commit small and lets a failed upload resume per config | |
| for cfg in sorted(os.listdir(os.path.join(OUT, "data"))): | |
| api.upload_folder(repo_id=REPO, repo_type="dataset", folder_path=os.path.join(OUT, "data", cfg), | |
| path_in_repo=f"data/{cfg}", commit_message=f"Upload {cfg} config") | |
| api.upload_folder(repo_id=REPO, repo_type="dataset", folder_path=OUT, commit_message="Update card, charts, stats, code", | |
| allow_patterns=["assets/*.png", "stats/*.json", "README.md", "code/**"], | |
| ignore_patterns=["stats/sft_lengths.json", "stats/ladder_tokenizer.json"]) | |
| print("https://huggingface.co/datasets/" + REPO) | |
| if __name__ == "__main__": | |
| main() | |