Spaces:
Runtime error
Runtime error
File size: 1,349 Bytes
d5a6d18 09be2fb d5a6d18 09be2fb d5a6d18 09be2fb d5a6d18 09be2fb d5a6d18 09be2fb d5a6d18 705340b d5a6d18 09be2fb d5a6d18 09be2fb |
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 45 46 47 48 |
import shutil
from getpass import getpass
from pathlib import Path
import yaml
from model import Summarization
from huggingface_hub import HfApi, Repository
def upload(model_to_upload, model_name):
hf_username = input("Enter your HuggingFace username:")
hf_token = getpass("Enter your HuggingFace token:")
model_url = HfApi().create_repo(token=hf_token, name=model_name, exist_ok=True)
model_repo = Repository(
"./hf_model",
clone_from=model_url,
use_auth_token=hf_token,
git_email=f"{hf_username}@users.noreply.huggingface.co",
git_user=hf_username,
)
del hf_token
readme_txt = f"""
---
Summarisation model {model_name}
""".strip()
(Path(model_repo.local_dir) / "README.md").write_text(readme_txt)
model_to_upload.save_model(Path(model_repo.local_dir))
commit_url = model_repo.push_to_hub()
print("Check out your model at:")
print(commit_url)
print(f"https://huggingface.co/{hf_username}/{model_name}")
if Path("./hf_model").exists():
shutil.rmtree("./hf_model")
if __name__ == "__main__":
with open("model_params.yml") as f:
params = yaml.safe_load(f)
model = Summarization()
model.load_model(model_dir="./models")
upload(model_to_upload=model, model_name=params["name"])
|