LearningPaper24 / update_hf_dataset.py
vivianchen98's picture
Update file: update_hf_dataset.py
d258705 verified
raw
history blame
1.81 kB
from huggingface_hub import HfApi
import os
import glob
def update_huggingface_dataset(repo_name, repo_type="dataset"):
"""
Update/overwrite files in an existing Hugging Face dataset repository,
excluding the video subfolder.
Args:
repo_name (str): Name of the repository (format: "username/repo-name")
repo_type (str): Type of repository ("dataset" or "model")
"""
# Initialize the Hugging Face API
api = HfApi()
try:
# Get the current directory (root of the repository)
repo_root = "/nas/pohan/datasets/AIConfVideo/learningpaper24"
# Get all files and directories except the video folder
files_to_upload = []
for root, dirs, files in os.walk(repo_root):
# Skip the video directory
if "video" in dirs:
dirs.remove("video")
for file in files:
file_path = os.path.join(root, file)
rel_path = os.path.relpath(file_path, repo_root)
files_to_upload.append((file_path, rel_path))
# Upload each file individually
for file_path, rel_path in files_to_upload:
api.upload_file(
path_or_fileobj=file_path,
path_in_repo=rel_path,
repo_id=repo_name,
repo_type=repo_type,
commit_message=f"Update file: {rel_path}",
)
print(f"Uploaded: {rel_path}")
print(f"Successfully updated all files (except video folder) in {repo_name}")
except Exception as e:
print(f"Error occurred: {str(e)}")
if __name__ == "__main__":
# Replace with your repository name
REPO_NAME = "vivianchen98/LearningPaper24" # Your dataset repository name
update_huggingface_dataset(REPO_NAME)