Upload upload.py with huggingface_hub
Browse files
upload.py
ADDED
|
@@ -0,0 +1,112 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
#!/usr/bin/env python3
|
| 2 |
+
"""
|
| 3 |
+
Script to upload VidChain project to Hugging Face Hub
|
| 4 |
+
"""
|
| 5 |
+
|
| 6 |
+
import os
|
| 7 |
+
from huggingface_hub import login, create_repo, HfApi
|
| 8 |
+
from pathlib import Path
|
| 9 |
+
|
| 10 |
+
def upload_to_huggingface():
|
| 11 |
+
# Step 1: Login to Hugging Face
|
| 12 |
+
print("🔐 Logging in to Hugging Face Hub...")
|
| 13 |
+
login() # This will prompt for your token if not already logged in
|
| 14 |
+
|
| 15 |
+
# Step 2: Configuration
|
| 16 |
+
repo_id = "simplecloud/VidChain-exercise" # Change this to your desired repo name
|
| 17 |
+
repo_type = "dataset" # Can be "space", "dataset", or "model"
|
| 18 |
+
|
| 19 |
+
# Step 3: Create repository if it doesn't exist
|
| 20 |
+
print(f"📦 Creating repository: {repo_id}")
|
| 21 |
+
try:
|
| 22 |
+
create_repo(
|
| 23 |
+
repo_id=repo_id,
|
| 24 |
+
repo_type=repo_type,
|
| 25 |
+
exist_ok=True,
|
| 26 |
+
private=False # Set to True if you want a private repo
|
| 27 |
+
)
|
| 28 |
+
print(f"✅ Repository created/verified: {repo_id}")
|
| 29 |
+
except Exception as e:
|
| 30 |
+
print(f"⚠️ Repository creation issue: {e}")
|
| 31 |
+
|
| 32 |
+
# Step 4: Initialize HfApi
|
| 33 |
+
api = HfApi()
|
| 34 |
+
|
| 35 |
+
# Step 5: Upload the entire project folder
|
| 36 |
+
print("📤 Uploading project files...")
|
| 37 |
+
current_dir = Path(".")
|
| 38 |
+
|
| 39 |
+
# Define files/folders to upload
|
| 40 |
+
files_to_upload = [
|
| 41 |
+
"upload.py",
|
| 42 |
+
".gitignore",
|
| 43 |
+
"asset/",
|
| 44 |
+
"VTimeLLM/"
|
| 45 |
+
]
|
| 46 |
+
|
| 47 |
+
# Upload each file/folder
|
| 48 |
+
for item in files_to_upload:
|
| 49 |
+
item_path = current_dir / item
|
| 50 |
+
if item_path.exists():
|
| 51 |
+
if item_path.is_file():
|
| 52 |
+
print(f"📄 Uploading file: {item}")
|
| 53 |
+
try:
|
| 54 |
+
api.upload_file(
|
| 55 |
+
path_or_fileobj=str(item_path),
|
| 56 |
+
path_in_repo=item,
|
| 57 |
+
repo_id=repo_id,
|
| 58 |
+
repo_type=repo_type
|
| 59 |
+
)
|
| 60 |
+
print(f"✅ Successfully uploaded: {item}")
|
| 61 |
+
except Exception as e:
|
| 62 |
+
print(f"❌ Failed to upload {item}: {e}")
|
| 63 |
+
else:
|
| 64 |
+
print(f"📁 Uploading folder: {item}")
|
| 65 |
+
try:
|
| 66 |
+
api.upload_folder(
|
| 67 |
+
folder_path=str(item_path),
|
| 68 |
+
path_in_repo=item,
|
| 69 |
+
repo_id=repo_id,
|
| 70 |
+
repo_type=repo_type,
|
| 71 |
+
ignore_patterns=["__pycache__", "*.pyc", ".DS_Store", ".git", ".ipynb"]
|
| 72 |
+
)
|
| 73 |
+
print(f"✅ Successfully uploaded: {item}")
|
| 74 |
+
except Exception as e:
|
| 75 |
+
print(f"❌ Failed to upload {item}: {e}")
|
| 76 |
+
else:
|
| 77 |
+
print(f"⚠️ Skipping {item} - not found")
|
| 78 |
+
|
| 79 |
+
# Step 6: Upload README.md separately (if it exists)
|
| 80 |
+
readme_path = current_dir / "README.md"
|
| 81 |
+
if readme_path.exists():
|
| 82 |
+
print("📄 Uploading README.md...")
|
| 83 |
+
try:
|
| 84 |
+
api.upload_file(
|
| 85 |
+
path_or_fileobj=str(readme_path),
|
| 86 |
+
path_in_repo="README.md",
|
| 87 |
+
repo_id=repo_id,
|
| 88 |
+
repo_type=repo_type
|
| 89 |
+
)
|
| 90 |
+
print("✅ Successfully uploaded: README.md")
|
| 91 |
+
except Exception as e:
|
| 92 |
+
print(f"❌ Failed to upload README.md: {e}")
|
| 93 |
+
|
| 94 |
+
# Step 7: Upload requirements.txt if it exists
|
| 95 |
+
req_path = current_dir / "requirements.txt"
|
| 96 |
+
if req_path.exists():
|
| 97 |
+
print("📄 Uploading requirements.txt...")
|
| 98 |
+
try:
|
| 99 |
+
api.upload_file(
|
| 100 |
+
path_or_fileobj=str(req_path),
|
| 101 |
+
path_in_repo="requirements.txt",
|
| 102 |
+
repo_id=repo_id,
|
| 103 |
+
repo_type=repo_type
|
| 104 |
+
)
|
| 105 |
+
print("✅ Successfully uploaded: requirements.txt")
|
| 106 |
+
except Exception as e:
|
| 107 |
+
print(f"❌ Failed to upload requirements.txt: {e}")
|
| 108 |
+
|
| 109 |
+
print(f"🎉 Upload completed! Your project is available at: https://huggingface.co/{repo_id}")
|
| 110 |
+
|
| 111 |
+
if __name__ == "__main__":
|
| 112 |
+
upload_to_huggingface()
|