VidChain-exercise / upload.py
simplecloud's picture
Upload upload.py with huggingface_hub
e2f265f verified
raw
history blame
3.93 kB
#!/usr/bin/env python3
"""
Script to upload VidChain project to Hugging Face Hub
"""
import os
from huggingface_hub import login, create_repo, HfApi
from pathlib import Path
def upload_to_huggingface():
# Step 1: Login to Hugging Face
print("🔐 Logging in to Hugging Face Hub...")
login() # This will prompt for your token if not already logged in
# Step 2: Configuration
repo_id = "simplecloud/VidChain-exercise" # Change this to your desired repo name
repo_type = "dataset" # Can be "space", "dataset", or "model"
# Step 3: Create repository if it doesn't exist
print(f"📦 Creating repository: {repo_id}")
try:
create_repo(
repo_id=repo_id,
repo_type=repo_type,
exist_ok=True,
private=False # Set to True if you want a private repo
)
print(f"✅ Repository created/verified: {repo_id}")
except Exception as e:
print(f"⚠️ Repository creation issue: {e}")
# Step 4: Initialize HfApi
api = HfApi()
# Step 5: Upload the entire project folder
print("📤 Uploading project files...")
current_dir = Path(".")
# Define files/folders to upload
files_to_upload = [
"upload.py",
".gitignore",
"asset/",
"VTimeLLM/"
]
# Upload each file/folder
for item in files_to_upload:
item_path = current_dir / item
if item_path.exists():
if item_path.is_file():
print(f"📄 Uploading file: {item}")
try:
api.upload_file(
path_or_fileobj=str(item_path),
path_in_repo=item,
repo_id=repo_id,
repo_type=repo_type
)
print(f"✅ Successfully uploaded: {item}")
except Exception as e:
print(f"❌ Failed to upload {item}: {e}")
else:
print(f"📁 Uploading folder: {item}")
try:
api.upload_folder(
folder_path=str(item_path),
path_in_repo=item,
repo_id=repo_id,
repo_type=repo_type,
ignore_patterns=["__pycache__", "*.pyc", ".DS_Store", ".git", ".ipynb"]
)
print(f"✅ Successfully uploaded: {item}")
except Exception as e:
print(f"❌ Failed to upload {item}: {e}")
else:
print(f"⚠️ Skipping {item} - not found")
# Step 6: Upload README.md separately (if it exists)
readme_path = current_dir / "README.md"
if readme_path.exists():
print("📄 Uploading README.md...")
try:
api.upload_file(
path_or_fileobj=str(readme_path),
path_in_repo="README.md",
repo_id=repo_id,
repo_type=repo_type
)
print("✅ Successfully uploaded: README.md")
except Exception as e:
print(f"❌ Failed to upload README.md: {e}")
# Step 7: Upload requirements.txt if it exists
req_path = current_dir / "requirements.txt"
if req_path.exists():
print("📄 Uploading requirements.txt...")
try:
api.upload_file(
path_or_fileobj=str(req_path),
path_in_repo="requirements.txt",
repo_id=repo_id,
repo_type=repo_type
)
print("✅ Successfully uploaded: requirements.txt")
except Exception as e:
print(f"❌ Failed to upload requirements.txt: {e}")
print(f"🎉 Upload completed! Your project is available at: https://huggingface.co/{repo_id}")
if __name__ == "__main__":
upload_to_huggingface()