portfolio-engine / deploy_to_hf.py
engineportf's picture
Initial Deployment from Local Engine
208fbf8 verified
Raw
History Blame Contribute Delete
1.81 kB
import os
import sys
from huggingface_hub import HfApi, create_repo
def deploy():
print("\nπŸš€ Hugging Face Space Deployment Tool πŸš€")
print("=========================================\n")
token = input("Please paste your Hugging Face WRITE Token (from hf.co/settings/tokens): ").strip()
if not token:
print("Error: No token provided. Exiting.")
sys.exit(1)
username = HfApi(token=token).whoami()["name"]
repo_name = input(f"Enter the name for your new Space (e.g., 'portfolio-engine'): ").strip()
repo_id = f"{username}/{repo_name}"
print(f"\n[1/2] Creating Space '{repo_id}' on Hugging Face...")
try:
create_repo(repo_id=repo_id, repo_type="space", space_sdk="docker", token=token, exist_ok=True)
print(" Space created successfully!")
except Exception as e:
print(f"Error creating space: {e}")
sys.exit(1)
print(f"\n[2/2] Uploading project files to '{repo_id}'... (This may take a minute)")
api = HfApi(token=token)
# Exclude unnecessary/heavy local folders
ignore_patterns = ["__pycache__/*", ".git/*", ".pytest_cache/*", ".ruff_cache/*", "PortableGit/*", "*.db", "scratch/*", "output/*", "docs/*"]
try:
api.upload_folder(
folder_path=".",
repo_id=repo_id,
repo_type="space",
ignore_patterns=ignore_patterns,
commit_message="Initial Deployment from Local Engine"
)
print("\nβœ… DEPLOYMENT COMPLETE! βœ…")
print(f"Your app is now live (or building) at: https://huggingface.co/spaces/{repo_id}")
except Exception as e:
print(f"Error uploading files: {e}")
if __name__ == "__main__":
deploy()