Upload dataset_upload.py with huggingface_hub
Browse files- dataset_upload.py +38 -0
dataset_upload.py
ADDED
|
@@ -0,0 +1,38 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import os
|
| 2 |
+
from huggingface_hub import upload_file, list_repo_files
|
| 3 |
+
from tqdm import tqdm
|
| 4 |
+
|
| 5 |
+
# === CONFIGURATION ===
|
| 6 |
+
local_folder = "./" # Replace with your local folder
|
| 7 |
+
repo_id = "unibuc-cs/Emotion3DFromAction" # Replace with your dataset repo
|
| 8 |
+
repo_type = "dataset"
|
| 9 |
+
target_folder_in_repo = "" # e.g., "data/" or "" for root
|
| 10 |
+
|
| 11 |
+
# === Get list of existing files in the repo ===
|
| 12 |
+
existing_files = list_repo_files(repo_id=repo_id, repo_type=repo_type)
|
| 13 |
+
|
| 14 |
+
# === UPLOAD FUNCTION ===
|
| 15 |
+
def upload_folder(local_folder, repo_id, target_folder_in_repo=""):
|
| 16 |
+
for root, _, files in os.walk(local_folder):
|
| 17 |
+
for filename in tqdm(files, desc="Uploading files"):
|
| 18 |
+
local_path = os.path.join(root, filename)
|
| 19 |
+
relative_path = os.path.relpath(local_path, start=local_folder)
|
| 20 |
+
hf_path = os.path.join(target_folder_in_repo, relative_path).replace("\\", "/") # for Windows paths
|
| 21 |
+
|
| 22 |
+
if hf_path in existing_files:
|
| 23 |
+
print(f"Skipped (already exists): {hf_path}")
|
| 24 |
+
continue
|
| 25 |
+
|
| 26 |
+
try:
|
| 27 |
+
upload_file(
|
| 28 |
+
path_or_fileobj=local_path,
|
| 29 |
+
path_in_repo=hf_path,
|
| 30 |
+
repo_id=repo_id,
|
| 31 |
+
repo_type="dataset",
|
| 32 |
+
)
|
| 33 |
+
print(f"Uploaded: {hf_path}")
|
| 34 |
+
except Exception as e:
|
| 35 |
+
print(f"Failed to upload {hf_path}: {e}")
|
| 36 |
+
|
| 37 |
+
# === RUN UPLOAD ===
|
| 38 |
+
upload_folder(local_folder, repo_id, target_folder_in_repo)
|