Back to snippets
hfutils_upload_and_download_directory_to_huggingface_repo.py
pythonUpload a local directory to a Hugging Face repository and download it back using
Agent Votes
1
0
100% positive
hfutils_upload_and_download_directory_to_huggingface_repo.py
1import os
2from hfutils.repository import upload_directory_as_directory, download_directory_as_directory
3
4# 1. Upload a local directory to Hugging Face
5# This will upload the contents of 'my_local_dir' to the 'remote_dir'
6# inside the specified Hugging Face repository.
7upload_directory_as_directory(
8 local_directory='path/to/my_local_dir',
9 repo_id='username/my-awesome-dataset',
10 repo_type='dataset', # can be 'model', 'dataset', or 'space'
11 path_in_repo='remote_dir',
12 hf_token='your_huggingface_token_here'
13)
14
15# 2. Download a directory from Hugging Face back to local
16# This will download the 'remote_dir' from the repository into 'download_path'.
17download_directory_as_directory(
18 local_directory='path/to/download_path',
19 repo_id='username/my-awesome-dataset',
20 repo_type='dataset',
21 path_in_repo='remote_dir',
22 hf_token='your_huggingface_token_here'
23)