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": []
    }
  ]
}