Upload folder using huggingface_hub
Browse files- 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(
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 18 |
|
| 19 |
-
# 2.
|
| 20 |
-
|
| 21 |
-
# We use a custom ignore list to be 100% sure
|
| 22 |
ignore_patterns = [
|
|
|
|
| 23 |
"Dataset/*",
|
|
|
|
| 24 |
"data/*",
|
| 25 |
-
".git/*",
|
| 26 |
-
"
|
|
|
|
| 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("
|
| 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()
|