| """Upload the humanize-text-model repo to Hugging Face. |
| |
| Repo layout (matches Humanizer's expectations): |
| en/ zh/ humanize.py README.md LICENSE requirements.txt scripts/ tests/ src/ |
| """ |
| import os |
| import shutil |
| from pathlib import Path |
|
|
| from huggingface_hub import HfApi |
|
|
| TOKEN = os.environ["HF_TOKEN"] |
| REPO = "Danny-Lynote/humanize-text-model" |
| SRC = Path(__file__).resolve().parent.parent |
| STAGE = Path("/var/folders/x9/f0cp93qs3qqclss21p96pcgr0000gn/T/opencode/humanize-upload") |
|
|
| shutil.rmtree(STAGE, ignore_errors=True) |
| STAGE.mkdir(parents=True) |
| for name in ["humanize.py", "README.md", "LICENSE", "requirements.txt", "scripts", "tests", "src"]: |
| shutil.copytree(SRC / name, STAGE / name) if (SRC / name).is_dir() else shutil.copy2(SRC / name, STAGE / name) |
| shutil.copytree(SRC / "checkpoints/humanize-text-model/en", STAGE / "en") |
| shutil.copytree(SRC / "checkpoints/humanize-text-model/zh", STAGE / "zh") |
| (STAGE / "docs").mkdir(exist_ok=True) |
| if (SRC / "docs").exists(): |
| for f in (SRC / "docs").iterdir(): |
| if f.is_file(): |
| shutil.copy2(f, STAGE / "docs" / f.name) |
|
|
| api = HfApi(token=TOKEN, endpoint="https://huggingface.co") |
| try: |
| info = api.repo_info(repo_id=REPO, repo_type="model") |
| print("repo exists, sha:", info.sha) |
| except Exception: |
| api.create_repo(repo_id=REPO, repo_type="model", private=False) |
| print("created model repo") |
|
|
| api.upload_folder( |
| folder_path=str(STAGE), |
| repo_id=REPO, |
| repo_type="model", |
| commit_message="Bilingual humanize-text-model (EN T5-small + ZH Chinese T5-small)", |
| ) |
| print("uploaded. url: https://huggingface.co/" + REPO) |
|
|