vivianchen98 commited on
Commit
f355e04
·
verified ·
1 Parent(s): 5929f61

Update file: update_hf_dataset.py

Browse files
Files changed (1) hide show
  1. update_hf_dataset.py +55 -0
update_hf_dataset.py ADDED
@@ -0,0 +1,55 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
+ for file in files:
30
+ file_path = os.path.join(root, file)
31
+ rel_path = os.path.relpath(file_path, repo_root)
32
+ files_to_upload.append((file_path, rel_path))
33
+
34
+ # Upload each file individually
35
+ for file_path, rel_path in files_to_upload:
36
+ api.upload_file(
37
+ path_or_fileobj=file_path,
38
+ path_in_repo=rel_path,
39
+ repo_id=repo_name,
40
+ repo_type=repo_type,
41
+ commit_message=f"Update file: {rel_path}",
42
+ )
43
+ print(f"Uploaded: {rel_path}")
44
+
45
+ print(f"Successfully updated all files (except video folder) in {repo_name}")
46
+
47
+ except Exception as e:
48
+ print(f"Error occurred: {str(e)}")
49
+
50
+
51
+ if __name__ == "__main__":
52
+ # Replace with your repository name
53
+ REPO_NAME = "vivianchen98/LearningPaper24" # Your dataset repository name
54
+
55
+ update_huggingface_dataset(REPO_NAME)