Spaces:
Runtime error
Runtime error
File size: 1,379 Bytes
d5a6d18 |
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(upload_model, model_name):
hf_username = input("Enter your HuggingFace username:")
hf_password = getpass("Enter your HuggingFace password:")
if Path("./models").exists():
shutil.rmtree("./models")
token = HfApi().login(username=hf_username, password=hf_password)
del hf_password
model_url = HfApi().create_repo(token=token, name=model_name, exist_ok=True)
model_repo = Repository(
"./model",
clone_from=model_url,
use_auth_token=token,
git_email=f"{hf_username}@users.noreply.huggingface.co",
git_user=hf_username,
)
readme_txt = f"""
---
Summarisation model {model_name}
""".strip()
(Path(model_repo.local_dir) / "README.md").write_text(readme_txt)
upload_model.save_model()
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 __name__ == "__main__":
with open("model_params.yml") as f:
params = yaml.safe_load(f)
model = Summarization()
model.load_model(model_dir="./models")
upload(upload_model=model, model_name=params["name"])
|