File size: 1,618 Bytes
7cb8aac
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
"""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)