Spaces:
Sleeping
Sleeping
File size: 1,934 Bytes
6ea020b | 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 | # upload_to_hf.py
# ===================================================================
# Helper script to upload NexLab to Hugging Face Spaces.
# Bypasses Git to avoid committing large executables like NexPrint.exe.
# ===================================================================
import os
import sys
def upload():
try:
from huggingface_hub import HfApi
except ImportError:
print("huggingface_hub library is not installed.")
print("Installing it now via pip...")
import subprocess
subprocess.check_call([sys.executable, "-m", "pip", "install", "huggingface_hub"])
from huggingface_hub import HfApi
# Ask the user for their token if not already stored
print("\n--- Hugging Face Spaces Direct Uploader ---")
token = input("Enter your Hugging Face Write Token: ").strip()
if not token:
print("❌ Token is required. You can get one from: https://huggingface.co/settings/tokens")
return
repo_id = "alisaleem97/NexLab_System"
print(f"Uploading files to Space: {repo_id}...")
api = HfApi()
# Ignore patterns to skip local virtual environments, large files, and Git history
ignore_patterns = [
"print_client/**",
".git/**",
"venv/**",
".env",
"**/*.log",
"**/__pycache__/**",
"backups/**",
"tmp/**",
"NexLab_Published/**"
]
try:
api.upload_folder(
folder_path=".",
repo_id=repo_id,
repo_type="space",
token=token,
ignore_patterns=ignore_patterns
)
print("\n🎉 Upload Completed Successfully!")
print("Your Space will now build and start automatically.")
print(f"Visit it at: https://huggingface.co/spaces/{repo_id}")
except Exception as e:
print(f"\n❌ Error during upload: {e}")
if __name__ == "__main__":
upload()
|