colab: авто-пуш результата на HF
Browse files68 unmodified lines6970717273747568 unmodified linesshutil.make_archive("/content/pposr_model", "zip", exp)print("модель упакована: /content/pposr_model.zip", flush=True)print("скачать: files.download('/content/pposr_model.zip')", flush=True)if __name__ == "__main__":68 unmodified lines6970717273747576777879808182838485868788899091929394959697989910010110210310410510610710868 unmodified linesshutil.make_archive("/content/pposr_model", "zip", exp)print("модель упакована: /content/pposr_model.zip", flush=True)# если есть токен — сразу заливаем на HF, чтобы не пересылать файлыtoken = _find_token()if token:try:from huggingface_hub import HfApiapi = HfApi(token=token)repo = "AdminHugging/PP-OSR-Hydrogen"api.create_repo(repo, repo_type="model", private=False, exist_ok=True)api.upload_folder(folder_path=exp, repo_id=repo, repo_type="model",commit_message="PP-OSR-H: обученная модель (Colab)")print(f"залито на https://huggingface.co/{repo}", flush=True)except Exception as exc: # noqa: BLE001print(f"пуш не удался: {type(exc).__name__}: {str(exc)[:160]}", flush=True)else:print("токена нет — скачай zip вручную (см. ниже)", flush=True)def _find_token() -> str | None:"""Токен из Colab Secrets (HF_TOKEN), переменной окружения или файла рядом."""tok = os.environ.get("HF_TOKEN")if tok:return tok.strip()try:from google.colab import userdata # type: ignorereturn userdata.get("HF_TOKEN").strip()except Exception: # noqa: BLE001passlocal = os.path.join(HERE, "hf_token.txt")if os.path.exists(local):return open(local, encoding="utf-8").read().strip()return Noneif __name__ == "__main__":
ppai/colab_pposr.py+34-1