{ "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", "\n", " \"Open\n", "\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": [] } ] }