You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: docs/source/guides/upload.mdx
+35-5Lines changed: 35 additions & 5 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -58,24 +58,54 @@ Specify the path of the file to upload, where you want to upload the file to in
58
58
59
59
### Upload a folder
60
60
61
-
Use the [`upload_folder`] function to upload a local folder to an existing repository. Specify the path of the local folder to upload, where you want to upload the folder to in the repository, and the name of the repository you want to add the folder to. Depending on your repository type, you can optionally set the repository type as a `dataset`, `model`, or `space`.
61
+
Use the [`upload_folder`] function to upload a local folder to an existing repository. Specify the path of the local folder
62
+
to upload, where you want to upload the folder to in the repository, and the name of the repository you want to add the
63
+
folder to. Depending on your repository type, you can optionally set the repository type as a `dataset`, `model`, or `space`.
64
+
65
+
```py
66
+
>>>from huggingface_hub import HfApi
67
+
>>> api = HfApi()
68
+
69
+
# Upload all the content from the local folder to your remote Space.
70
+
# By default, files are uploaded at the root of the repo
71
+
>>> api.upload_folder(
72
+
...folder_path="/path/to/local/space",
73
+
...repo_id="username/my-cool-space",
74
+
...repo_type="space",
75
+
... )
76
+
```
62
77
63
78
Use the `allow_patterns` and `ignore_patterns` arguments to specify which files to upload. These parameters accept either a single pattern or a list of patterns.
64
79
Patterns are Standard Wildcards (globbing patterns) as documented [here](https://tldp.org/LDP/GNU-Linux-Tools-Summary/html/x11655.htm).
65
80
If both `allow_patterns` and `ignore_patterns` are provided, both constraints apply. By default, all files from the folder are uploaded.
66
81
67
82
```py
68
-
>>>from huggingface_hub import HfApi
69
-
>>> api = HfApi()
70
83
>>> api.upload_folder(
71
84
...folder_path="/path/to/local/folder",
72
-
...path_in_repo="my-dataset/train",
85
+
...path_in_repo="my-dataset/train",# Upload to a specific folder
73
86
...repo_id="username/test-dataset",
74
87
...repo_type="dataset",
75
-
...ignore_patterns="**/logs/*.txt",
88
+
...ignore_patterns="**/logs/*.txt", # Ignore all text logs
89
+
... )
90
+
```
91
+
92
+
You can also use the `delete_patterns` argument to specify files you want to delete from the repo in the same commit.
93
+
This can prove useful if you want to clean a remote folder before pushing files in it and you don't know which files
94
+
already exists.
95
+
96
+
The example below uploads the local `./logs` folder to the remote `/experiment/logs/` folder. Only txt files are uploaded
97
+
but before that, all previous logs on the repo on deleted. All of this in a single commit.
98
+
```py
99
+
>>> api.upload_folder(
100
+
...folder_path="/path/to/local/folder/logs",
101
+
...repo_id="username/trained-model",
102
+
...path_in_repo="experiment/logs/",
103
+
...allow_patterns="*.txt", # Upload all local text files
104
+
...delete_patterns="*.txt", # Delete all remote text files before
76
105
... )
77
106
```
78
107
108
+
79
109
### create_commit
80
110
81
111
If you want to work at a commit-level, use the [`create_commit`] function directly. There are two types of operations supported by [`create_commit`]:
0 commit comments