Sean676 commited on
Commit
701ddb5
·
verified ·
1 Parent(s): 1409538

Upload upload_to_hf.py with huggingface_hub

Browse files
Files changed (1) hide show
  1. upload_to_hf.py +60 -0
upload_to_hf.py ADDED
@@ -0,0 +1,60 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ from huggingface_hub import HfApi
2
+ import os
3
+ from pathlib import Path
4
+
5
+ def upload_dataset_to_hf():
6
+ # Configuration
7
+ dataset_name = "cv_proj" # Replace with your dataset name
8
+ username = "Sean676" # Replace with your Hugging Face username
9
+ repo_id = f"{username}/{dataset_name}"
10
+
11
+ # Initialize API
12
+ api = HfApi()
13
+
14
+ # Create dataset repository
15
+ try:
16
+ repo_url = api.create_repo(
17
+ repo_id=repo_id,
18
+ repo_type="dataset",
19
+ private=False, # Set to True if you want private dataset
20
+ exist_ok=True
21
+ )
22
+ print(f"Repository created/verified: {repo_url}")
23
+ except Exception as e:
24
+ print(f"Error creating repository: {e}")
25
+ print("Please check:")
26
+ print("1. You are logged in with correct token")
27
+ print("2. Your username 'ys' is correct")
28
+ print("3. You have permission to create datasets")
29
+ return
30
+
31
+ # Upload files
32
+ dataset_path = Path(".")
33
+ files_to_upload = []
34
+
35
+ # Add all files recursively
36
+ for file_path in dataset_path.rglob("*"):
37
+ if file_path.is_file() and not file_path.name.startswith('.'):
38
+ files_to_upload.append(str(file_path))
39
+
40
+ # Upload each file
41
+ for file_path in files_to_upload:
42
+ try:
43
+ # Get relative path
44
+ rel_path = os.path.relpath(file_path, dataset_path)
45
+
46
+ # Upload file
47
+ api.upload_file(
48
+ path_or_fileobj=file_path,
49
+ path_in_repo=rel_path,
50
+ repo_id=repo_id,
51
+ repo_type="dataset"
52
+ )
53
+ print(f"Uploaded: {rel_path}")
54
+ except Exception as e:
55
+ print(f"Failed to upload {file_path}: {e}")
56
+
57
+ print("Upload completed!")
58
+
59
+ if __name__ == "__main__":
60
+ upload_dataset_to_hf()