File size: 23,229 Bytes
3d65c27 |
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 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 |
{
"nbformat": 4,
"nbformat_minor": 0,
"metadata": {
"colab": {
"private_outputs": true,
"provenance": [],
"collapsed_sections": [
"IZ_JYwvBLrg-",
"PNF2kdyeO3Dn"
]
},
"kernelspec": {
"name": "python3",
"display_name": "Python 3"
},
"language_info": {
"name": "python"
}
},
"cells": [
{
"cell_type": "markdown",
"source": [
"# ๐ HuggingFace Backup - Colab Edition\n",
"\n",
"Hey there, fellow adventurers in AI! Welcome to our delightfully unique corner of the universe! โจ\n",
"\n",
"## ๐ซ What's This All About?\n",
"This is our cozy mashup of Nocrypt's notebook and everyday AI tools, but with our own special twist! Think of it as the Colab-flavored version of our Jupyter notebook - because sometimes you need your AI magic on the go!\n",
"\n",
"### ๐ฏ Quick Features:\n",
"- Fast uploads to HuggingFace (because waiting is overrated!)\n",
"- Focus on checkpoints (keeping it simple and sweet)\n",
"- Built for Google Colab (our cloud-powered playground)\n",
"- All the same magic as our Jupyter version, just with cloud sprinkles! โจ\n",
"\n",
"## ๐ Lost & Found\n",
"- Repo doing a disappearing act? [Find us on GitHub!](https://github.com/duskfallcrew/HuggingFace_Backup)\n",
"- CivitAI friends: Updates drop faster than a cat chasing a laser!\n",
"\n",
"## โ Support the Magic\n",
"[![ko-fi](https://ko-fi.com/img/githubbutton_sm.svg)](https://ko-fi.com/Z8Z8L4EO)\n",
"\n",
"## ๐ฎ Join Our Adventure!\n",
"We're a system of 300+ alters, rocking life with DID, ADHD, Autism, and CPTSD. We believe AI can be a game-changer for mental health and creativity. Come explore with us!\n",
"\n",
"### ๐ Find Us Here:\n",
"- ๐ [End Media](https://www.end-media.org/)\n",
"- ๐ฎ [Discord](https://discord.gg/5t2kYxt7An)\n",
"- ๐ค [HuggingFace](https://huggingface.co/EarthnDusk)\n",
"- ๐ต [YouTube](https://www.youtube.com/channel/UCk7MGP7nrJz5awBSP75xmVw)\n",
"- ๐ช [Reddit](https://www.reddit.com/r/earthndusk/)\n",
"- ๐จ [DeviantArt](https://www.deviantart.com/diffusionai)\n",
"\n",
"### ๐ดโโ ๏ธ Special Thanks To:\n",
"- [Pirate Diffusion](https://www.piratediffusion.com/)\n",
"- [Yodayo](https://yodayo.com/)\n",
"\n",
"## ๐ Credits & Cool People\n",
"Huge thanks to our code ancestors:\n",
"- EVERYDREAM2 TRAINER\n",
"- LINAQRUF\n",
"- NOCRYPT [![](https://dcbadge.vercel.app/api/shield/442099748669751297?style=flat)](https://lookup.guru/442099748669751297)\n",
"\n",
"Want more AI adventures? Check out the original SD Colab:\n",
"<a target=\"_blank\" href=\"https://colab.research.google.com/drive/1wEa-tS10h4LlDykd87TF5zzpXIIQoCmq\">\n",
" <img src=\"https://colab.research.google.com/assets/colab-badge.svg\" alt=\"Open In Colab\"/>\n",
"</a>\n",
"\n",
"## ๐ ๏ธ Need Help?\n",
"- Found a bug? Don't panic! Drop by our GitHub or Discord\n",
"- Questions? We're here for you!\n",
"- Want to help? Pull requests are like hugs - always welcome!\n",
"\n",
"## ๐ฏ Recent Updates:\n",
"1. ๐ Enhanced Colab compatibility\n",
"2. ๐ง Streamlined file handling\n",
"3. ๐จ Made everything prettier (because we can!)\n",
"4. ๐ Clearer instructions (no more confusion!)\n",
"5. โจ Added extra sprinkles of magic\n",
"\n",
"Remember: We're not pro coders, we're creative problem solvers! Sometimes the best solutions come with a side of chaos and a sprinkle of adventure! ๐โจ\n",
"\n",
"Let's make some AI magic happen! Ready to dive in? ๐"
],
"metadata": {
"id": "CxgFI41UGzRu"
}
},
{
"cell_type": "markdown",
"source": [
"# Google Drive Mount\n",
"\n"
],
"metadata": {
"id": "IZ_JYwvBLrg-"
}
},
{
"cell_type": "code",
"source": [
"# @title ๐ Connect Your Google Drive\n",
"# @markdown ## Let's Get Your Storage Powers Activated! โจ\n",
"\n",
"# @markdown ### What's This All About?\n",
"# @markdown Hey there, fellow creator! Before we dive into the fun stuff, let's talk storage!\n",
"\n",
"# @markdown #### ๐ฏ Your Options:\n",
"# @markdown 1. **Google Drive** (Recommended!)\n",
"# @markdown - Perfect for keeping your models safe\n",
"# @markdown - Easy access to all your files\n",
"# @markdown - Everything stays organized\n",
"# @markdown\n",
"# @markdown 2. **Alternative Routes** (For the adventurous!)\n",
"# @markdown - Terminal wizardry (if you're comfortable with commands)\n",
"# @markdown - Direct uploads to Colab\n",
"# @markdown - Other cloud storage solutions\n",
"# @markdown\n",
"# @markdown #### ๐ Pro Tips:\n",
"# @markdown - Watch for the popup after clicking \"Connect\"\n",
"# @markdown - You'll need to authorize access (don't worry, it's safe!)\n",
"# @markdown - Your drive will appear as `/content/drive`\n",
"\n",
"from google.colab import drive\n",
"from google.colab import output\n",
"import os\n",
"\n",
"def mount_drive():\n",
" if not os.path.exists('/content/drive'):\n",
" print(\"๐ฎ Summoning your Google Drive...\")\n",
" drive.mount('/content/drive')\n",
" print(\"\\nโจ Drive mounted successfully! You're ready to rock!\")\n",
" else:\n",
" print(\"๐ Your Drive is already connected and ready to go!\")\n",
"\n",
"# Enable our magical widgets\n",
"output.enable_custom_widget_manager()\n",
"\n",
"# Let's get that drive connected!\n",
"mount_drive()\n",
"\n",
"print(\"\"\"\n",
"๐ Quick Navigation Guide:\n",
"- Your Drive lives at: /content/drive\n",
"- Main workspace: /content/drive/MyDrive\n",
"- Look for the folder icon in the left sidebar\n",
"\n",
"Need to upload files?\n",
"1. Find the folder icon on the left\n",
"2. Navigate to your drive\n",
"3. Drag and drop your files\n",
"4. Magic happens! โจ\n",
"\n",
"Having troubles? No worries! You can:\n",
"1. Try reconnecting (run this cell again)\n",
"2. Use terminal commands if you're feeling brave\n",
"3. Direct upload to Colab (look for the folder icon!)\n",
"\n",
"Remember: Your creative journey is valid, no matter which path you choose! ๐\n",
"\"\"\")\n"
],
"metadata": {
"id": "cGrPfIjkH-rQ",
"cellView": "form"
},
"execution_count": null,
"outputs": []
},
{
"cell_type": "markdown",
"source": [
"# Installation & Requirements\n",
"-----------------\n",
"\n"
],
"metadata": {
"id": "J_I_G6_i0rIM"
}
},
{
"cell_type": "code",
"source": [
"# @title ๐ ๏ธ Installation Wizard\n",
"# @markdown ## Let's get your workspace ready for some AI magic! โจ\n",
"\n",
"# @markdown ### What's in the Box?\n",
"# @markdown - Hugging Face Hub (for all your model adventures)\n",
"# @markdown - IPython Widgets (for a prettier interface)\n",
"# @markdown - Essential file handling tools\n",
"\n",
"print(\"๐ Starting the setup process...\")\n",
"\n",
"def check_and_install(package, install_name=None, verbose=False):\n",
" \"\"\"Checks if a package is installed and installs it if needed.\"\"\"\n",
" import importlib\n",
" if install_name is None:\n",
" install_name = package\n",
" try:\n",
" importlib.import_module(package)\n",
" print(f\"โ
{package} is already installed.\")\n",
" except ImportError:\n",
" print(f\"๐ฆ Installing {package}...\")\n",
" if verbose:\n",
" !pip install {install_name}\n",
" else:\n",
" !pip install -q {install_name}\n",
" print(f\"โจ {package} installed successfully.\")\n",
" except Exception as e:\n",
" print(f\"โ An error occurred during install of {package}: {e}\")\n",
"\n",
"# Packages needed for our project\n",
"required_packages = {\n",
" 'huggingface_hub': '--force-reinstall huggingface_hub', #Reinstalls if exists\n",
" 'ipywidgets': 'ipywidgets',\n",
" 'glob': 'glob', # Changed to glob, since glob2 is not essential here\n",
" 'tqdm': 'tqdm' # Install tqdm\n",
"}\n",
"\n",
"# Run installations\n",
"for package, install_cmd in required_packages.items():\n",
" check_and_install(package, install_cmd, verbose=True) #Turn verbose output on\n",
"\n",
"# Clean up output\n",
"from IPython.display import clear_output\n",
"clear_output()\n",
"\n",
"print(\"\"\"\n",
"๐ All set! Here's a summary of what was installed:\n",
"\n",
"๐ค Hugging Face Hub - Your portal to model magic\n",
"๐จ IPython Widgets - To make things pretty\n",
"๐ File Handling - Tools to keep things organized\n",
"๐ Progress Bars - For better tracking of uploads\n",
"\n",
"Having issues? Here's a checklist:\n",
"1. Try running this cell again\n",
"2. Ensure your Colab runtime is not encountering errors\n",
"3. If still wonky, drop by our Discord for help!\n",
"\n",
"Let's make some AI magic! ๐\n",
"\"\"\")"
],
"metadata": {
"cellView": "form",
"id": "Nhi-k9j30ssE"
},
"execution_count": null,
"outputs": []
},
{
"cell_type": "code",
"source": [
"# @title ๐ Connect to Hugging Face Hub - Enhanced\n",
"# @markdown ## Let's get you logged into your Hugging Face account! โจ\n",
"\n",
"# @markdown ### Quick Guide:\n",
"# @markdown 1. **New User?** Head over to [Hugging Face](https://huggingface.co/) and create a free account.\n",
"# @markdown 2. **Get Your Token:** Visit your [tokens page](https://huggingface.co/settings/tokens).\n",
"# @markdown 3. **Create a Token:** Click 'New Token' or copy an existing one (ensure it has `Write` access).\n",
"# @markdown 4. **Paste Below:** Copy and paste your token into the field below.\n",
"\n",
"print(\"โจ Checking Hugging Face connection...\")\n",
"\n",
"# Check if hub_ok exists, set it if not\n",
"try:\n",
" hub_ok\n",
"except NameError:\n",
" print(\"๐ฆ Installing huggingface_hub (if needed)...\")\n",
" !pip install --force-reinstall -q huggingface_hub\n",
" hub_ok = True\n",
"\n",
"from IPython.display import clear_output\n",
"from huggingface_hub import login\n",
"clear_output() #clear the output\n",
"\n",
"# @markdown ### ๐ Your Hugging Face Token\n",
"write_token = \"\" # @param {type:\"string\"}\n",
"\n",
"try:\n",
" if write_token:\n",
" print(\"๐ Logging you in with your Hugging Face token...\")\n",
" login(write_token, add_to_git_credential=True)\n",
" print(\"๐ Successfully logged in to Hugging Face! Your powers are activated!\")\n",
" print(\"๐ซ You're ready to upload models and files.\")\n",
" else:\n",
" print(\"โ ๏ธ No token was provided. Please paste your Hugging Face token above.\")\n",
"except Exception as e:\n",
" print(\"โ Login failed. Please check the following:\")\n",
" print(f\" 1. Ensure your token is correct and has 'Write' access.\")\n",
" print(f\" 2. The error is: {e}\")\n",
" print(\"๐ค If you're still having problems, visit our Discord for help!\")\n",
" raise"
],
"metadata": {
"cellView": "form",
"id": "1B8DZ_p8IcNh"
},
"execution_count": null,
"outputs": []
},
{
"cell_type": "code",
"source": [
"# @title ๐๏ธ Repository Setup Wizard - Enhanced\n",
"# @markdown ### Let's get your Hugging Face repository ready! โจ\n",
"\n",
"from huggingface_hub.utils import validate_repo_id, HfHubHTTPError\n",
"from huggingface_hub import HfApi\n",
"import os\n",
"\n",
"# @markdown #### ๐จ Customize Your Repository\n",
"repo_name = \"\" # @param {type:\"string\"}\n",
"make_private = False # @param {type:\"boolean\"} {description:\"Keep your repo private?\"}\n",
"clone_repo = True # @param {type:\"boolean\"} {description:\"Download repo to Colab?\"}\n",
"\n",
"print(\"๐ ๏ธ Setting up your Hugging Face repository...\")\n",
"\n",
"try:\n",
" # Initialize the Hugging Face API\n",
" api = HfApi()\n",
" user = api.whoami()\n",
" model_repo = f\"{user['name']}/{repo_name.strip()}\"\n",
"\n",
" # Validate the repository name\n",
" print(f\"๐ Validating repository name: '{model_repo}'\")\n",
" validate_repo_id(model_repo)\n",
"\n",
" # Create or check the repository\n",
" print(\"๐ฆ Creating repository if it doesn't exist...\")\n",
" api.create_repo(\n",
" repo_id=model_repo,\n",
" private=make_private,\n",
" exist_ok=True\n",
" )\n",
" print(f\"๐ Repository '{model_repo}' is ready for action!\")\n",
"\n",
" # Clone the repository if requested\n",
" if clone_repo:\n",
" print(\"\\n๐ฆ Cloning your repository (with LFS)...\")\n",
" clone_path = f\"/content/{repo_name.strip()}\"\n",
"\n",
" if os.path.exists(clone_path):\n",
" print(f\"โ ๏ธ Repository already exists at '{clone_path}'. Skipping clone step.\")\n",
" else:\n",
" !git lfs install --skip-smudge\n",
" !export GIT_LFS_SKIP_SMUDGE=1\n",
" !git clone https://huggingface.co/{model_repo} {clone_path}\n",
" print(\"โจ Repository cloned successfully!\")\n",
"\n",
"except Exception as e:\n",
" print(f\"โ An error occurred during repository setup: {e}\")\n",
" raise\n",
"\n",
"print(\"โ
Repository setup complete!\")"
],
"metadata": {
"id": "J851eLx6Ii3h"
},
"execution_count": null,
"outputs": []
},
{
"cell_type": "code",
"source": [
"# @title ๐ Hugging Face File Uploader - Interactive\n",
"# @markdown ## ๐ Ready to Upload Your Files to Hugging Face?\n",
"\n",
"# @markdown ### Quick Guide:\n",
"# @markdown 1. Fill in your Hugging Face `Organization/Username` and `Repository name`.\n",
"# @markdown 2. Specify the directory to search in below.\n",
"# @markdown 3. Select the files you want to upload using the file picker below.\n",
"# @markdown 4. Click the `Upload` button to begin the upload process.\n",
"\n",
"# @markdown ### Pro Tips:\n",
"# @markdown - If files are missing, ensure they are in the current directory.\n",
"# @markdown - Use Ctrl/Cmd to select multiple files.\n",
"# @markdown - Customize the commit message.\n",
"\n",
"import os\n",
"import glob\n",
"import time\n",
"from pathlib import Path\n",
"from huggingface_hub import HfApi\n",
"from IPython.display import display, HTML, clear_output, Image\n",
"from tqdm.notebook import tqdm\n",
"from ipywidgets import *\n",
"\n",
"# @markdown ### ๐ Repository Details\n",
"hfuser = \"\" # @param {type:\"string\"} {description: \"Your Hugging Face Username or Organization\"}\n",
"hfrepo = \"\" # @param {type:\"string\"} {description: \"Your Hugging Face Repository Name\"}\n",
"\n",
"# @markdown ### ๐๏ธ File Settings\n",
"file_type = \"mp3\" # @param [\"safetensors\", \"pt\", \"mp3\", \"pth\", \"onnx\", \"pb\", \"h5\", \"ckpt\", \"bin\", \"json\", \"yaml\", \"yml\", \"txt\", \"csv\", \"pkl\", \"png\", \"jpg\", \"jpeg\", \"webp\", \"gif\", \"zip\", \"tar\", \"gz\", \"mp3\", \"wav\", \"ogg\", \"mp4\", \"mov\", \"avi\", \"mkv\"]\n",
"#sort_by = \"name\" # @param [\"name\", \"date\"]\n",
"\n",
"# @markdown ### ๐ File Location\n",
"file_location = \"\" # @param {type:\"string\"} {description: \"The directory to search for files\"}\n",
"\n",
"# @markdown ### ๐ญ Upload Settings\n",
"commit_message = \"Upload with Earth & Dusk Huggingface ๐ค Backup\" # @param {type:\"string\"}\n",
"create_pr = False # @param {type:\"boolean\"}\n",
"clear_after = True # @param {type:\"boolean\"}\n",
"\n",
"\n",
"def format_size(size):\n",
" \"\"\"Formats a file size into a human-readable string.\"\"\"\n",
" for unit in ['B', 'KB', 'MB', 'GB']:\n",
" if size < 1024:\n",
" return f\"{size:.2f} {unit}\"\n",
" size /= 1024\n",
" return f\"{size:.2f} TB\"\n",
"\n",
"def find_files(file_location, file_type):\n",
" \"\"\"Finds files matching the selected file type in the given directory.\"\"\"\n",
" try:\n",
" files = sorted(\n",
" glob.glob(os.path.join(file_location, f\"*.{file_type}\")),\n",
" key=os.path.getmtime if sort_by == 'date' else str\n",
" )\n",
" return files\n",
" except Exception as e:\n",
" print(f\"โ Error finding files: {e}\")\n",
" return []\n",
"\n",
"# Widget Setup\n",
"all_ckpts = find_files(file_location, file_type)\n",
"ckpt_picker = SelectMultiple(options=all_ckpts, layout=Layout(width=\"600px\"), description=\"Select File(s)\")\n",
"upload_btn = Button(description='Upload')\n",
"out = Output()\n",
"\n",
"def upload_ckpts(_):\n",
" repo_id = f\"{hfuser}/{hfrepo}\"\n",
" with out:\n",
" if not ckpt_picker.value:\n",
" print(\"Nothing selected for upload, make sure to click one of the files in the list, or verify there are files in the specified directory.\")\n",
" return\n",
" for ckpt in ckpt_picker.value:\n",
" print(f\"Uploading to HF: huggingface.co/{repo_id}/{os.path.basename(ckpt)}\")\n",
" size = os.path.getsize(ckpt)\n",
" print(f\"๐ฆ Uploading file: {ckpt} ({format_size(size)})\")\n",
"\n",
" try:\n",
" start_time = time.time()\n",
" response = api.upload_file(\n",
" path_or_fileobj=ckpt,\n",
" path_in_repo=os.path.basename(ckpt),\n",
" repo_id=repo_id,\n",
" repo_type=None,\n",
" create_pr=create_pr,\n",
" commit_message=commit_message\n",
" )\n",
" duration = time.time() - start_time\n",
" print(f\"โ
Upload completed in {duration:.1f} seconds\")\n",
" except Exception as e:\n",
" print(f\"โ Error uploading {ckpt}: {e}\")\n",
" print(\"\\nโจ All uploads complete!\")\n",
" if create_pr:\n",
" print(\"๐ Check your repository for the new Pull Request!\")\n",
" else:\n",
" print(\"๐ Files have been uploaded directly to your repository!\")\n",
" if clear_after:\n",
" time.sleep(3)\n",
" clear_output()\n",
"\n",
"\n",
"upload_btn.on_click(upload_ckpts)\n",
"\n",
"# Display widgets\n",
"box = VBox([\n",
" ckpt_picker,\n",
" HBox([\n",
" Label(\"HF User:\"),\n",
" Text(value = hfuser, placeholder='YourUSERHERE', disabled = True),\n",
" Label(\"HF Repo:\"),\n",
" Text(value = hfrepo, placeholder='ModelNameHere', disabled = True),\n",
" ]),\n",
" HBox([\n",
" Label(\"File Directory:\"),\n",
" Text(value = file_location, placeholder='/content', disabled = True),\n",
" ]),\n",
" upload_btn,\n",
" out,\n",
"\n",
"])\n",
"\n",
"display(box)\n",
"\n",
"# Helper function for updating the displayed file path\n",
"def update_file_list(event):\n",
" global all_ckpts\n",
" all_ckpts = find_files(file_location, file_type)\n",
" ckpt_picker.options = all_ckpts\n",
"\n",
"def on_file_type_change(change):\n",
" global all_ckpts\n",
" all_ckpts = find_files(file_location, change.new)\n",
" ckpt_picker.options = all_ckpts\n",
"\n",
"#Observe for file path changes\n",
"observe_file_path = Text(value=\"/content\")\n",
"observe_file_path.observe(update_file_list, names='value')\n",
"\n",
"#Observe for file type changes\n",
"observe_file_type = Dropdown(options=[\"safetensors\", \"pt\", \"pth\", \"mp3\", \"onnx\", \"pb\", \"h5\", \"ckpt\", \"bin\", \"json\", \"yaml\", \"yml\", \"txt\", \"csv\", \"pkl\", \"png\", \"jpg\", \"jpeg\", \"webp\", \"gif\", \"zip\", \"tar\", \"gz\", \"mp3\", \"wav\", \"ogg\", \"mp4\", \"mov\", \"avi\", \"mkv\"], value = file_type)\n",
"observe_file_type.observe(on_file_type_change, names='value')\n",
"display(HBox([Label(\"File Type:\"), observe_file_type]))"
],
"metadata": {
"id": "lucnlbQQCBZd"
},
"execution_count": null,
"outputs": []
}
]
} |