Ali Rabeh - staff commited on
Commit
bcd4e66
·
1 Parent(s): 1b9587b

edited README.md

Browse files
Files changed (1) hide show
  1. README.md +42 -0
README.md CHANGED
@@ -1,3 +1,45 @@
1
  ---
2
  license: cc-by-nc-4.0
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
3
  ---
 
1
  ---
2
  license: cc-by-nc-4.0
3
+
4
+ **License:** cc-by-nc-4.0
5
+
6
+ Below is an example of downloading a folder from our repository.
7
+
8
+ ## Installation
9
+
10
+ To run the example code, you need to install the following package:
11
+
12
+ ```bash
13
+ pip install huggingface_hub
14
+
15
+ The following script demonstrates how to download a directory from the Hugging Face Hub:
16
+
17
+ from huggingface_hub import HfApi, hf_hub_download
18
+ import os
19
+ import shutil
20
+
21
+ REPO_ID = "BGLab/FlowBench"
22
+ DIRECTORY = "LDC_NS_2D"
23
+
24
+ # Initialize the Hugging Face API
25
+ api = HfApi()
26
+
27
+ # List files in the directory
28
+ files_list = api.list_repo_files(repo_id=REPO_ID, repo_type="dataset")
29
+
30
+ # Filter the files in the specified directory
31
+ files_to_download = [f for f in files_list if f.startswith(DIRECTORY)]
32
+
33
+ # Create local directory if it doesn't exist
34
+ os.makedirs(DIRECTORY, exist_ok=True)
35
+
36
+ # Download each file
37
+ for file in files_to_download:
38
+ file_path = hf_hub_download(repo_id=REPO_ID, filename=file, repo_type="dataset")
39
+ # Copy the file to the local directory using shutil.copy2
40
+ shutil.copy2(file_path, os.path.join(DIRECTORY, os.path.basename(file_path)))
41
+
42
+ print("Files downloaded successfully.")
43
+
44
+
45
  ---