File size: 1,188 Bytes
44a2260
 
bcd4e66
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
44a2260
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
---

license: cc-by-nc-4.0

**License:** cc-by-nc-4.0

Below is an example of downloading a folder from our repository.

## Installation

To run the example code, you need to install the following package:

```bash
pip install huggingface_hub

The following script demonstrates how to download a directory from the Hugging Face Hub:

from huggingface_hub import HfApi, hf_hub_download
import os
import shutil

REPO_ID = "BGLab/FlowBench"
DIRECTORY = "LDC_NS_2D"

# Initialize the Hugging Face API
api = HfApi()

# List files in the directory
files_list = api.list_repo_files(repo_id=REPO_ID, repo_type="dataset")

# Filter the files in the specified directory
files_to_download = [f for f in files_list if f.startswith(DIRECTORY)]

# Create local directory if it doesn't exist
os.makedirs(DIRECTORY, exist_ok=True)

# Download each file
for file in files_to_download:
    file_path = hf_hub_download(repo_id=REPO_ID, filename=file, repo_type="dataset")
    # Copy the file to the local directory using shutil.copy2
    shutil.copy2(file_path, os.path.join(DIRECTORY, os.path.basename(file_path)))

print("Files downloaded successfully.")


---