d-e-e-k-11 commited on
Commit
50c3eb1
·
verified ·
1 Parent(s): 90644ee

Upload folder using huggingface_hub

Browse files
Files changed (1) hide show
  1. upload_to_hf.py +17 -10
upload_to_hf.py CHANGED
@@ -14,36 +14,43 @@ def upload():
14
  try:
15
  # 1. Create the repo if it doesn't exist
16
  print(f"Checking if repo {REPO_ID} exists...")
17
- create_repo(repo_id=REPO_ID, repo_type="space", space_sdk="docker", exist_ok=True)
 
 
 
 
 
18
 
19
- # 2. Upload the folder while ignoring the large dataset
20
- print("Hashing files and uploading (ignoring Dataset/ and data/)...")
21
- # We use a custom ignore list to be 100% sure
22
  ignore_patterns = [
 
23
  "Dataset/*",
 
24
  "data/*",
25
- ".git/*",
26
- "__pycache__/*",
 
27
  "*.pyc",
28
  "training_history.png",
29
  "history.json"
30
  ]
31
 
 
 
32
  api.upload_folder(
33
  folder_path=".",
34
  repo_id=REPO_ID,
35
  repo_type="space",
36
- ignore_patterns=ignore_patterns,
37
- delete_patterns=None # Set to "Dataset/*" etc if you want to clean remote
38
  )
39
 
40
  print(f"\nSuccess! Your app is live at: https://huggingface.co/spaces/{REPO_ID}")
41
- print("Note: It may take a few minutes for the Docker container to build on Hugging Face.")
42
 
43
  except Exception as e:
44
  print(f"\nError: {e}")
45
  print("\nIf you are not logged in, run: huggingface-cli login")
46
- print("Or provide a token in the script.")
47
 
48
  if __name__ == "__main__":
49
  upload()
 
14
  try:
15
  # 1. Create the repo if it doesn't exist
16
  print(f"Checking if repo {REPO_ID} exists...")
17
+ create_repo(
18
+ repo_id=REPO_ID,
19
+ repo_type="space",
20
+ space_sdk="docker",
21
+ exist_ok=True
22
+ )
23
 
24
+ # 2. Define files to ignore
25
+ # We explicitly exclude the 41k+ images in Dataset/ to avoid hashing crashes
 
26
  ignore_patterns = [
27
+ "Dataset/**/*",
28
  "Dataset/*",
29
+ "data/**/*",
30
  "data/*",
31
+ ".git/**/*",
32
+ ".git/*",
33
+ "__pycache__/**/*",
34
  "*.pyc",
35
  "training_history.png",
36
  "history.json"
37
  ]
38
 
39
+ # 3. Use upload_folder (which handles multi-part uploads for large files internally)
40
+ print("Uploading project files (skipping large datasets)...")
41
  api.upload_folder(
42
  folder_path=".",
43
  repo_id=REPO_ID,
44
  repo_type="space",
45
+ ignore_patterns=ignore_patterns
 
46
  )
47
 
48
  print(f"\nSuccess! Your app is live at: https://huggingface.co/spaces/{REPO_ID}")
49
+ print("The build process will start automatically.")
50
 
51
  except Exception as e:
52
  print(f"\nError: {e}")
53
  print("\nIf you are not logged in, run: huggingface-cli login")
 
54
 
55
  if __name__ == "__main__":
56
  upload()