colab: авто-пуш результата на HF
Browse files68 unmodified lines697071727273747576777879808182838485868788899091929394959697989910010110210310410510610710868 unmodified lines
shutil.make_archive("/content/pposr_model", "zip", exp) print("модель упакована: /content/pposr_model.zip", flush=True) print("скачать: files.download('/content/pposr_model.zip')", flush=True)
# если есть токен — сразу заливаем на HF, чтобы не пересылать файлы token = _find_token() if token: try: from huggingface_hub import HfApi
api = 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: BLE001 print(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: ignore
return userdata.get("HF_TOKEN").strip() except Exception: # noqa: BLE001 pass local = os.path.join(HERE, "hf_token.txt") if os.path.exists(local): return open(local, encoding="utf-8").read().strip() return None
if __name__ == "__main__":ppai/colab_pposr.py+34-1