Upload commit_review_model_to_public_repo.ipynb
Browse files
gemma4_training/commit_review_model_to_public_repo.ipynb
ADDED
|
@@ -0,0 +1,117 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
{
|
| 2 |
+
"nbformat": 4,
|
| 3 |
+
"nbformat_minor": 0,
|
| 4 |
+
"metadata": {
|
| 5 |
+
"colab": {
|
| 6 |
+
"provenance": []
|
| 7 |
+
},
|
| 8 |
+
"kernelspec": {
|
| 9 |
+
"name": "python3",
|
| 10 |
+
"display_name": "Python 3"
|
| 11 |
+
},
|
| 12 |
+
"language_info": {
|
| 13 |
+
"name": "python"
|
| 14 |
+
}
|
| 15 |
+
},
|
| 16 |
+
"cells": [
|
| 17 |
+
{
|
| 18 |
+
"cell_type": "code",
|
| 19 |
+
"execution_count": null,
|
| 20 |
+
"metadata": {
|
| 21 |
+
"id": "2KiA3HOvxFB0"
|
| 22 |
+
},
|
| 23 |
+
"outputs": [],
|
| 24 |
+
"source": [
|
| 25 |
+
"\n",
|
| 26 |
+
"import os\n",
|
| 27 |
+
"from pathlib import Path\n",
|
| 28 |
+
"from huggingface_hub import snapshot_download, HfApi, get_token\n",
|
| 29 |
+
"\n",
|
| 30 |
+
"# Configuration\n",
|
| 31 |
+
"SOURCE_REPO = \"codeShare/kromoss-lora-exports\"\n",
|
| 32 |
+
"SOURCE_FOLDER = \"gemma4_lora_to_review/95_percent\"\n",
|
| 33 |
+
"\n",
|
| 34 |
+
"DEST_REPO = \"codeShare/gemma-4-E2B-it-heretic-image-caption-adapter\"\n",
|
| 35 |
+
"\n",
|
| 36 |
+
"# 1. Authenticate with Hugging Face\n",
|
| 37 |
+
"HF_TOKEN = os.environ.get(\"HF_TOKEN\") or get_token()\n",
|
| 38 |
+
"\n",
|
| 39 |
+
"if not HF_TOKEN:\n",
|
| 40 |
+
" try:\n",
|
| 41 |
+
" from google.colab import userdata\n",
|
| 42 |
+
" HF_TOKEN = userdata.get(\"HF_TOKEN\")\n",
|
| 43 |
+
" except Exception:\n",
|
| 44 |
+
" pass\n",
|
| 45 |
+
"\n",
|
| 46 |
+
"if not HF_TOKEN:\n",
|
| 47 |
+
" raise RuntimeError(\"Hugging Face API token is required.\")\n",
|
| 48 |
+
"\n",
|
| 49 |
+
"api = HfApi(token=HF_TOKEN)\n",
|
| 50 |
+
"\n",
|
| 51 |
+
"# 2. Download ALL files from the source folder\n",
|
| 52 |
+
"print(f\"Downloading {SOURCE_FOLDER} from {SOURCE_REPO}...\")\n",
|
| 53 |
+
"\n",
|
| 54 |
+
"local_download_dir = Path(\"./downloaded_adapter_95\")\n",
|
| 55 |
+
"\n",
|
| 56 |
+
"snapshot_download(\n",
|
| 57 |
+
" repo_id=SOURCE_REPO,\n",
|
| 58 |
+
" repo_type=\"model\",\n",
|
| 59 |
+
" allow_patterns=[\n",
|
| 60 |
+
" f\"{SOURCE_FOLDER}/**\",\n",
|
| 61 |
+
" f\"{SOURCE_FOLDER}/*\"\n",
|
| 62 |
+
" ],\n",
|
| 63 |
+
" local_dir=str(local_download_dir),\n",
|
| 64 |
+
" token=HF_TOKEN\n",
|
| 65 |
+
")\n",
|
| 66 |
+
"\n",
|
| 67 |
+
"actual_folder = local_download_dir / SOURCE_FOLDER\n",
|
| 68 |
+
"\n",
|
| 69 |
+
"if not actual_folder.exists():\n",
|
| 70 |
+
" raise FileNotFoundError(\n",
|
| 71 |
+
" f\"Could not locate downloaded folder: {actual_folder}\"\n",
|
| 72 |
+
" )\n",
|
| 73 |
+
"\n",
|
| 74 |
+
"# 3. Collect EVERY file recursively\n",
|
| 75 |
+
"files_to_upload = [\n",
|
| 76 |
+
" p for p in actual_folder.rglob(\"*\")\n",
|
| 77 |
+
" if p.is_file()\n",
|
| 78 |
+
"]\n",
|
| 79 |
+
"\n",
|
| 80 |
+
"if not files_to_upload:\n",
|
| 81 |
+
" raise RuntimeError(\"No files found to upload!\")\n",
|
| 82 |
+
"\n",
|
| 83 |
+
"print(f\"\\nFound {len(files_to_upload)} files:\")\n",
|
| 84 |
+
"\n",
|
| 85 |
+
"for p in files_to_upload:\n",
|
| 86 |
+
" print(f\" {p.relative_to(actual_folder)}\")\n",
|
| 87 |
+
"\n",
|
| 88 |
+
"# 4. Ensure destination repository exists\n",
|
| 89 |
+
"api.create_repo(\n",
|
| 90 |
+
" repo_id=DEST_REPO,\n",
|
| 91 |
+
" repo_type=\"model\",\n",
|
| 92 |
+
" private=False,\n",
|
| 93 |
+
" exist_ok=True\n",
|
| 94 |
+
")\n",
|
| 95 |
+
"\n",
|
| 96 |
+
"# 5. Upload ALL files and their subdirectories\n",
|
| 97 |
+
"print(f\"\\nUploading {len(files_to_upload)} files to {DEST_REPO}...\")\n",
|
| 98 |
+
"\n",
|
| 99 |
+
"upload_response = api.upload_folder(\n",
|
| 100 |
+
" repo_id=DEST_REPO,\n",
|
| 101 |
+
" repo_type=\"model\",\n",
|
| 102 |
+
" folder_path=str(actual_folder),\n",
|
| 103 |
+
" path_in_repo=\"\",\n",
|
| 104 |
+
" commit_message=(\n",
|
| 105 |
+
" \"Upload all files from gemma4_lora_to_review/95_percent\"\n",
|
| 106 |
+
" ),\n",
|
| 107 |
+
" ignore_patterns=[]\n",
|
| 108 |
+
")\n",
|
| 109 |
+
"\n",
|
| 110 |
+
"print(\"\\nUpload completed successfully!\")\n",
|
| 111 |
+
"print(\"Destination:\", f\"https://huggingface.co/{DEST_REPO}\")\n",
|
| 112 |
+
"print(\"Files uploaded:\", len(files_to_upload))\n",
|
| 113 |
+
"print(\"Response:\", upload_response)\n"
|
| 114 |
+
]
|
| 115 |
+
}
|
| 116 |
+
]
|
| 117 |
+
}
|