Upload folder using huggingface_hub

#2
by moja72 - opened
Bros!_Lora.safetensors → 4mand4_v2-000025.safetensors RENAMED
@@ -1,3 +1,3 @@
1
  version https://git-lfs.github.com/spec/v1
2
- oid sha256:a24bee799fe9e7536ee913a5da8b8892cd97bc2ca02a2aa3a902a92a2a1a2208
3
- size 2535602544
 
1
  version https://git-lfs.github.com/spec/v1
2
+ oid sha256:0454a3bce57112fdb9fbad17a364337a3e33ed33976defcf6616ce973682168e
3
+ size 2535602400
4mand4_v2-000050.safetensors ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:b007664bc9ac5bf8665f5e4a0142753345d10f749669ac6e482d03e2a1e0f3b2
3
+ size 2535602400
4mand4_v2-000075.safetensors ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:41caac318cd8fbea59a6877c55a05b6945ee90a48efa88f80a9731c9648881e4
3
+ size 2535602400
4mand4_v2-000100.safetensors ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:e081ba922079b286293f61598d93a69b718d8041b324c9403206d30f57f2632f
3
+ size 2535602400
4mand4_v2-000125.safetensors ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:c6ad703e452e15606e1a0c544f6bb8d14da5ee566036f9dd85600bce731ac156
3
+ size 2535602400
Hugging_Face_Upload_Download_V9.ipynb ADDED
@@ -0,0 +1,359 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ {
2
+ "cells": [
3
+ {
4
+ "cell_type": "markdown",
5
+ "id": "0abc7dd7",
6
+ "metadata": {},
7
+ "source": [
8
+ "### Master Notebook for Hugging Face repos Upload and Download V9\n",
9
+ "\n",
10
+ "### Always get latest version before starting to use : https://www.patreon.com/posts/104672510\n",
11
+ "\n",
12
+ "### Execute below cell once to install libraries\n",
13
+ "\n",
14
+ "### Don't forget to set accurate folder and file paths and repo names befor executing cells"
15
+ ]
16
+ },
17
+ {
18
+ "cell_type": "code",
19
+ "execution_count": null,
20
+ "id": "caa74bef",
21
+ "metadata": {},
22
+ "outputs": [],
23
+ "source": [
24
+ "!pip install huggingface_hub --upgrade\n",
25
+ "\n",
26
+ "!pip install ipywidgets --upgrade\n",
27
+ "\n",
28
+ "!pip install git+https://github.com/huggingface/huggingface_hub --upgrade"
29
+ ]
30
+ },
31
+ {
32
+ "cell_type": "markdown",
33
+ "id": "502249bf",
34
+ "metadata": {},
35
+ "source": [
36
+ "### Use below cell to paste your Hugging Face token key. \n",
37
+ "\n",
38
+ "### Access Tokens are here : https://huggingface.co/settings/tokens"
39
+ ]
40
+ },
41
+ {
42
+ "cell_type": "code",
43
+ "execution_count": null,
44
+ "id": "0d8027c8",
45
+ "metadata": {},
46
+ "outputs": [],
47
+ "source": [
48
+ "import os\n",
49
+ "import subprocess\n",
50
+ "import platform\n",
51
+ "\n",
52
+ "hugging_face_token = 'replace_with_your_HF_token'\n",
53
+ "\n",
54
+ "# Set the environment variable\n",
55
+ "os.environ['HUGGING_FACE_HUB_TOKEN'] = hugging_face_token\n",
56
+ "\n",
57
+ "# Determine the operating system\n",
58
+ "system = platform.system()\n",
59
+ "\n",
60
+ "if system == \"Linux\":\n",
61
+ " export_command = f'export HUGGING_FACE_HUB_TOKEN={hugging_face_token}'\n",
62
+ " subprocess.run(export_command, shell=True, check=True)\n",
63
+ "elif system == \"Windows\":\n",
64
+ " set_command = f'set HUGGING_FACE_HUB_TOKEN={hugging_face_token}'\n",
65
+ " subprocess.run(set_command, shell=True, check=True)\n",
66
+ "\n",
67
+ "# Command to log in using the token\n",
68
+ "login_command = ['huggingface-cli', 'login', '--token', hugging_face_token]\n",
69
+ "\n",
70
+ "# Execute the login command and capture output\n",
71
+ "try:\n",
72
+ " result = subprocess.run(login_command, check=True, capture_output=True, text=True)\n",
73
+ " print(\"Output:\", result.stdout)\n",
74
+ " print(\"Error:\", result.stderr)\n",
75
+ "except subprocess.CalledProcessError as e:\n",
76
+ " print(\"Command failed with exit code:\", e.returncode)\n",
77
+ " print(\"Output:\", e.output)\n",
78
+ " print(\"Error:\", e.stderr)"
79
+ ]
80
+ },
81
+ {
82
+ "cell_type": "markdown",
83
+ "id": "afb149da",
84
+ "metadata": {},
85
+ "source": [
86
+ "### Very fast new upload - Wait till UPLOAD COMPLETED printed"
87
+ ]
88
+ },
89
+ {
90
+ "cell_type": "code",
91
+ "execution_count": null,
92
+ "id": "30b96a4f",
93
+ "metadata": {},
94
+ "outputs": [],
95
+ "source": [
96
+ "!huggingface-cli upload-large-folder \"YourUserName/reponame\" r\"/home/Ubuntu/apps/StableSwarmUI/Models/Lora\" --repo-type=model --no-bars\n",
97
+ "\n",
98
+ "print(\".\\n.\\nUPLOAD COMPLETED\")"
99
+ ]
100
+ },
101
+ {
102
+ "cell_type": "markdown",
103
+ "id": "4e7a6316",
104
+ "metadata": {},
105
+ "source": [
106
+ "### Very fast new upload V2 - Wait till UPLOAD COMPLETED printed"
107
+ ]
108
+ },
109
+ {
110
+ "cell_type": "code",
111
+ "execution_count": null,
112
+ "id": "75a18901",
113
+ "metadata": {},
114
+ "outputs": [],
115
+ "source": [
116
+ "from huggingface_hub import HfApi\n",
117
+ "\n",
118
+ "api = HfApi()\n",
119
+ "\n",
120
+ "api.upload_large_folder(repo_id=\"YourUserName/reponame\", \n",
121
+ " repo_type=\"model\", \n",
122
+ " folder_path=r\"/home/Ubuntu/apps/StableSwarmUI/Models/Lora\")\n",
123
+ "\n",
124
+ "print(\".\\n.\\nUPLOAD COMPLETED\")"
125
+ ]
126
+ },
127
+ {
128
+ "cell_type": "markdown",
129
+ "id": "58da07da-2e0b-4a32-a36d-ddf511800c58",
130
+ "metadata": {},
131
+ "source": [
132
+ "### Upload a single file with specific name to remote repo - Wait till UPLOAD COMPLETED printed"
133
+ ]
134
+ },
135
+ {
136
+ "cell_type": "code",
137
+ "execution_count": null,
138
+ "id": "0502703b-8b44-4e58-af2c-82f67d713548",
139
+ "metadata": {},
140
+ "outputs": [],
141
+ "source": [
142
+ "# This cell is used to upload single file into a repo with certain name\n",
143
+ "\n",
144
+ "from huggingface_hub import HfApi\n",
145
+ "api = HfApi()\n",
146
+ "api.upload_file(\n",
147
+ " path_or_fileobj=r\"/home/Ubuntu/apps/stable-diffusion-webui/models/Stable-diffusion/model_name.safetensors\",\n",
148
+ " path_in_repo=\"model_name.safetensors\",\n",
149
+ " repo_id=\"YourUserName/reponame\",\n",
150
+ " repo_type=\"model\",\n",
151
+ ")\n",
152
+ "\n",
153
+ "print(\".\\n.\\nUPLOAD COMPLETED\")"
154
+ ]
155
+ },
156
+ {
157
+ "cell_type": "markdown",
158
+ "id": "2dd50994-5595-46a6-b315-595ede0cf922",
159
+ "metadata": {},
160
+ "source": [
161
+ "### Upload a folder fast but not suggested for too big and many files - Wait till UPLOAD COMPLETED printed"
162
+ ]
163
+ },
164
+ {
165
+ "cell_type": "code",
166
+ "execution_count": null,
167
+ "id": "a89ece44-8f27-43bb-a7fc-e966409d6f5a",
168
+ "metadata": {},
169
+ "outputs": [],
170
+ "source": [
171
+ "# This cell is used to upload a folder into a repo with single commit\n",
172
+ "\n",
173
+ "from huggingface_hub import HfApi\n",
174
+ "api = HfApi()\n",
175
+ "api.upload_folder(\n",
176
+ " folder_path=r\"/home/Ubuntu/apps/stable-diffusion-webui/models/Stable-diffusion\",\n",
177
+ " repo_id=\"YourUserName/reponame\",\n",
178
+ " repo_type=\"model\",\n",
179
+ ")\n",
180
+ "\n",
181
+ "print(\".\\n.\\nUPLOAD COMPLETED\")"
182
+ ]
183
+ },
184
+ {
185
+ "cell_type": "markdown",
186
+ "id": "4d26f8d6-31cd-42a5-9477-ba1e77cd271c",
187
+ "metadata": {},
188
+ "source": [
189
+ "### To upload all files in given folder to the target Hugging Face repository use below - Wait till UPLOAD COMPLETED printed"
190
+ ]
191
+ },
192
+ {
193
+ "cell_type": "code",
194
+ "execution_count": null,
195
+ "id": "6fc96104",
196
+ "metadata": {},
197
+ "outputs": [],
198
+ "source": [
199
+ "# This cell uploads a folder into remote repo with multi commit\n",
200
+ "# Supports continue feature so if gets interrupted you can run again to continue / resume\n",
201
+ "\n",
202
+ "from huggingface_hub import HfApi\n",
203
+ "from huggingface_hub import get_collection, delete_collection_item\n",
204
+ "from huggingface_hub import upload_file\n",
205
+ "from huggingface_hub import (\n",
206
+ " HfFolder,\n",
207
+ " ModelCard,\n",
208
+ " ModelCardData,\n",
209
+ " create_repo,\n",
210
+ " hf_hub_download,\n",
211
+ " upload_folder,\n",
212
+ " whoami,\n",
213
+ ")\n",
214
+ "api = HfApi()\n",
215
+ "upload_folder(\n",
216
+ " folder_path=r\"/home/Ubuntu/apps/stable-diffusion-webui/models/Stable-diffusion\",\n",
217
+ " repo_id=\"YourUserName/reponame\",\n",
218
+ " repo_type=\"model\",\n",
219
+ " multi_commits=True,\n",
220
+ " multi_commits_verbose=True,\n",
221
+ ")\n",
222
+ "\n",
223
+ "print(\".\\n.\\nUPLOAD COMPLETED\")"
224
+ ]
225
+ },
226
+ {
227
+ "cell_type": "markdown",
228
+ "id": "7381726f",
229
+ "metadata": {},
230
+ "source": [
231
+ "### To download all files in given Hugging Face repository use below - Wait till DOWNLOAD COMPLETED printed"
232
+ ]
233
+ },
234
+ {
235
+ "cell_type": "code",
236
+ "execution_count": null,
237
+ "id": "90f6c9b1",
238
+ "metadata": {},
239
+ "outputs": [],
240
+ "source": [
241
+ "# You can run this cell multiple times if any error occurs it will resume\n",
242
+ "\n",
243
+ "from huggingface_hub import snapshot_download\n",
244
+ "import os\n",
245
+ "\n",
246
+ "# Ensure the local directory exists\n",
247
+ "\n",
248
+ "\n",
249
+ "repo_id=\"YourUserName/reponame\"\n",
250
+ "local_dir=\"/home/Ubuntu/apps/stable-diffusion-webui/models/Stable-diffusion\"\n",
251
+ "\n",
252
+ "os.makedirs(local_dir, exist_ok=True)\n",
253
+ "\n",
254
+ "snapshot_download(repo_id=repo_id,local_dir=local_dir)\n",
255
+ "\n",
256
+ "print(\".\\n.\\nDOWNLOAD COMPLETED\")"
257
+ ]
258
+ },
259
+ {
260
+ "cell_type": "markdown",
261
+ "id": "09f0f192-4d6b-4511-8366-6c676cd2404c",
262
+ "metadata": {},
263
+ "source": [
264
+ "### Download a specific sub directory / folder - Wait till DOWNLOAD COMPLETED printed"
265
+ ]
266
+ },
267
+ {
268
+ "cell_type": "code",
269
+ "execution_count": null,
270
+ "id": "download_subdirectory",
271
+ "metadata": {},
272
+ "outputs": [],
273
+ "source": [
274
+ "# This cell downloads a specific subdirectory from a given repo\n",
275
+ "\n",
276
+ "from huggingface_hub import snapshot_download\n",
277
+ "import os\n",
278
+ "\n",
279
+ "# Define the repository and subdirectory\n",
280
+ "repo_id = \"YourUserName/reponame\"\n",
281
+ "subdirectory = \"folder_path_in_remote_repo/*\" # don't delete /* part just change folder path - if you get click to show javascript error ignore it and follow folder it will work\n",
282
+ "local_dir = \"/home/Ubuntu/apps/stable-diffusion-webui/models/Stable-diffusion\"\n",
283
+ "\n",
284
+ "# Ensure the local directory exists\n",
285
+ "os.makedirs(local_dir, exist_ok=True)\n",
286
+ "\n",
287
+ "# Download only the specific subdirectory\n",
288
+ "snapshot_download(\n",
289
+ " repo_id=repo_id,\n",
290
+ " local_dir=local_dir,\n",
291
+ " allow_patterns=subdirectory\n",
292
+ ")\n",
293
+ "\n",
294
+ "print(f\"Downloaded {subdirectory} from {repo_id} to {local_dir}\")\n",
295
+ "print(\".\\n.\\nDOWNLOAD COMPLETED\")"
296
+ ]
297
+ },
298
+ {
299
+ "cell_type": "markdown",
300
+ "id": "47b04ce9-9653-4e4f-9bd9-1b6ed383f502",
301
+ "metadata": {},
302
+ "source": [
303
+ "### Download a specific file - Wait till DOWNLOAD COMPLETED printed"
304
+ ]
305
+ },
306
+ {
307
+ "cell_type": "code",
308
+ "execution_count": null,
309
+ "id": "download_specific_file",
310
+ "metadata": {},
311
+ "outputs": [],
312
+ "source": [
313
+ "# This cell downloads a specific file from a given repo\n",
314
+ "\n",
315
+ "from huggingface_hub import hf_hub_download\n",
316
+ "import os\n",
317
+ "\n",
318
+ "# Define the repository, file path, and local directory\n",
319
+ "repo_id = \"YourUserName/reponame\"\n",
320
+ "file_path = \"folder/file_name.extension\"\n",
321
+ "local_dir = \"/home/Ubuntu/apps/stable-diffusion-webui/models/Stable-diffusion\"\n",
322
+ "\n",
323
+ "# Ensure the local directory exists\n",
324
+ "os.makedirs(local_dir, exist_ok=True)\n",
325
+ "\n",
326
+ "# Download the specific file\n",
327
+ "file_path_local = hf_hub_download(\n",
328
+ " repo_id=repo_id,\n",
329
+ " filename=file_path,\n",
330
+ " local_dir=local_dir\n",
331
+ ")\n",
332
+ "\n",
333
+ "print(f\"Downloaded {file_path} from {repo_id} to {file_path_local}\")\n",
334
+ "print(\".\\n.\\nDOWNLOAD COMPLETED\")"
335
+ ]
336
+ }
337
+ ],
338
+ "metadata": {
339
+ "kernelspec": {
340
+ "display_name": "Python 3",
341
+ "language": "python",
342
+ "name": "python3"
343
+ },
344
+ "language_info": {
345
+ "codemirror_mode": {
346
+ "name": "ipython",
347
+ "version": 3
348
+ },
349
+ "file_extension": ".py",
350
+ "mimetype": "text/x-python",
351
+ "name": "python",
352
+ "nbconvert_exporter": "python",
353
+ "pygments_lexer": "ipython3",
354
+ "version": "3.9.16"
355
+ }
356
+ },
357
+ "nbformat": 4,
358
+ "nbformat_minor": 5
359
+ }
nsfw_flux_lora_v1.safetensors → Lora2 - 40steps - FORGE Realistic/00000-3713422574.png RENAMED
File without changes
Lora2 - 40steps - FORGE Realistic/00004-3713422578.png ADDED

Git LFS Details

  • SHA256: d448cb8bb235a9f47077650450503acef4d423a70ae6d530a002e5e7c3342cea
  • Pointer size: 132 Bytes
  • Size of remote file: 1.49 MB
Lora2 - 40steps - FORGE Realistic/00007-3713422581.png ADDED

Git LFS Details

  • SHA256: 6e3c7473351cae6c39582001f485eeb6abee24beebae2c85d1b59a6c5dea4078
  • Pointer size: 132 Bytes
  • Size of remote file: 1.6 MB
Lora2 - 40steps - FORGE Realistic/00008-3713422582.png ADDED

Git LFS Details

  • SHA256: 4da76e4cbb7cf55221bf5710b4876a1bb57982ff7843d39bef94be702ec52abd
  • Pointer size: 132 Bytes
  • Size of remote file: 1.41 MB
Lora2 - 40steps - FORGE Realistic/00009-3713422583.png ADDED

Git LFS Details

  • SHA256: b59e517f58b98d2e9934b3b1b3e5adfd1ff0d79bb519bbeaf8b5214d3cebc6ae
  • Pointer size: 132 Bytes
  • Size of remote file: 1.57 MB
Lora2 - 40steps - FORGE Realistic/Top/00000-911273068.png ADDED

Git LFS Details

  • SHA256: d84cd32dfa38d2ea5d9f5671ab3ea0e1f5fc144a2f09a5678c52ab7a6e878e66
  • Pointer size: 132 Bytes
  • Size of remote file: 1.36 MB
Lora2 - 40steps - FORGE Realistic/Top/00001-3713422575.png ADDED

Git LFS Details

  • SHA256: 295d97df2019b63250a393fc71ceb6046b74fa24e305476843af16a5016d5684
  • Pointer size: 132 Bytes
  • Size of remote file: 1.62 MB
Lora2 - 40steps - FORGE Realistic/Top/00001-911273069.png ADDED

Git LFS Details

  • SHA256: ed2534a6c897b638eff0d7cabc0e0b4047ccfc1043546cc90ae21d15f11b5699
  • Pointer size: 132 Bytes
  • Size of remote file: 1.39 MB
Lora2 - 40steps - FORGE Realistic/Top/00002-3713422576.png ADDED

Git LFS Details

  • SHA256: 089b63a921f7348d1bf65c2dc263b9306cb8081d137e7ed1c7f51d19e25c18ba
  • Pointer size: 132 Bytes
  • Size of remote file: 1.37 MB
Lora2 - 40steps - FORGE Realistic/Top/00002-911273070.png ADDED

Git LFS Details

  • SHA256: da65bd3e187609b91adb53b9498461c4e1fa1ede2c4fe4d7f921856f7468bc26
  • Pointer size: 132 Bytes
  • Size of remote file: 1.3 MB
Lora2 - 40steps - FORGE Realistic/Top/00003-3713422577.png ADDED

Git LFS Details

  • SHA256: 5701513f8c2ca063fd998277419171820c234f7d129ce76ab60e12af9256ed4c
  • Pointer size: 132 Bytes
  • Size of remote file: 1.41 MB
Lora2 - 40steps - FORGE Realistic/Top/00005-3713422579.png ADDED

Git LFS Details

  • SHA256: 277e5e0b1f9316b49a6353165a3875625f25193e1cebac7474b8cb10b178f6be
  • Pointer size: 132 Bytes
  • Size of remote file: 1.53 MB
Lora2 - 40steps - FORGE Realistic/Top/00006-3713422580.png ADDED

Git LFS Details

  • SHA256: ece335b398fdf79c01b9f6d807fb16f66c9900f07ae3c4d9b30650ee1e3d9e32
  • Pointer size: 132 Bytes
  • Size of remote file: 1.46 MB