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\n",
|
| 10 |
+
"from transformers import AutoTokenizer, DataCollatorWithPadding\n",
|
| 11 |
+
"\n",
|
| 12 |
+
"raw_datasets = load_dataset(\"glue\", \"mrpc\")\n",
|
| 13 |
+
"checkpoint = \"bert-base-uncased\"\n",
|
| 14 |
+
"tokenizer = AutoTokenizer.from_pretrained(checkpoint)\n",
|
| 15 |
+
"\n",
|
| 16 |
+
"def tokenize_function(example):\n",
|
| 17 |
+
" return tokenizer(example[\"sentence1\"], example[\"sentence2\"], truncation=True)\n",
|
| 18 |
+
"\n",
|
| 19 |
+
"tokenized_datasets = raw_datasets.map(tokenize_function, batched=True)\n",
|
| 20 |
+
"data_collator = DataCollatorWithPadding(tokenizer=tokenizer)"
|
| 21 |
+
]
|
| 22 |
+
},
|
| 23 |
+
{
|
| 24 |
+
"cell_type": "code",
|
| 25 |
+
"execution_count": 24,
|
| 26 |
+
"metadata": {},
|
| 27 |
+
"outputs": [],
|
| 28 |
+
"source": [
|
| 29 |
+
"from transformers import TrainingArguments\n",
|
| 30 |
+
"\n",
|
| 31 |
+
"training_args = TrainingArguments(\n",
|
| 32 |
+
" 'test-trainer',\n",
|
| 33 |
+
" save_strategy='epoch',\n",
|
| 34 |
+
" push_to_hub=True\n",
|
| 35 |
+
")"
|
| 36 |
+
]
|
| 37 |
+
},
|
| 38 |
+
{
|
| 39 |
+
"cell_type": "code",
|
| 40 |
+
"execution_count": 26,
|
| 41 |
+
"metadata": {},
|
| 42 |
+
"outputs": [
|
| 43 |
+
{
|
| 44 |
+
"name": "stderr",
|
| 45 |
+
"output_type": "stream",
|
| 46 |
+
"text": [
|
| 47 |
+
"Some weights of BertForSequenceClassification were not initialized from the model checkpoint at bert-base-uncased and are newly initialized: ['classifier.bias', 'classifier.weight']\n",
|
| 48 |
+
"You should probably TRAIN this model on a down-stream task to be able to use it for predictions and inference.\n"
|
| 49 |
+
]
|
| 50 |
+
}
|
| 51 |
+
],
|
| 52 |
+
"source": [
|
| 53 |
+
"from transformers import AutoModelForSequenceClassification\n",
|
| 54 |
+
"\n",
|
| 55 |
+
"model = AutoModelForSequenceClassification.from_pretrained(checkpoint, num_labels=2)"
|
| 56 |
+
]
|
| 57 |
+
},
|
| 58 |
+
{
|
| 59 |
+
"cell_type": "code",
|
| 60 |
+
"execution_count": 31,
|
| 61 |
+
"metadata": {},
|
| 62 |
+
"outputs": [],
|
| 63 |
+
"source": [
|
| 64 |
+
"from transformers import Trainer\n",
|
| 65 |
+
"\n",
|
| 66 |
+
"trainer = Trainer(\n",
|
| 67 |
+
" model,\n",
|
| 68 |
+
" training_args,\n",
|
| 69 |
+
" train_dataset=tokenized_datasets['train'],\n",
|
| 70 |
+
" eval_dataset=tokenized_datasets['validation'],\n",
|
| 71 |
+
" # data_collator=data_collator, THE DEFAULT DATACOLLATOR IS DataCollatorWithPadding\n",
|
| 72 |
+
" tokenizer=tokenizer\n",
|
| 73 |
+
")"
|
| 74 |
+
]
|
| 75 |
+
},
|
| 76 |
+
{
|
| 77 |
+
"cell_type": "code",
|
| 78 |
+
"execution_count": 33,
|
| 79 |
+
"metadata": {},
|
| 80 |
+
"outputs": [
|
| 81 |
+
{
|
| 82 |
+
"data": {
|
| 83 |
+
"text/html": [
|
| 84 |
+
"\n",
|
| 85 |
+
" <div>\n",
|
| 86 |
+
" \n",
|
| 87 |
+
" <progress value='1377' max='1377' style='width:300px; height:20px; vertical-align: middle;'></progress>\n",
|
| 88 |
+
" [1377/1377 03:44, Epoch 3/3]\n",
|
| 89 |
+
" </div>\n",
|
| 90 |
+
" <table border=\"1\" class=\"dataframe\">\n",
|
| 91 |
+
" <thead>\n",
|
| 92 |
+
" <tr style=\"text-align: left;\">\n",
|
| 93 |
+
" <th>Step</th>\n",
|
| 94 |
+
" <th>Training Loss</th>\n",
|
| 95 |
+
" </tr>\n",
|
| 96 |
+
" </thead>\n",
|
| 97 |
+
" <tbody>\n",
|
| 98 |
+
" <tr>\n",
|
| 99 |
+
" <td>500</td>\n",
|
| 100 |
+
" <td>0.528100</td>\n",
|
| 101 |
+
" </tr>\n",
|
| 102 |
+
" <tr>\n",
|
| 103 |
+
" <td>1000</td>\n",
|
| 104 |
+
" <td>0.284700</td>\n",
|
| 105 |
+
" </tr>\n",
|
| 106 |
+
" </tbody>\n",
|
| 107 |
+
"</table><p>"
|
| 108 |
+
],
|
| 109 |
+
"text/plain": [
|
| 110 |
+
"<IPython.core.display.HTML object>"
|
| 111 |
+
]
|
| 112 |
+
},
|
| 113 |
+
"metadata": {},
|
| 114 |
+
"output_type": "display_data"
|
| 115 |
+
},
|
| 116 |
+
{
|
| 117 |
+
"data": {
|
| 118 |
+
"text/plain": [
|
| 119 |
+
"TrainOutput(global_step=1377, training_loss=0.33464579696489055, metrics={'train_runtime': 225.3138, 'train_samples_per_second': 48.839, 'train_steps_per_second': 6.111, 'total_flos': 405114969714960.0, 'train_loss': 0.33464579696489055, 'epoch': 3.0})"
|
| 120 |
+
]
|
| 121 |
+
},
|
| 122 |
+
"execution_count": 33,
|
| 123 |
+
"metadata": {},
|
| 124 |
+
"output_type": "execute_result"
|
| 125 |
+
}
|
| 126 |
+
],
|
| 127 |
+
"source": [
|
| 128 |
+
"trainer.train()"
|
| 129 |
+
]
|
| 130 |
+
},
|
| 131 |
+
{
|
| 132 |
+
"cell_type": "code",
|
| 133 |
+
"execution_count": 34,
|
| 134 |
+
"metadata": {},
|
| 135 |
+
"outputs": [
|
| 136 |
+
{
|
| 137 |
+
"data": {
|
| 138 |
+
"text/plain": [
|
| 139 |
+
"CommitInfo(commit_url='https://huggingface.co/dantedgp/test-trainer/commit/01f53eabc3a6811a185fdb75f9c38f3bd2368327', commit_message='End of training', commit_description='', oid='01f53eabc3a6811a185fdb75f9c38f3bd2368327', pr_url=None, pr_revision=None, pr_num=None)"
|
| 140 |
+
]
|
| 141 |
+
},
|
| 142 |
+
"execution_count": 34,
|
| 143 |
+
"metadata": {},
|
| 144 |
+
"output_type": "execute_result"
|
| 145 |
+
}
|
| 146 |
+
],
|
| 147 |
+
"source": [
|
| 148 |
+
"trainer.push_to_hub('End of training')"
|
| 149 |
+
]
|
| 150 |
+
},
|
| 151 |
+
{
|
| 152 |
+
"cell_type": "code",
|
| 153 |
+
"execution_count": 37,
|
| 154 |
+
"metadata": {},
|
| 155 |
+
"outputs": [
|
| 156 |
+
{
|
| 157 |
+
"data": {
|
| 158 |
+
"text/plain": [
|
| 159 |
+
"BertForSequenceClassification(\n",
|
| 160 |
+
" (bert): BertModel(\n",
|
| 161 |
+
" (embeddings): BertEmbeddings(\n",
|
| 162 |
+
" (word_embeddings): Embedding(30522, 768, padding_idx=0)\n",
|
| 163 |
+
" (position_embeddings): Embedding(512, 768)\n",
|
| 164 |
+
" (token_type_embeddings): Embedding(2, 768)\n",
|
| 165 |
+
" (LayerNorm): LayerNorm((768,), eps=1e-12, elementwise_affine=True)\n",
|
| 166 |
+
" (dropout): Dropout(p=0.1, inplace=False)\n",
|
| 167 |
+
" )\n",
|
| 168 |
+
" (encoder): BertEncoder(\n",
|
| 169 |
+
" (layer): ModuleList(\n",
|
| 170 |
+
" (0-11): 12 x BertLayer(\n",
|
| 171 |
+
" (attention): BertAttention(\n",
|
| 172 |
+
" (self): BertSdpaSelfAttention(\n",
|
| 173 |
+
" (query): Linear(in_features=768, out_features=768, bias=True)\n",
|
| 174 |
+
" (key): Linear(in_features=768, out_features=768, bias=True)\n",
|
| 175 |
+
" (value): Linear(in_features=768, out_features=768, bias=True)\n",
|
| 176 |
+
" (dropout): Dropout(p=0.1, inplace=False)\n",
|
| 177 |
+
" )\n",
|
| 178 |
+
" (output): BertSelfOutput(\n",
|
| 179 |
+
" (dense): Linear(in_features=768, out_features=768, bias=True)\n",
|
| 180 |
+
" (LayerNorm): LayerNorm((768,), eps=1e-12, elementwise_affine=True)\n",
|
| 181 |
+
" (dropout): Dropout(p=0.1, inplace=False)\n",
|
| 182 |
+
" )\n",
|
| 183 |
+
" )\n",
|
| 184 |
+
" (intermediate): BertIntermediate(\n",
|
| 185 |
+
" (dense): Linear(in_features=768, out_features=3072, bias=True)\n",
|
| 186 |
+
" (intermediate_act_fn): GELUActivation()\n",
|
| 187 |
+
" )\n",
|
| 188 |
+
" (output): BertOutput(\n",
|
| 189 |
+
" (dense): Linear(in_features=3072, out_features=768, bias=True)\n",
|
| 190 |
+
" (LayerNorm): LayerNorm((768,), eps=1e-12, elementwise_affine=True)\n",
|
| 191 |
+
" (dropout): Dropout(p=0.1, inplace=False)\n",
|
| 192 |
+
" )\n",
|
| 193 |
+
" )\n",
|
| 194 |
+
" )\n",
|
| 195 |
+
" )\n",
|
| 196 |
+
" (pooler): BertPooler(\n",
|
| 197 |
+
" (dense): Linear(in_features=768, out_features=768, bias=True)\n",
|
| 198 |
+
" (activation): Tanh()\n",
|
| 199 |
+
" )\n",
|
| 200 |
+
" )\n",
|
| 201 |
+
" (dropout): Dropout(p=0.1, inplace=False)\n",
|
| 202 |
+
" (classifier): Linear(in_features=768, out_features=2, bias=True)\n",
|
| 203 |
+
")"
|
| 204 |
+
]
|
| 205 |
+
},
|
| 206 |
+
"execution_count": 37,
|
| 207 |
+
"metadata": {},
|
| 208 |
+
"output_type": "execute_result"
|
| 209 |
+
}
|
| 210 |
+
],
|
| 211 |
+
"source": [
|
| 212 |
+
"trained = trainer.model\n",
|
| 213 |
+
"trained"
|
| 214 |
+
]
|
| 215 |
+
},
|
| 216 |
+
{
|
| 217 |
+
"cell_type": "code",
|
| 218 |
+
"execution_count": 41,
|
| 219 |
+
"metadata": {},
|
| 220 |
+
"outputs": [
|
| 221 |
+
{
|
| 222 |
+
"data": {
|
| 223 |
+
"application/vnd.jupyter.widget-view+json": {
|
| 224 |
+
"model_id": "506efd4d18aa4d05b4e3f2a48b5102a9",
|
| 225 |
+
"version_major": 2,
|
| 226 |
+
"version_minor": 0
|
| 227 |
+
},
|
| 228 |
+
"text/plain": [
|
| 229 |
+
"model.safetensors: 0%| | 0.00/438M [00:00<?, ?B/s]"
|
| 230 |
+
]
|
| 231 |
+
},
|
| 232 |
+
"metadata": {},
|
| 233 |
+
"output_type": "display_data"
|
| 234 |
+
},
|
| 235 |
+
{
|
| 236 |
+
"data": {
|
| 237 |
+
"text/plain": [
|
| 238 |
+
"CommitInfo(commit_url='https://huggingface.co/dantedgp/helloworld/commit/1d1921b00fac46f76e9889846966fb6463ba6ad5', commit_message='Upload BertForSequenceClassification', commit_description='', oid='1d1921b00fac46f76e9889846966fb6463ba6ad5', pr_url=None, pr_revision=None, pr_num=None)"
|
| 239 |
+
]
|
| 240 |
+
},
|
| 241 |
+
"execution_count": 41,
|
| 242 |
+
"metadata": {},
|
| 243 |
+
"output_type": "execute_result"
|
| 244 |
+
}
|
| 245 |
+
],
|
| 246 |
+
"source": [
|
| 247 |
+
"trained.push_to_hub('helloworld')"
|
| 248 |
+
]
|
| 249 |
+
},
|
| 250 |
+
{
|
| 251 |
+
"cell_type": "code",
|
| 252 |
+
"execution_count": 7,
|
| 253 |
+
"metadata": {},
|
| 254 |
+
"outputs": [
|
| 255 |
+
{
|
| 256 |
+
"data": {
|
| 257 |
+
"text/html": [],
|
| 258 |
+
"text/plain": [
|
| 259 |
+
"<IPython.core.display.HTML object>"
|
| 260 |
+
]
|
| 261 |
+
},
|
| 262 |
+
"metadata": {},
|
| 263 |
+
"output_type": "display_data"
|
| 264 |
+
},
|
| 265 |
+
{
|
| 266 |
+
"data": {
|
| 267 |
+
"text/plain": [
|
| 268 |
+
"((408, 2), (408,))"
|
| 269 |
+
]
|
| 270 |
+
},
|
| 271 |
+
"execution_count": 7,
|
| 272 |
+
"metadata": {},
|
| 273 |
+
"output_type": "execute_result"
|
| 274 |
+
}
|
| 275 |
+
],
|
| 276 |
+
"source": [
|
| 277 |
+
"predictions = trainer.predict(tokenized_datasets['validation'])\n",
|
| 278 |
+
"predictions.predictions.shape, predictions.label_ids.shape"
|
| 279 |
+
]
|
| 280 |
+
},
|
| 281 |
+
{
|
| 282 |
+
"cell_type": "code",
|
| 283 |
+
"execution_count": 8,
|
| 284 |
+
"metadata": {},
|
| 285 |
+
"outputs": [],
|
| 286 |
+
"source": [
|
| 287 |
+
"import numpy as np\n",
|
| 288 |
+
"\n",
|
| 289 |
+
"preds = np.argmax(predictions.predictions, axis=-1)"
|
| 290 |
+
]
|
| 291 |
+
},
|
| 292 |
+
{
|
| 293 |
+
"cell_type": "code",
|
| 294 |
+
"execution_count": 9,
|
| 295 |
+
"metadata": {},
|
| 296 |
+
"outputs": [
|
| 297 |
+
{
|
| 298 |
+
"data": {
|
| 299 |
+
"text/plain": [
|
| 300 |
+
"{'accuracy': 0.8627450980392157, 'f1': 0.9057239057239057}"
|
| 301 |
+
]
|
| 302 |
+
},
|
| 303 |
+
"execution_count": 9,
|
| 304 |
+
"metadata": {},
|
| 305 |
+
"output_type": "execute_result"
|
| 306 |
+
}
|
| 307 |
+
],
|
| 308 |
+
"source": [
|
| 309 |
+
"import evaluate\n",
|
| 310 |
+
"metric = evaluate.load('glue', 'mrpc')\n",
|
| 311 |
+
"metric.compute(predictions=preds, references=predictions.label_ids)"
|
| 312 |
+
]
|
| 313 |
+
},
|
| 314 |
+
{
|
| 315 |
+
"cell_type": "code",
|
| 316 |
+
"execution_count": 22,
|
| 317 |
+
"metadata": {},
|
| 318 |
+
"outputs": [
|
| 319 |
+
{
|
| 320 |
+
"data": {
|
| 321 |
+
"application/vnd.jupyter.widget-view+json": {
|
| 322 |
+
"model_id": "336e47c0a0fe4141a89683d75c0e8e94",
|
| 323 |
+
"version_major": 2,
|
| 324 |
+
"version_minor": 0
|
| 325 |
+
},
|
| 326 |
+
"text/plain": [
|
| 327 |
+
"VBox(children=(HTML(value='<center> <img\\nsrc=https://huggingface.co/front/assets/huggingface_logo-noborder.sv…"
|
| 328 |
+
]
|
| 329 |
+
},
|
| 330 |
+
"metadata": {},
|
| 331 |
+
"output_type": "display_data"
|
| 332 |
+
}
|
| 333 |
+
],
|
| 334 |
+
"source": [
|
| 335 |
+
"from huggingface_hub import notebook_login\n",
|
| 336 |
+
"\n",
|
| 337 |
+
"notebook_login()"
|
| 338 |
+
]
|
| 339 |
+
},
|
| 340 |
+
{
|
| 341 |
+
"cell_type": "code",
|
| 342 |
+
"execution_count": 47,
|
| 343 |
+
"metadata": {},
|
| 344 |
+
"outputs": [],
|
| 345 |
+
"source": [
|
| 346 |
+
"from huggingface_hub import create_repo"
|
| 347 |
+
]
|
| 348 |
+
},
|
| 349 |
+
{
|
| 350 |
+
"cell_type": "code",
|
| 351 |
+
"execution_count": 49,
|
| 352 |
+
"metadata": {},
|
| 353 |
+
"outputs": [
|
| 354 |
+
{
|
| 355 |
+
"data": {
|
| 356 |
+
"text/plain": [
|
| 357 |
+
"RepoUrl('https://huggingface.co/dantedgp/dummy-model', endpoint='https://huggingface.co', repo_type='model', repo_id='dantedgp/dummy-model')"
|
| 358 |
+
]
|
| 359 |
+
},
|
| 360 |
+
"execution_count": 49,
|
| 361 |
+
"metadata": {},
|
| 362 |
+
"output_type": "execute_result"
|
| 363 |
+
}
|
| 364 |
+
],
|
| 365 |
+
"source": [
|
| 366 |
+
"create_repo('dummy-model')"
|
| 367 |
+
]
|
| 368 |
+
},
|
| 369 |
+
{
|
| 370 |
+
"cell_type": "code",
|
| 371 |
+
"execution_count": 57,
|
| 372 |
+
"metadata": {},
|
| 373 |
+
"outputs": [
|
| 374 |
+
{
|
| 375 |
+
"ename": "RepositoryNotFoundError",
|
| 376 |
+
"evalue": "404 Client Error. (Request ID: Root=1-66814b92-084543d21a090a0d33651128;0e873452-423f-4b6f-ac06-df2e696ba2fa)\n\nRepository Not Found for url: https://huggingface.co/api/models/dantedgp/namespace/preupload/main.\nPlease make sure you specified the correct `repo_id` and `repo_type`.\nIf you are trying to access a private or gated repo, make sure you are authenticated.\nNote: Creating a commit assumes that the repo already exists on the Huggingface Hub. Please use `create_repo` if it's not the case.",
|
| 377 |
+
"output_type": "error",
|
| 378 |
+
"traceback": [
|
| 379 |
+
"\u001b[1;31m---------------------------------------------------------------------------\u001b[0m",
|
| 380 |
+
"\u001b[1;31mHTTPError\u001b[0m Traceback (most recent call last)",
|
| 381 |
+
"File \u001b[1;32mD:\\Apps\\anaconda3\\envs\\ExperimentsNew\\Lib\\site-packages\\huggingface_hub\\utils\\_errors.py:304\u001b[0m, in \u001b[0;36mhf_raise_for_status\u001b[1;34m(response, endpoint_name)\u001b[0m\n\u001b[0;32m 303\u001b[0m \u001b[38;5;28;01mtry\u001b[39;00m:\n\u001b[1;32m--> 304\u001b[0m response\u001b[38;5;241m.\u001b[39mraise_for_status()\n\u001b[0;32m 305\u001b[0m \u001b[38;5;28;01mexcept\u001b[39;00m HTTPError \u001b[38;5;28;01mas\u001b[39;00m e:\n",
|
| 382 |
+
"File \u001b[1;32mD:\\Apps\\anaconda3\\envs\\ExperimentsNew\\Lib\\site-packages\\requests\\models.py:1024\u001b[0m, in \u001b[0;36mResponse.raise_for_status\u001b[1;34m(self)\u001b[0m\n\u001b[0;32m 1023\u001b[0m \u001b[38;5;28;01mif\u001b[39;00m http_error_msg:\n\u001b[1;32m-> 1024\u001b[0m \u001b[38;5;28;01mraise\u001b[39;00m HTTPError(http_error_msg, response\u001b[38;5;241m=\u001b[39m\u001b[38;5;28mself\u001b[39m)\n",
|
| 383 |
+
"\u001b[1;31mHTTPError\u001b[0m: 404 Client Error: Not Found for url: https://huggingface.co/api/models/dantedgp/namespace/preupload/main",
|
| 384 |
+
"\nThe above exception was the direct cause of the following exception:\n",
|
| 385 |
+
"\u001b[1;31mRepositoryNotFoundError\u001b[0m Traceback (most recent call last)",
|
| 386 |
+
"Cell \u001b[1;32mIn[57], line 3\u001b[0m\n\u001b[0;32m 1\u001b[0m \u001b[38;5;28;01mfrom\u001b[39;00m \u001b[38;5;21;01mhuggingface_hub\u001b[39;00m \u001b[38;5;28;01mimport\u001b[39;00m upload_file\n\u001b[1;32m----> 3\u001b[0m upload_file(\n\u001b[0;32m 4\u001b[0m path_or_fileobj\u001b[38;5;241m=\u001b[39m\u001b[38;5;124m'\u001b[39m\u001b[38;5;124mfine_tuning.ipynb\u001b[39m\u001b[38;5;124m'\u001b[39m,\n\u001b[0;32m 5\u001b[0m path_in_repo\u001b[38;5;241m=\u001b[39m\u001b[38;5;124m'\u001b[39m\u001b[38;5;124mfine_tuning.ipynb\u001b[39m\u001b[38;5;124m'\u001b[39m,\n\u001b[0;32m 6\u001b[0m repo_id\u001b[38;5;241m=\u001b[39m\u001b[38;5;124m'\u001b[39m\u001b[38;5;124mdantedgp/namespace\u001b[39m\u001b[38;5;124m'\u001b[39m\n\u001b[0;32m 7\u001b[0m )\n",
|
| 387 |
+
"File \u001b[1;32mD:\\Apps\\anaconda3\\envs\\ExperimentsNew\\Lib\\site-packages\\huggingface_hub\\utils\\_validators.py:114\u001b[0m, in \u001b[0;36mvalidate_hf_hub_args.<locals>._inner_fn\u001b[1;34m(*args, **kwargs)\u001b[0m\n\u001b[0;32m 111\u001b[0m \u001b[38;5;28;01mif\u001b[39;00m check_use_auth_token:\n\u001b[0;32m 112\u001b[0m kwargs \u001b[38;5;241m=\u001b[39m smoothly_deprecate_use_auth_token(fn_name\u001b[38;5;241m=\u001b[39mfn\u001b[38;5;241m.\u001b[39m\u001b[38;5;18m__name__\u001b[39m, has_token\u001b[38;5;241m=\u001b[39mhas_token, kwargs\u001b[38;5;241m=\u001b[39mkwargs)\n\u001b[1;32m--> 114\u001b[0m \u001b[38;5;28;01mreturn\u001b[39;00m fn(\u001b[38;5;241m*\u001b[39margs, \u001b[38;5;241m*\u001b[39m\u001b[38;5;241m*\u001b[39mkwargs)\n",
|
| 388 |
+
"File \u001b[1;32mD:\\Apps\\anaconda3\\envs\\ExperimentsNew\\Lib\\site-packages\\huggingface_hub\\hf_api.py:1286\u001b[0m, in \u001b[0;36mfuture_compatible.<locals>._inner\u001b[1;34m(self, *args, **kwargs)\u001b[0m\n\u001b[0;32m 1283\u001b[0m \u001b[38;5;28;01mreturn\u001b[39;00m \u001b[38;5;28mself\u001b[39m\u001b[38;5;241m.\u001b[39mrun_as_future(fn, \u001b[38;5;28mself\u001b[39m, \u001b[38;5;241m*\u001b[39margs, \u001b[38;5;241m*\u001b[39m\u001b[38;5;241m*\u001b[39mkwargs)\n\u001b[0;32m 1285\u001b[0m \u001b[38;5;66;03m# Otherwise, call the function normally\u001b[39;00m\n\u001b[1;32m-> 1286\u001b[0m \u001b[38;5;28;01mreturn\u001b[39;00m fn(\u001b[38;5;28mself\u001b[39m, \u001b[38;5;241m*\u001b[39margs, \u001b[38;5;241m*\u001b[39m\u001b[38;5;241m*\u001b[39mkwargs)\n",
|
| 389 |
+
"File \u001b[1;32mD:\\Apps\\anaconda3\\envs\\ExperimentsNew\\Lib\\site-packages\\huggingface_hub\\hf_api.py:4374\u001b[0m, in \u001b[0;36mHfApi.upload_file\u001b[1;34m(self, path_or_fileobj, path_in_repo, repo_id, token, repo_type, revision, commit_message, commit_description, create_pr, parent_commit, run_as_future)\u001b[0m\n\u001b[0;32m 4366\u001b[0m commit_message \u001b[38;5;241m=\u001b[39m (\n\u001b[0;32m 4367\u001b[0m commit_message \u001b[38;5;28;01mif\u001b[39;00m commit_message \u001b[38;5;129;01mis\u001b[39;00m \u001b[38;5;129;01mnot\u001b[39;00m \u001b[38;5;28;01mNone\u001b[39;00m \u001b[38;5;28;01melse\u001b[39;00m \u001b[38;5;124mf\u001b[39m\u001b[38;5;124m\"\u001b[39m\u001b[38;5;124mUpload \u001b[39m\u001b[38;5;132;01m{\u001b[39;00mpath_in_repo\u001b[38;5;132;01m}\u001b[39;00m\u001b[38;5;124m with huggingface_hub\u001b[39m\u001b[38;5;124m\"\u001b[39m\n\u001b[0;32m 4368\u001b[0m )\n\u001b[0;32m 4369\u001b[0m operation \u001b[38;5;241m=\u001b[39m CommitOperationAdd(\n\u001b[0;32m 4370\u001b[0m path_or_fileobj\u001b[38;5;241m=\u001b[39mpath_or_fileobj,\n\u001b[0;32m 4371\u001b[0m path_in_repo\u001b[38;5;241m=\u001b[39mpath_in_repo,\n\u001b[0;32m 4372\u001b[0m )\n\u001b[1;32m-> 4374\u001b[0m commit_info \u001b[38;5;241m=\u001b[39m \u001b[38;5;28mself\u001b[39m\u001b[38;5;241m.\u001b[39mcreate_commit(\n\u001b[0;32m 4375\u001b[0m repo_id\u001b[38;5;241m=\u001b[39mrepo_id,\n\u001b[0;32m 4376\u001b[0m repo_type\u001b[38;5;241m=\u001b[39mrepo_type,\n\u001b[0;32m 4377\u001b[0m operations\u001b[38;5;241m=\u001b[39m[operation],\n\u001b[0;32m 4378\u001b[0m commit_message\u001b[38;5;241m=\u001b[39mcommit_message,\n\u001b[0;32m 4379\u001b[0m commit_description\u001b[38;5;241m=\u001b[39mcommit_description,\n\u001b[0;32m 4380\u001b[0m token\u001b[38;5;241m=\u001b[39mtoken,\n\u001b[0;32m 4381\u001b[0m revision\u001b[38;5;241m=\u001b[39mrevision,\n\u001b[0;32m 4382\u001b[0m create_pr\u001b[38;5;241m=\u001b[39mcreate_pr,\n\u001b[0;32m 4383\u001b[0m parent_commit\u001b[38;5;241m=\u001b[39mparent_commit,\n\u001b[0;32m 4384\u001b[0m )\n\u001b[0;32m 4386\u001b[0m \u001b[38;5;28;01mif\u001b[39;00m commit_info\u001b[38;5;241m.\u001b[39mpr_url \u001b[38;5;129;01mis\u001b[39;00m \u001b[38;5;129;01mnot\u001b[39;00m \u001b[38;5;28;01mNone\u001b[39;00m:\n\u001b[0;32m 4387\u001b[0m revision \u001b[38;5;241m=\u001b[39m quote(_parse_revision_from_pr_url(commit_info\u001b[38;5;241m.\u001b[39mpr_url), safe\u001b[38;5;241m=\u001b[39m\u001b[38;5;124m\"\u001b[39m\u001b[38;5;124m\"\u001b[39m)\n",
|
| 390 |
+
"File \u001b[1;32mD:\\Apps\\anaconda3\\envs\\ExperimentsNew\\Lib\\site-packages\\huggingface_hub\\utils\\_validators.py:114\u001b[0m, in \u001b[0;36mvalidate_hf_hub_args.<locals>._inner_fn\u001b[1;34m(*args, **kwargs)\u001b[0m\n\u001b[0;32m 111\u001b[0m \u001b[38;5;28;01mif\u001b[39;00m check_use_auth_token:\n\u001b[0;32m 112\u001b[0m kwargs \u001b[38;5;241m=\u001b[39m smoothly_deprecate_use_auth_token(fn_name\u001b[38;5;241m=\u001b[39mfn\u001b[38;5;241m.\u001b[39m\u001b[38;5;18m__name__\u001b[39m, has_token\u001b[38;5;241m=\u001b[39mhas_token, kwargs\u001b[38;5;241m=\u001b[39mkwargs)\n\u001b[1;32m--> 114\u001b[0m \u001b[38;5;28;01mreturn\u001b[39;00m fn(\u001b[38;5;241m*\u001b[39margs, \u001b[38;5;241m*\u001b[39m\u001b[38;5;241m*\u001b[39mkwargs)\n",
|
| 391 |
+
"File \u001b[1;32mD:\\Apps\\anaconda3\\envs\\ExperimentsNew\\Lib\\site-packages\\huggingface_hub\\hf_api.py:1286\u001b[0m, in \u001b[0;36mfuture_compatible.<locals>._inner\u001b[1;34m(self, *args, **kwargs)\u001b[0m\n\u001b[0;32m 1283\u001b[0m \u001b[38;5;28;01mreturn\u001b[39;00m \u001b[38;5;28mself\u001b[39m\u001b[38;5;241m.\u001b[39mrun_as_future(fn, \u001b[38;5;28mself\u001b[39m, \u001b[38;5;241m*\u001b[39margs, \u001b[38;5;241m*\u001b[39m\u001b[38;5;241m*\u001b[39mkwargs)\n\u001b[0;32m 1285\u001b[0m \u001b[38;5;66;03m# Otherwise, call the function normally\u001b[39;00m\n\u001b[1;32m-> 1286\u001b[0m \u001b[38;5;28;01mreturn\u001b[39;00m fn(\u001b[38;5;28mself\u001b[39m, \u001b[38;5;241m*\u001b[39margs, \u001b[38;5;241m*\u001b[39m\u001b[38;5;241m*\u001b[39mkwargs)\n",
|
| 392 |
+
"File \u001b[1;32mD:\\Apps\\anaconda3\\envs\\ExperimentsNew\\Lib\\site-packages\\huggingface_hub\\hf_api.py:3677\u001b[0m, in \u001b[0;36mHfApi.create_commit\u001b[1;34m(self, repo_id, operations, commit_message, commit_description, token, repo_type, revision, create_pr, num_threads, parent_commit, run_as_future)\u001b[0m\n\u001b[0;32m 3674\u001b[0m \u001b[38;5;66;03m# If updating twice the same file or update then delete a file in a single commit\u001b[39;00m\n\u001b[0;32m 3675\u001b[0m _warn_on_overwriting_operations(operations)\n\u001b[1;32m-> 3677\u001b[0m \u001b[38;5;28mself\u001b[39m\u001b[38;5;241m.\u001b[39mpreupload_lfs_files(\n\u001b[0;32m 3678\u001b[0m repo_id\u001b[38;5;241m=\u001b[39mrepo_id,\n\u001b[0;32m 3679\u001b[0m additions\u001b[38;5;241m=\u001b[39madditions,\n\u001b[0;32m 3680\u001b[0m token\u001b[38;5;241m=\u001b[39mtoken,\n\u001b[0;32m 3681\u001b[0m repo_type\u001b[38;5;241m=\u001b[39mrepo_type,\n\u001b[0;32m 3682\u001b[0m revision\u001b[38;5;241m=\u001b[39munquoted_revision, \u001b[38;5;66;03m# first-class methods take unquoted revision\u001b[39;00m\n\u001b[0;32m 3683\u001b[0m create_pr\u001b[38;5;241m=\u001b[39mcreate_pr,\n\u001b[0;32m 3684\u001b[0m num_threads\u001b[38;5;241m=\u001b[39mnum_threads,\n\u001b[0;32m 3685\u001b[0m free_memory\u001b[38;5;241m=\u001b[39m\u001b[38;5;28;01mFalse\u001b[39;00m, \u001b[38;5;66;03m# do not remove `CommitOperationAdd.path_or_fileobj` on LFS files for \"normal\" users\u001b[39;00m\n\u001b[0;32m 3686\u001b[0m )\n\u001b[0;32m 3687\u001b[0m files_to_copy \u001b[38;5;241m=\u001b[39m _fetch_files_to_copy(\n\u001b[0;32m 3688\u001b[0m copies\u001b[38;5;241m=\u001b[39mcopies,\n\u001b[0;32m 3689\u001b[0m repo_type\u001b[38;5;241m=\u001b[39mrepo_type,\n\u001b[1;32m (...)\u001b[0m\n\u001b[0;32m 3693\u001b[0m endpoint\u001b[38;5;241m=\u001b[39m\u001b[38;5;28mself\u001b[39m\u001b[38;5;241m.\u001b[39mendpoint,\n\u001b[0;32m 3694\u001b[0m )\n\u001b[0;32m 3695\u001b[0m commit_payload \u001b[38;5;241m=\u001b[39m _prepare_commit_payload(\n\u001b[0;32m 3696\u001b[0m operations\u001b[38;5;241m=\u001b[39moperations,\n\u001b[0;32m 3697\u001b[0m files_to_copy\u001b[38;5;241m=\u001b[39mfiles_to_copy,\n\u001b[1;32m (...)\u001b[0m\n\u001b[0;32m 3700\u001b[0m parent_commit\u001b[38;5;241m=\u001b[39mparent_commit,\n\u001b[0;32m 3701\u001b[0m )\n",
|
| 393 |
+
"File \u001b[1;32mD:\\Apps\\anaconda3\\envs\\ExperimentsNew\\Lib\\site-packages\\huggingface_hub\\hf_api.py:4153\u001b[0m, in \u001b[0;36mHfApi.preupload_lfs_files\u001b[1;34m(self, repo_id, additions, token, repo_type, revision, create_pr, num_threads, free_memory, gitignore_content)\u001b[0m\n\u001b[0;32m 4151\u001b[0m \u001b[38;5;66;03m# Check which new files are LFS\u001b[39;00m\n\u001b[0;32m 4152\u001b[0m \u001b[38;5;28;01mtry\u001b[39;00m:\n\u001b[1;32m-> 4153\u001b[0m _fetch_upload_modes(\n\u001b[0;32m 4154\u001b[0m additions\u001b[38;5;241m=\u001b[39mnew_additions,\n\u001b[0;32m 4155\u001b[0m repo_type\u001b[38;5;241m=\u001b[39mrepo_type,\n\u001b[0;32m 4156\u001b[0m repo_id\u001b[38;5;241m=\u001b[39mrepo_id,\n\u001b[0;32m 4157\u001b[0m headers\u001b[38;5;241m=\u001b[39mheaders,\n\u001b[0;32m 4158\u001b[0m revision\u001b[38;5;241m=\u001b[39mrevision,\n\u001b[0;32m 4159\u001b[0m endpoint\u001b[38;5;241m=\u001b[39m\u001b[38;5;28mself\u001b[39m\u001b[38;5;241m.\u001b[39mendpoint,\n\u001b[0;32m 4160\u001b[0m create_pr\u001b[38;5;241m=\u001b[39mcreate_pr \u001b[38;5;129;01mor\u001b[39;00m \u001b[38;5;28;01mFalse\u001b[39;00m,\n\u001b[0;32m 4161\u001b[0m gitignore_content\u001b[38;5;241m=\u001b[39mgitignore_content,\n\u001b[0;32m 4162\u001b[0m )\n\u001b[0;32m 4163\u001b[0m \u001b[38;5;28;01mexcept\u001b[39;00m RepositoryNotFoundError \u001b[38;5;28;01mas\u001b[39;00m e:\n\u001b[0;32m 4164\u001b[0m e\u001b[38;5;241m.\u001b[39mappend_to_message(_CREATE_COMMIT_NO_REPO_ERROR_MESSAGE)\n",
|
| 394 |
+
"File \u001b[1;32mD:\\Apps\\anaconda3\\envs\\ExperimentsNew\\Lib\\site-packages\\huggingface_hub\\utils\\_validators.py:114\u001b[0m, in \u001b[0;36mvalidate_hf_hub_args.<locals>._inner_fn\u001b[1;34m(*args, **kwargs)\u001b[0m\n\u001b[0;32m 111\u001b[0m \u001b[38;5;28;01mif\u001b[39;00m check_use_auth_token:\n\u001b[0;32m 112\u001b[0m kwargs \u001b[38;5;241m=\u001b[39m smoothly_deprecate_use_auth_token(fn_name\u001b[38;5;241m=\u001b[39mfn\u001b[38;5;241m.\u001b[39m\u001b[38;5;18m__name__\u001b[39m, has_token\u001b[38;5;241m=\u001b[39mhas_token, kwargs\u001b[38;5;241m=\u001b[39mkwargs)\n\u001b[1;32m--> 114\u001b[0m \u001b[38;5;28;01mreturn\u001b[39;00m fn(\u001b[38;5;241m*\u001b[39margs, \u001b[38;5;241m*\u001b[39m\u001b[38;5;241m*\u001b[39mkwargs)\n",
|
| 395 |
+
"File \u001b[1;32mD:\\Apps\\anaconda3\\envs\\ExperimentsNew\\Lib\\site-packages\\huggingface_hub\\_commit_api.py:508\u001b[0m, in \u001b[0;36m_fetch_upload_modes\u001b[1;34m(additions, repo_type, repo_id, headers, revision, endpoint, create_pr, gitignore_content)\u001b[0m\n\u001b[0;32m 500\u001b[0m payload[\u001b[38;5;124m\"\u001b[39m\u001b[38;5;124mgitIgnore\u001b[39m\u001b[38;5;124m\"\u001b[39m] \u001b[38;5;241m=\u001b[39m gitignore_content\n\u001b[0;32m 502\u001b[0m resp \u001b[38;5;241m=\u001b[39m get_session()\u001b[38;5;241m.\u001b[39mpost(\n\u001b[0;32m 503\u001b[0m \u001b[38;5;124mf\u001b[39m\u001b[38;5;124m\"\u001b[39m\u001b[38;5;132;01m{\u001b[39;00mendpoint\u001b[38;5;132;01m}\u001b[39;00m\u001b[38;5;124m/api/\u001b[39m\u001b[38;5;132;01m{\u001b[39;00mrepo_type\u001b[38;5;132;01m}\u001b[39;00m\u001b[38;5;124ms/\u001b[39m\u001b[38;5;132;01m{\u001b[39;00mrepo_id\u001b[38;5;132;01m}\u001b[39;00m\u001b[38;5;124m/preupload/\u001b[39m\u001b[38;5;132;01m{\u001b[39;00mrevision\u001b[38;5;132;01m}\u001b[39;00m\u001b[38;5;124m\"\u001b[39m,\n\u001b[0;32m 504\u001b[0m json\u001b[38;5;241m=\u001b[39mpayload,\n\u001b[0;32m 505\u001b[0m headers\u001b[38;5;241m=\u001b[39mheaders,\n\u001b[0;32m 506\u001b[0m params\u001b[38;5;241m=\u001b[39m{\u001b[38;5;124m\"\u001b[39m\u001b[38;5;124mcreate_pr\u001b[39m\u001b[38;5;124m\"\u001b[39m: \u001b[38;5;124m\"\u001b[39m\u001b[38;5;124m1\u001b[39m\u001b[38;5;124m\"\u001b[39m} \u001b[38;5;28;01mif\u001b[39;00m create_pr \u001b[38;5;28;01melse\u001b[39;00m \u001b[38;5;28;01mNone\u001b[39;00m,\n\u001b[0;32m 507\u001b[0m )\n\u001b[1;32m--> 508\u001b[0m hf_raise_for_status(resp)\n\u001b[0;32m 509\u001b[0m preupload_info \u001b[38;5;241m=\u001b[39m _validate_preupload_info(resp\u001b[38;5;241m.\u001b[39mjson())\n\u001b[0;32m 510\u001b[0m upload_modes\u001b[38;5;241m.\u001b[39mupdate(\u001b[38;5;241m*\u001b[39m\u001b[38;5;241m*\u001b[39m{file[\u001b[38;5;124m\"\u001b[39m\u001b[38;5;124mpath\u001b[39m\u001b[38;5;124m\"\u001b[39m]: file[\u001b[38;5;124m\"\u001b[39m\u001b[38;5;124muploadMode\u001b[39m\u001b[38;5;124m\"\u001b[39m] \u001b[38;5;28;01mfor\u001b[39;00m file \u001b[38;5;129;01min\u001b[39;00m preupload_info[\u001b[38;5;124m\"\u001b[39m\u001b[38;5;124mfiles\u001b[39m\u001b[38;5;124m\"\u001b[39m]})\n",
|
| 396 |
+
"File \u001b[1;32mD:\\Apps\\anaconda3\\envs\\ExperimentsNew\\Lib\\site-packages\\huggingface_hub\\utils\\_errors.py:352\u001b[0m, in \u001b[0;36mhf_raise_for_status\u001b[1;34m(response, endpoint_name)\u001b[0m\n\u001b[0;32m 333\u001b[0m \u001b[38;5;28;01melif\u001b[39;00m error_code \u001b[38;5;241m==\u001b[39m \u001b[38;5;124m\"\u001b[39m\u001b[38;5;124mRepoNotFound\u001b[39m\u001b[38;5;124m\"\u001b[39m \u001b[38;5;129;01mor\u001b[39;00m (\n\u001b[0;32m 334\u001b[0m response\u001b[38;5;241m.\u001b[39mstatus_code \u001b[38;5;241m==\u001b[39m \u001b[38;5;241m401\u001b[39m\n\u001b[0;32m 335\u001b[0m \u001b[38;5;129;01mand\u001b[39;00m response\u001b[38;5;241m.\u001b[39mrequest \u001b[38;5;129;01mis\u001b[39;00m \u001b[38;5;129;01mnot\u001b[39;00m \u001b[38;5;28;01mNone\u001b[39;00m\n\u001b[1;32m (...)\u001b[0m\n\u001b[0;32m 342\u001b[0m \u001b[38;5;66;03m# => for now, we process them as `RepoNotFound` anyway.\u001b[39;00m\n\u001b[0;32m 343\u001b[0m \u001b[38;5;66;03m# See https://gist.github.com/Wauplin/46c27ad266b15998ce56a6603796f0b9\u001b[39;00m\n\u001b[0;32m 344\u001b[0m message \u001b[38;5;241m=\u001b[39m (\n\u001b[0;32m 345\u001b[0m \u001b[38;5;124mf\u001b[39m\u001b[38;5;124m\"\u001b[39m\u001b[38;5;132;01m{\u001b[39;00mresponse\u001b[38;5;241m.\u001b[39mstatus_code\u001b[38;5;132;01m}\u001b[39;00m\u001b[38;5;124m Client Error.\u001b[39m\u001b[38;5;124m\"\u001b[39m\n\u001b[0;32m 346\u001b[0m \u001b[38;5;241m+\u001b[39m \u001b[38;5;124m\"\u001b[39m\u001b[38;5;130;01m\\n\u001b[39;00m\u001b[38;5;130;01m\\n\u001b[39;00m\u001b[38;5;124m\"\u001b[39m\n\u001b[1;32m (...)\u001b[0m\n\u001b[0;32m 350\u001b[0m \u001b[38;5;124m\"\u001b[39m\u001b[38;5;124m make sure you are authenticated.\u001b[39m\u001b[38;5;124m\"\u001b[39m\n\u001b[0;32m 351\u001b[0m )\n\u001b[1;32m--> 352\u001b[0m \u001b[38;5;28;01mraise\u001b[39;00m RepositoryNotFoundError(message, response) \u001b[38;5;28;01mfrom\u001b[39;00m \u001b[38;5;21;01me\u001b[39;00m\n\u001b[0;32m 354\u001b[0m \u001b[38;5;28;01melif\u001b[39;00m response\u001b[38;5;241m.\u001b[39mstatus_code \u001b[38;5;241m==\u001b[39m \u001b[38;5;241m400\u001b[39m:\n\u001b[0;32m 355\u001b[0m message \u001b[38;5;241m=\u001b[39m (\n\u001b[0;32m 356\u001b[0m \u001b[38;5;124mf\u001b[39m\u001b[38;5;124m\"\u001b[39m\u001b[38;5;130;01m\\n\u001b[39;00m\u001b[38;5;130;01m\\n\u001b[39;00m\u001b[38;5;124mBad request for \u001b[39m\u001b[38;5;132;01m{\u001b[39;00mendpoint_name\u001b[38;5;132;01m}\u001b[39;00m\u001b[38;5;124m endpoint:\u001b[39m\u001b[38;5;124m\"\u001b[39m \u001b[38;5;28;01mif\u001b[39;00m endpoint_name \u001b[38;5;129;01mis\u001b[39;00m \u001b[38;5;129;01mnot\u001b[39;00m \u001b[38;5;28;01mNone\u001b[39;00m \u001b[38;5;28;01melse\u001b[39;00m \u001b[38;5;124m\"\u001b[39m\u001b[38;5;130;01m\\n\u001b[39;00m\u001b[38;5;130;01m\\n\u001b[39;00m\u001b[38;5;124mBad request:\u001b[39m\u001b[38;5;124m\"\u001b[39m\n\u001b[0;32m 357\u001b[0m )\n",
|
| 397 |
+
"\u001b[1;31mRepositoryNotFoundError\u001b[0m: 404 Client Error. (Request ID: Root=1-66814b92-084543d21a090a0d33651128;0e873452-423f-4b6f-ac06-df2e696ba2fa)\n\nRepository Not Found for url: https://huggingface.co/api/models/dantedgp/namespace/preupload/main.\nPlease make sure you specified the correct `repo_id` and `repo_type`.\nIf you are trying to access a private or gated repo, make sure you are authenticated.\nNote: Creating a commit assumes that the repo already exists on the Huggingface Hub. Please use `create_repo` if it's not the case."
|
| 398 |
+
]
|
| 399 |
+
}
|
| 400 |
+
],
|
| 401 |
+
"source": [
|
| 402 |
+
"from huggingface_hub import upload_file\n",
|
| 403 |
+
"\n",
|
| 404 |
+
"upload_file(\n",
|
| 405 |
+
" path_or_fileobj='fine_tuning.ipynb',\n",
|
| 406 |
+
" path_in_repo='fine_tuning.ipynb',\n",
|
| 407 |
+
" repo_id='dantedgp/test-trainer'\n",
|
| 408 |
+
")"
|
| 409 |
+
]
|
| 410 |
+
},
|
| 411 |
+
{
|
| 412 |
+
"cell_type": "code",
|
| 413 |
+
"execution_count": 53,
|
| 414 |
+
"metadata": {},
|
| 415 |
+
"outputs": [
|
| 416 |
+
{
|
| 417 |
+
"data": {
|
| 418 |
+
"text/plain": [
|
| 419 |
+
"\u001b[1;31mSignature:\u001b[0m\n",
|
| 420 |
+
"\u001b[0mupload_file\u001b[0m\u001b[1;33m(\u001b[0m\u001b[1;33m\n",
|
| 421 |
+
"\u001b[0m \u001b[1;33m*\u001b[0m\u001b[1;33m,\u001b[0m\u001b[1;33m\n",
|
| 422 |
+
"\u001b[0m \u001b[0mpath_or_fileobj\u001b[0m\u001b[1;33m:\u001b[0m \u001b[1;34m'Union[str, Path, bytes, BinaryIO]'\u001b[0m\u001b[1;33m,\u001b[0m\u001b[1;33m\n",
|
| 423 |
+
"\u001b[0m \u001b[0mpath_in_repo\u001b[0m\u001b[1;33m:\u001b[0m \u001b[1;34m'str'\u001b[0m\u001b[1;33m,\u001b[0m\u001b[1;33m\n",
|
| 424 |
+
"\u001b[0m \u001b[0mrepo_id\u001b[0m\u001b[1;33m:\u001b[0m \u001b[1;34m'str'\u001b[0m\u001b[1;33m,\u001b[0m\u001b[1;33m\n",
|
| 425 |
+
"\u001b[0m \u001b[0mtoken\u001b[0m\u001b[1;33m:\u001b[0m \u001b[1;34m'Union[str, bool, None]'\u001b[0m \u001b[1;33m=\u001b[0m \u001b[1;32mNone\u001b[0m\u001b[1;33m,\u001b[0m\u001b[1;33m\n",
|
| 426 |
+
"\u001b[0m \u001b[0mrepo_type\u001b[0m\u001b[1;33m:\u001b[0m \u001b[1;34m'Optional[str]'\u001b[0m \u001b[1;33m=\u001b[0m \u001b[1;32mNone\u001b[0m\u001b[1;33m,\u001b[0m\u001b[1;33m\n",
|
| 427 |
+
"\u001b[0m \u001b[0mrevision\u001b[0m\u001b[1;33m:\u001b[0m \u001b[1;34m'Optional[str]'\u001b[0m \u001b[1;33m=\u001b[0m \u001b[1;32mNone\u001b[0m\u001b[1;33m,\u001b[0m\u001b[1;33m\n",
|
| 428 |
+
"\u001b[0m \u001b[0mcommit_message\u001b[0m\u001b[1;33m:\u001b[0m \u001b[1;34m'Optional[str]'\u001b[0m \u001b[1;33m=\u001b[0m \u001b[1;32mNone\u001b[0m\u001b[1;33m,\u001b[0m\u001b[1;33m\n",
|
| 429 |
+
"\u001b[0m \u001b[0mcommit_description\u001b[0m\u001b[1;33m:\u001b[0m \u001b[1;34m'Optional[str]'\u001b[0m \u001b[1;33m=\u001b[0m \u001b[1;32mNone\u001b[0m\u001b[1;33m,\u001b[0m\u001b[1;33m\n",
|
| 430 |
+
"\u001b[0m \u001b[0mcreate_pr\u001b[0m\u001b[1;33m:\u001b[0m \u001b[1;34m'Optional[bool]'\u001b[0m \u001b[1;33m=\u001b[0m \u001b[1;32mNone\u001b[0m\u001b[1;33m,\u001b[0m\u001b[1;33m\n",
|
| 431 |
+
"\u001b[0m \u001b[0mparent_commit\u001b[0m\u001b[1;33m:\u001b[0m \u001b[1;34m'Optional[str]'\u001b[0m \u001b[1;33m=\u001b[0m \u001b[1;32mNone\u001b[0m\u001b[1;33m,\u001b[0m\u001b[1;33m\n",
|
| 432 |
+
"\u001b[0m \u001b[0mrun_as_future\u001b[0m\u001b[1;33m:\u001b[0m \u001b[1;34m'bool'\u001b[0m \u001b[1;33m=\u001b[0m \u001b[1;32mFalse\u001b[0m\u001b[1;33m,\u001b[0m\u001b[1;33m\n",
|
| 433 |
+
"\u001b[0m\u001b[1;33m)\u001b[0m \u001b[1;33m->\u001b[0m \u001b[1;34m'Union[CommitInfo, Future[CommitInfo]]'\u001b[0m\u001b[1;33m\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n",
|
| 434 |
+
"\u001b[1;31mSource:\u001b[0m \n",
|
| 435 |
+
" \u001b[1;33m@\u001b[0m\u001b[0mvalidate_hf_hub_args\u001b[0m\u001b[1;33m\n",
|
| 436 |
+
"\u001b[0m \u001b[1;33m@\u001b[0m\u001b[0mfuture_compatible\u001b[0m\u001b[1;33m\n",
|
| 437 |
+
"\u001b[0m \u001b[1;32mdef\u001b[0m \u001b[0mupload_file\u001b[0m\u001b[1;33m(\u001b[0m\u001b[1;33m\n",
|
| 438 |
+
"\u001b[0m \u001b[0mself\u001b[0m\u001b[1;33m,\u001b[0m\u001b[1;33m\n",
|
| 439 |
+
"\u001b[0m \u001b[1;33m*\u001b[0m\u001b[1;33m,\u001b[0m\u001b[1;33m\n",
|
| 440 |
+
"\u001b[0m \u001b[0mpath_or_fileobj\u001b[0m\u001b[1;33m:\u001b[0m \u001b[0mUnion\u001b[0m\u001b[1;33m[\u001b[0m\u001b[0mstr\u001b[0m\u001b[1;33m,\u001b[0m \u001b[0mPath\u001b[0m\u001b[1;33m,\u001b[0m \u001b[0mbytes\u001b[0m\u001b[1;33m,\u001b[0m \u001b[0mBinaryIO\u001b[0m\u001b[1;33m]\u001b[0m\u001b[1;33m,\u001b[0m\u001b[1;33m\n",
|
| 441 |
+
"\u001b[0m \u001b[0mpath_in_repo\u001b[0m\u001b[1;33m:\u001b[0m \u001b[0mstr\u001b[0m\u001b[1;33m,\u001b[0m\u001b[1;33m\n",
|
| 442 |
+
"\u001b[0m \u001b[0mrepo_id\u001b[0m\u001b[1;33m:\u001b[0m \u001b[0mstr\u001b[0m\u001b[1;33m,\u001b[0m\u001b[1;33m\n",
|
| 443 |
+
"\u001b[0m \u001b[0mtoken\u001b[0m\u001b[1;33m:\u001b[0m \u001b[0mUnion\u001b[0m\u001b[1;33m[\u001b[0m\u001b[0mstr\u001b[0m\u001b[1;33m,\u001b[0m \u001b[0mbool\u001b[0m\u001b[1;33m,\u001b[0m \u001b[1;32mNone\u001b[0m\u001b[1;33m]\u001b[0m \u001b[1;33m=\u001b[0m \u001b[1;32mNone\u001b[0m\u001b[1;33m,\u001b[0m\u001b[1;33m\n",
|
| 444 |
+
"\u001b[0m \u001b[0mrepo_type\u001b[0m\u001b[1;33m:\u001b[0m \u001b[0mOptional\u001b[0m\u001b[1;33m[\u001b[0m\u001b[0mstr\u001b[0m\u001b[1;33m]\u001b[0m \u001b[1;33m=\u001b[0m \u001b[1;32mNone\u001b[0m\u001b[1;33m,\u001b[0m\u001b[1;33m\n",
|
| 445 |
+
"\u001b[0m \u001b[0mrevision\u001b[0m\u001b[1;33m:\u001b[0m \u001b[0mOptional\u001b[0m\u001b[1;33m[\u001b[0m\u001b[0mstr\u001b[0m\u001b[1;33m]\u001b[0m \u001b[1;33m=\u001b[0m \u001b[1;32mNone\u001b[0m\u001b[1;33m,\u001b[0m\u001b[1;33m\n",
|
| 446 |
+
"\u001b[0m \u001b[0mcommit_message\u001b[0m\u001b[1;33m:\u001b[0m \u001b[0mOptional\u001b[0m\u001b[1;33m[\u001b[0m\u001b[0mstr\u001b[0m\u001b[1;33m]\u001b[0m \u001b[1;33m=\u001b[0m \u001b[1;32mNone\u001b[0m\u001b[1;33m,\u001b[0m\u001b[1;33m\n",
|
| 447 |
+
"\u001b[0m \u001b[0mcommit_description\u001b[0m\u001b[1;33m:\u001b[0m \u001b[0mOptional\u001b[0m\u001b[1;33m[\u001b[0m\u001b[0mstr\u001b[0m\u001b[1;33m]\u001b[0m \u001b[1;33m=\u001b[0m \u001b[1;32mNone\u001b[0m\u001b[1;33m,\u001b[0m\u001b[1;33m\n",
|
| 448 |
+
"\u001b[0m \u001b[0mcreate_pr\u001b[0m\u001b[1;33m:\u001b[0m \u001b[0mOptional\u001b[0m\u001b[1;33m[\u001b[0m\u001b[0mbool\u001b[0m\u001b[1;33m]\u001b[0m \u001b[1;33m=\u001b[0m \u001b[1;32mNone\u001b[0m\u001b[1;33m,\u001b[0m\u001b[1;33m\n",
|
| 449 |
+
"\u001b[0m \u001b[0mparent_commit\u001b[0m\u001b[1;33m:\u001b[0m \u001b[0mOptional\u001b[0m\u001b[1;33m[\u001b[0m\u001b[0mstr\u001b[0m\u001b[1;33m]\u001b[0m \u001b[1;33m=\u001b[0m \u001b[1;32mNone\u001b[0m\u001b[1;33m,\u001b[0m\u001b[1;33m\n",
|
| 450 |
+
"\u001b[0m \u001b[0mrun_as_future\u001b[0m\u001b[1;33m:\u001b[0m \u001b[0mbool\u001b[0m \u001b[1;33m=\u001b[0m \u001b[1;32mFalse\u001b[0m\u001b[1;33m,\u001b[0m\u001b[1;33m\n",
|
| 451 |
+
"\u001b[0m \u001b[1;33m)\u001b[0m \u001b[1;33m->\u001b[0m \u001b[0mUnion\u001b[0m\u001b[1;33m[\u001b[0m\u001b[0mCommitInfo\u001b[0m\u001b[1;33m,\u001b[0m \u001b[0mFuture\u001b[0m\u001b[1;33m[\u001b[0m\u001b[0mCommitInfo\u001b[0m\u001b[1;33m]\u001b[0m\u001b[1;33m]\u001b[0m\u001b[1;33m:\u001b[0m\u001b[1;33m\n",
|
| 452 |
+
"\u001b[0m \u001b[1;34m\"\"\"\n",
|
| 453 |
+
" Upload a local file (up to 50 GB) to the given repo. The upload is done\n",
|
| 454 |
+
" through a HTTP post request, and doesn't require git or git-lfs to be\n",
|
| 455 |
+
" installed.\n",
|
| 456 |
+
"\n",
|
| 457 |
+
" Args:\n",
|
| 458 |
+
" path_or_fileobj (`str`, `Path`, `bytes`, or `IO`):\n",
|
| 459 |
+
" Path to a file on the local machine or binary data stream /\n",
|
| 460 |
+
" fileobj / buffer.\n",
|
| 461 |
+
" path_in_repo (`str`):\n",
|
| 462 |
+
" Relative filepath in the repo, for example:\n",
|
| 463 |
+
" `\"checkpoints/1fec34a/weights.bin\"`\n",
|
| 464 |
+
" repo_id (`str`):\n",
|
| 465 |
+
" The repository to which the file will be uploaded, for example:\n",
|
| 466 |
+
" `\"username/custom_transformers\"`\n",
|
| 467 |
+
" token (Union[bool, str, None], optional):\n",
|
| 468 |
+
" A valid user access token (string). Defaults to the locally saved\n",
|
| 469 |
+
" token, which is the recommended method for authentication (see\n",
|
| 470 |
+
" https://huggingface.co/docs/huggingface_hub/quick-start#authentication).\n",
|
| 471 |
+
" To disable authentication, pass `False`.\n",
|
| 472 |
+
" repo_type (`str`, *optional*):\n",
|
| 473 |
+
" Set to `\"dataset\"` or `\"space\"` if uploading to a dataset or\n",
|
| 474 |
+
" space, `None` or `\"model\"` if uploading to a model. Default is\n",
|
| 475 |
+
" `None`.\n",
|
| 476 |
+
" revision (`str`, *optional*):\n",
|
| 477 |
+
" The git revision to commit from. Defaults to the head of the `\"main\"` branch.\n",
|
| 478 |
+
" commit_message (`str`, *optional*):\n",
|
| 479 |
+
" The summary / title / first line of the generated commit\n",
|
| 480 |
+
" commit_description (`str` *optional*)\n",
|
| 481 |
+
" The description of the generated commit\n",
|
| 482 |
+
" create_pr (`boolean`, *optional*):\n",
|
| 483 |
+
" Whether or not to create a Pull Request with that commit. Defaults to `False`.\n",
|
| 484 |
+
" If `revision` is not set, PR is opened against the `\"main\"` branch. If\n",
|
| 485 |
+
" `revision` is set and is a branch, PR is opened against this branch. If\n",
|
| 486 |
+
" `revision` is set and is not a branch name (example: a commit oid), an\n",
|
| 487 |
+
" `RevisionNotFoundError` is returned by the server.\n",
|
| 488 |
+
" parent_commit (`str`, *optional*):\n",
|
| 489 |
+
" The OID / SHA of the parent commit, as a hexadecimal string. Shorthands (7 first characters) are also supported.\n",
|
| 490 |
+
" If specified and `create_pr` is `False`, the commit will fail if `revision` does not point to `parent_commit`.\n",
|
| 491 |
+
" If specified and `create_pr` is `True`, the pull request will be created from `parent_commit`.\n",
|
| 492 |
+
" Specifying `parent_commit` ensures the repo has not changed before committing the changes, and can be\n",
|
| 493 |
+
" especially useful if the repo is updated / committed to concurrently.\n",
|
| 494 |
+
" run_as_future (`bool`, *optional*):\n",
|
| 495 |
+
" Whether or not to run this method in the background. Background jobs are run sequentially without\n",
|
| 496 |
+
" blocking the main thread. Passing `run_as_future=True` will return a [Future](https://docs.python.org/3/library/concurrent.futures.html#future-objects)\n",
|
| 497 |
+
" object. Defaults to `False`.\n",
|
| 498 |
+
"\n",
|
| 499 |
+
"\n",
|
| 500 |
+
" Returns:\n",
|
| 501 |
+
" [`CommitInfo`] or `Future`:\n",
|
| 502 |
+
" Instance of [`CommitInfo`] containing information about the newly created commit (commit hash, commit\n",
|
| 503 |
+
" url, pr url, commit message,...). If `run_as_future=True` is passed, returns a Future object which will\n",
|
| 504 |
+
" contain the result when executed.\n",
|
| 505 |
+
" <Tip>\n",
|
| 506 |
+
"\n",
|
| 507 |
+
" Raises the following errors:\n",
|
| 508 |
+
"\n",
|
| 509 |
+
" - [`HTTPError`](https://requests.readthedocs.io/en/latest/api/#requests.HTTPError)\n",
|
| 510 |
+
" if the HuggingFace API returned an error\n",
|
| 511 |
+
" - [`ValueError`](https://docs.python.org/3/library/exceptions.html#ValueError)\n",
|
| 512 |
+
" if some parameter value is invalid\n",
|
| 513 |
+
" - [`~utils.RepositoryNotFoundError`]\n",
|
| 514 |
+
" If the repository to download from cannot be found. This may be because it doesn't exist,\n",
|
| 515 |
+
" or because it is set to `private` and you do not have access.\n",
|
| 516 |
+
" - [`~utils.RevisionNotFoundError`]\n",
|
| 517 |
+
" If the revision to download from cannot be found.\n",
|
| 518 |
+
"\n",
|
| 519 |
+
" </Tip>\n",
|
| 520 |
+
"\n",
|
| 521 |
+
" <Tip warning={true}>\n",
|
| 522 |
+
"\n",
|
| 523 |
+
" `upload_file` assumes that the repo already exists on the Hub. If you get a\n",
|
| 524 |
+
" Client error 404, please make sure you are authenticated and that `repo_id` and\n",
|
| 525 |
+
" `repo_type` are set correctly. If repo does not exist, create it first using\n",
|
| 526 |
+
" [`~hf_api.create_repo`].\n",
|
| 527 |
+
"\n",
|
| 528 |
+
" </Tip>\n",
|
| 529 |
+
"\n",
|
| 530 |
+
" Example:\n",
|
| 531 |
+
"\n",
|
| 532 |
+
" ```python\n",
|
| 533 |
+
" >>> from huggingface_hub import upload_file\n",
|
| 534 |
+
"\n",
|
| 535 |
+
" >>> with open(\"./local/filepath\", \"rb\") as fobj:\n",
|
| 536 |
+
" ... upload_file(\n",
|
| 537 |
+
" ... path_or_fileobj=fileobj,\n",
|
| 538 |
+
" ... path_in_repo=\"remote/file/path.h5\",\n",
|
| 539 |
+
" ... repo_id=\"username/my-dataset\",\n",
|
| 540 |
+
" ... repo_type=\"dataset\",\n",
|
| 541 |
+
" ... token=\"my_token\",\n",
|
| 542 |
+
" ... )\n",
|
| 543 |
+
" \"https://huggingface.co/datasets/username/my-dataset/blob/main/remote/file/path.h5\"\n",
|
| 544 |
+
"\n",
|
| 545 |
+
" >>> upload_file(\n",
|
| 546 |
+
" ... path_or_fileobj=\".\\\\\\\\local\\\\\\\\file\\\\\\\\path\",\n",
|
| 547 |
+
" ... path_in_repo=\"remote/file/path.h5\",\n",
|
| 548 |
+
" ... repo_id=\"username/my-model\",\n",
|
| 549 |
+
" ... token=\"my_token\",\n",
|
| 550 |
+
" ... )\n",
|
| 551 |
+
" \"https://huggingface.co/username/my-model/blob/main/remote/file/path.h5\"\n",
|
| 552 |
+
"\n",
|
| 553 |
+
" >>> upload_file(\n",
|
| 554 |
+
" ... path_or_fileobj=\".\\\\\\\\local\\\\\\\\file\\\\\\\\path\",\n",
|
| 555 |
+
" ... path_in_repo=\"remote/file/path.h5\",\n",
|
| 556 |
+
" ... repo_id=\"username/my-model\",\n",
|
| 557 |
+
" ... token=\"my_token\",\n",
|
| 558 |
+
" ... create_pr=True,\n",
|
| 559 |
+
" ... )\n",
|
| 560 |
+
" \"https://huggingface.co/username/my-model/blob/refs%2Fpr%2F1/remote/file/path.h5\"\n",
|
| 561 |
+
" ```\n",
|
| 562 |
+
" \"\"\"\u001b[0m\u001b[1;33m\n",
|
| 563 |
+
"\u001b[0m \u001b[1;32mif\u001b[0m \u001b[0mrepo_type\u001b[0m \u001b[1;32mnot\u001b[0m \u001b[1;32min\u001b[0m \u001b[0mREPO_TYPES\u001b[0m\u001b[1;33m:\u001b[0m\u001b[1;33m\n",
|
| 564 |
+
"\u001b[0m \u001b[1;32mraise\u001b[0m \u001b[0mValueError\u001b[0m\u001b[1;33m(\u001b[0m\u001b[1;33mf\"\u001b[0m\u001b[1;33mInvalid repo type, must be one of \u001b[0m\u001b[1;33m{\u001b[0m\u001b[0mREPO_TYPES\u001b[0m\u001b[1;33m}\u001b[0m\u001b[1;33m\"\u001b[0m\u001b[1;33m)\u001b[0m\u001b[1;33m\n",
|
| 565 |
+
"\u001b[0m\u001b[1;33m\n",
|
| 566 |
+
"\u001b[0m \u001b[0mcommit_message\u001b[0m \u001b[1;33m=\u001b[0m \u001b[1;33m(\u001b[0m\u001b[1;33m\n",
|
| 567 |
+
"\u001b[0m \u001b[0mcommit_message\u001b[0m \u001b[1;32mif\u001b[0m \u001b[0mcommit_message\u001b[0m \u001b[1;32mis\u001b[0m \u001b[1;32mnot\u001b[0m \u001b[1;32mNone\u001b[0m \u001b[1;32melse\u001b[0m \u001b[1;33mf\"\u001b[0m\u001b[1;33mUpload \u001b[0m\u001b[1;33m{\u001b[0m\u001b[0mpath_in_repo\u001b[0m\u001b[1;33m}\u001b[0m\u001b[1;33m with huggingface_hub\u001b[0m\u001b[1;33m\"\u001b[0m\u001b[1;33m\n",
|
| 568 |
+
"\u001b[0m \u001b[1;33m)\u001b[0m\u001b[1;33m\n",
|
| 569 |
+
"\u001b[0m \u001b[0moperation\u001b[0m \u001b[1;33m=\u001b[0m \u001b[0mCommitOperationAdd\u001b[0m\u001b[1;33m(\u001b[0m\u001b[1;33m\n",
|
| 570 |
+
"\u001b[0m \u001b[0mpath_or_fileobj\u001b[0m\u001b[1;33m=\u001b[0m\u001b[0mpath_or_fileobj\u001b[0m\u001b[1;33m,\u001b[0m\u001b[1;33m\n",
|
| 571 |
+
"\u001b[0m \u001b[0mpath_in_repo\u001b[0m\u001b[1;33m=\u001b[0m\u001b[0mpath_in_repo\u001b[0m\u001b[1;33m,\u001b[0m\u001b[1;33m\n",
|
| 572 |
+
"\u001b[0m \u001b[1;33m)\u001b[0m\u001b[1;33m\n",
|
| 573 |
+
"\u001b[0m\u001b[1;33m\n",
|
| 574 |
+
"\u001b[0m \u001b[0mcommit_info\u001b[0m \u001b[1;33m=\u001b[0m \u001b[0mself\u001b[0m\u001b[1;33m.\u001b[0m\u001b[0mcreate_commit\u001b[0m\u001b[1;33m(\u001b[0m\u001b[1;33m\n",
|
| 575 |
+
"\u001b[0m \u001b[0mrepo_id\u001b[0m\u001b[1;33m=\u001b[0m\u001b[0mrepo_id\u001b[0m\u001b[1;33m,\u001b[0m\u001b[1;33m\n",
|
| 576 |
+
"\u001b[0m \u001b[0mrepo_type\u001b[0m\u001b[1;33m=\u001b[0m\u001b[0mrepo_type\u001b[0m\u001b[1;33m,\u001b[0m\u001b[1;33m\n",
|
| 577 |
+
"\u001b[0m \u001b[0moperations\u001b[0m\u001b[1;33m=\u001b[0m\u001b[1;33m[\u001b[0m\u001b[0moperation\u001b[0m\u001b[1;33m]\u001b[0m\u001b[1;33m,\u001b[0m\u001b[1;33m\n",
|
| 578 |
+
"\u001b[0m \u001b[0mcommit_message\u001b[0m\u001b[1;33m=\u001b[0m\u001b[0mcommit_message\u001b[0m\u001b[1;33m,\u001b[0m\u001b[1;33m\n",
|
| 579 |
+
"\u001b[0m \u001b[0mcommit_description\u001b[0m\u001b[1;33m=\u001b[0m\u001b[0mcommit_description\u001b[0m\u001b[1;33m,\u001b[0m\u001b[1;33m\n",
|
| 580 |
+
"\u001b[0m \u001b[0mtoken\u001b[0m\u001b[1;33m=\u001b[0m\u001b[0mtoken\u001b[0m\u001b[1;33m,\u001b[0m\u001b[1;33m\n",
|
| 581 |
+
"\u001b[0m \u001b[0mrevision\u001b[0m\u001b[1;33m=\u001b[0m\u001b[0mrevision\u001b[0m\u001b[1;33m,\u001b[0m\u001b[1;33m\n",
|
| 582 |
+
"\u001b[0m \u001b[0mcreate_pr\u001b[0m\u001b[1;33m=\u001b[0m\u001b[0mcreate_pr\u001b[0m\u001b[1;33m,\u001b[0m\u001b[1;33m\n",
|
| 583 |
+
"\u001b[0m \u001b[0mparent_commit\u001b[0m\u001b[1;33m=\u001b[0m\u001b[0mparent_commit\u001b[0m\u001b[1;33m,\u001b[0m\u001b[1;33m\n",
|
| 584 |
+
"\u001b[0m \u001b[1;33m)\u001b[0m\u001b[1;33m\n",
|
| 585 |
+
"\u001b[0m\u001b[1;33m\n",
|
| 586 |
+
"\u001b[0m \u001b[1;32mif\u001b[0m \u001b[0mcommit_info\u001b[0m\u001b[1;33m.\u001b[0m\u001b[0mpr_url\u001b[0m \u001b[1;32mis\u001b[0m \u001b[1;32mnot\u001b[0m \u001b[1;32mNone\u001b[0m\u001b[1;33m:\u001b[0m\u001b[1;33m\n",
|
| 587 |
+
"\u001b[0m \u001b[0mrevision\u001b[0m \u001b[1;33m=\u001b[0m \u001b[0mquote\u001b[0m\u001b[1;33m(\u001b[0m\u001b[0m_parse_revision_from_pr_url\u001b[0m\u001b[1;33m(\u001b[0m\u001b[0mcommit_info\u001b[0m\u001b[1;33m.\u001b[0m\u001b[0mpr_url\u001b[0m\u001b[1;33m)\u001b[0m\u001b[1;33m,\u001b[0m \u001b[0msafe\u001b[0m\u001b[1;33m=\u001b[0m\u001b[1;34m\"\"\u001b[0m\u001b[1;33m)\u001b[0m\u001b[1;33m\n",
|
| 588 |
+
"\u001b[0m \u001b[1;32mif\u001b[0m \u001b[0mrepo_type\u001b[0m \u001b[1;32min\u001b[0m \u001b[0mREPO_TYPES_URL_PREFIXES\u001b[0m\u001b[1;33m:\u001b[0m\u001b[1;33m\n",
|
| 589 |
+
"\u001b[0m \u001b[0mrepo_id\u001b[0m \u001b[1;33m=\u001b[0m \u001b[0mREPO_TYPES_URL_PREFIXES\u001b[0m\u001b[1;33m[\u001b[0m\u001b[0mrepo_type\u001b[0m\u001b[1;33m]\u001b[0m \u001b[1;33m+\u001b[0m \u001b[0mrepo_id\u001b[0m\u001b[1;33m\n",
|
| 590 |
+
"\u001b[0m \u001b[0mrevision\u001b[0m \u001b[1;33m=\u001b[0m \u001b[0mrevision\u001b[0m \u001b[1;32mif\u001b[0m \u001b[0mrevision\u001b[0m \u001b[1;32mis\u001b[0m \u001b[1;32mnot\u001b[0m \u001b[1;32mNone\u001b[0m \u001b[1;32melse\u001b[0m \u001b[0mDEFAULT_REVISION\u001b[0m\u001b[1;33m\n",
|
| 591 |
+
"\u001b[0m\u001b[1;33m\n",
|
| 592 |
+
"\u001b[0m \u001b[1;32mreturn\u001b[0m \u001b[0mCommitInfo\u001b[0m\u001b[1;33m(\u001b[0m\u001b[1;33m\n",
|
| 593 |
+
"\u001b[0m \u001b[0mcommit_url\u001b[0m\u001b[1;33m=\u001b[0m\u001b[0mcommit_info\u001b[0m\u001b[1;33m.\u001b[0m\u001b[0mcommit_url\u001b[0m\u001b[1;33m,\u001b[0m\u001b[1;33m\n",
|
| 594 |
+
"\u001b[0m \u001b[0mcommit_message\u001b[0m\u001b[1;33m=\u001b[0m\u001b[0mcommit_info\u001b[0m\u001b[1;33m.\u001b[0m\u001b[0mcommit_message\u001b[0m\u001b[1;33m,\u001b[0m\u001b[1;33m\n",
|
| 595 |
+
"\u001b[0m \u001b[0mcommit_description\u001b[0m\u001b[1;33m=\u001b[0m\u001b[0mcommit_info\u001b[0m\u001b[1;33m.\u001b[0m\u001b[0mcommit_description\u001b[0m\u001b[1;33m,\u001b[0m\u001b[1;33m\n",
|
| 596 |
+
"\u001b[0m \u001b[0moid\u001b[0m\u001b[1;33m=\u001b[0m\u001b[0mcommit_info\u001b[0m\u001b[1;33m.\u001b[0m\u001b[0moid\u001b[0m\u001b[1;33m,\u001b[0m\u001b[1;33m\n",
|
| 597 |
+
"\u001b[0m \u001b[0mpr_url\u001b[0m\u001b[1;33m=\u001b[0m\u001b[0mcommit_info\u001b[0m\u001b[1;33m.\u001b[0m\u001b[0mpr_url\u001b[0m\u001b[1;33m,\u001b[0m\u001b[1;33m\n",
|
| 598 |
+
"\u001b[0m \u001b[1;31m# Similar to `hf_hub_url` but it's \"blob\" instead of \"resolve\"\u001b[0m\u001b[1;33m\n",
|
| 599 |
+
"\u001b[0m \u001b[1;31m# TODO: remove this in v1.0\u001b[0m\u001b[1;33m\n",
|
| 600 |
+
"\u001b[0m \u001b[0m_url\u001b[0m\u001b[1;33m=\u001b[0m\u001b[1;33mf\"\u001b[0m\u001b[1;33m{\u001b[0m\u001b[0mself\u001b[0m\u001b[1;33m.\u001b[0m\u001b[0mendpoint\u001b[0m\u001b[1;33m}\u001b[0m\u001b[1;33m/\u001b[0m\u001b[1;33m{\u001b[0m\u001b[0mrepo_id\u001b[0m\u001b[1;33m}\u001b[0m\u001b[1;33m/blob/\u001b[0m\u001b[1;33m{\u001b[0m\u001b[0mrevision\u001b[0m\u001b[1;33m}\u001b[0m\u001b[1;33m/\u001b[0m\u001b[1;33m{\u001b[0m\u001b[0mpath_in_repo\u001b[0m\u001b[1;33m}\u001b[0m\u001b[1;33m\"\u001b[0m\u001b[1;33m,\u001b[0m\u001b[1;33m\n",
|
| 601 |
+
"\u001b[0m \u001b[1;33m)\u001b[0m\u001b[1;33m\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n",
|
| 602 |
+
"\u001b[1;31mFile:\u001b[0m d:\\apps\\anaconda3\\envs\\experimentsnew\\lib\\site-packages\\huggingface_hub\\hf_api.py\n",
|
| 603 |
+
"\u001b[1;31mType:\u001b[0m method"
|
| 604 |
+
]
|
| 605 |
+
},
|
| 606 |
+
"metadata": {},
|
| 607 |
+
"output_type": "display_data"
|
| 608 |
+
}
|
| 609 |
+
],
|
| 610 |
+
"source": [
|
| 611 |
+
"??upload_file"
|
| 612 |
+
]
|
| 613 |
+
},
|
| 614 |
+
{
|
| 615 |
+
"cell_type": "code",
|
| 616 |
+
"execution_count": null,
|
| 617 |
+
"metadata": {},
|
| 618 |
+
"outputs": [],
|
| 619 |
+
"source": []
|
| 620 |
+
}
|
| 621 |
+
],
|
| 622 |
+
"metadata": {
|
| 623 |
+
"kernelspec": {
|
| 624 |
+
"display_name": "ExperimentsNew",
|
| 625 |
+
"language": "python",
|
| 626 |
+
"name": "experimentsnew"
|
| 627 |
+
},
|
| 628 |
+
"language_info": {
|
| 629 |
+
"codemirror_mode": {
|
| 630 |
+
"name": "ipython",
|
| 631 |
+
"version": 3
|
| 632 |
+
},
|
| 633 |
+
"file_extension": ".py",
|
| 634 |
+
"mimetype": "text/x-python",
|
| 635 |
+
"name": "python",
|
| 636 |
+
"nbconvert_exporter": "python",
|
| 637 |
+
"pygments_lexer": "ipython3",
|
| 638 |
+
"version": "3.12.3"
|
| 639 |
+
}
|
| 640 |
+
},
|
| 641 |
+
"nbformat": 4,
|
| 642 |
+
"nbformat_minor": 4
|
| 643 |
+
}
|