Update file: update_hf_dataset.py
Browse files- update_hf_dataset.py +59 -0
update_hf_dataset.py
ADDED
@@ -0,0 +1,59 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
from huggingface_hub import HfApi
|
2 |
+
import os
|
3 |
+
import glob
|
4 |
+
|
5 |
+
|
6 |
+
def update_huggingface_dataset(repo_name, repo_type="dataset"):
|
7 |
+
"""
|
8 |
+
Update/overwrite files in an existing Hugging Face dataset repository,
|
9 |
+
excluding the video subfolder.
|
10 |
+
|
11 |
+
Args:
|
12 |
+
repo_name (str): Name of the repository (format: "username/repo-name")
|
13 |
+
repo_type (str): Type of repository ("dataset" or "model")
|
14 |
+
"""
|
15 |
+
# Initialize the Hugging Face API
|
16 |
+
api = HfApi()
|
17 |
+
|
18 |
+
try:
|
19 |
+
# Get the current directory (root of the repository)
|
20 |
+
repo_root = "/nas/pohan/datasets/AIConfVideo/learningpaper24"
|
21 |
+
|
22 |
+
# Get all files and directories except the video folder
|
23 |
+
files_to_upload = []
|
24 |
+
for root, dirs, files in os.walk(repo_root):
|
25 |
+
# Skip the video directory
|
26 |
+
if "video" in dirs:
|
27 |
+
dirs.remove("video")
|
28 |
+
|
29 |
+
# also skip this script
|
30 |
+
if root.endswith("update_hf_dataset.py"):
|
31 |
+
continue
|
32 |
+
|
33 |
+
for file in files:
|
34 |
+
file_path = os.path.join(root, file)
|
35 |
+
rel_path = os.path.relpath(file_path, repo_root)
|
36 |
+
files_to_upload.append((file_path, rel_path))
|
37 |
+
|
38 |
+
# Upload each file individually
|
39 |
+
for file_path, rel_path in files_to_upload:
|
40 |
+
api.upload_file(
|
41 |
+
path_or_fileobj=file_path,
|
42 |
+
path_in_repo=rel_path,
|
43 |
+
repo_id=repo_name,
|
44 |
+
repo_type=repo_type,
|
45 |
+
commit_message=f"Update file: {rel_path}",
|
46 |
+
)
|
47 |
+
print(f"Uploaded: {rel_path}")
|
48 |
+
|
49 |
+
print(f"Successfully updated all files (except video folder) in {repo_name}")
|
50 |
+
|
51 |
+
except Exception as e:
|
52 |
+
print(f"Error occurred: {str(e)}")
|
53 |
+
|
54 |
+
|
55 |
+
if __name__ == "__main__":
|
56 |
+
# Replace with your repository name
|
57 |
+
REPO_NAME = "vivianchen98/LearningPaper24" # Your dataset repository name
|
58 |
+
|
59 |
+
update_huggingface_dataset(REPO_NAME)
|