File size: 1,778 Bytes
8a1a7c0 | 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 | # Run this script to deploy the Space to HuggingFace
import os
import subprocess
import sys
def deploy():
try:
from huggingface_hub import HfApi
except ImportError:
subprocess.check_call([sys.executable, "-m", "pip", "install", "huggingface_hub"])
from huggingface_hub import HfApi
api = HfApi()
# Get username from whoami
user_info = api.whoami()
username = user_info["name"]
repo_id = f"{username}/cka-kubernetes-practice"
print(f"Deploying to HuggingFace as: {username}")
# Create the Space
try:
api.create_repo(
repo_id=repo_id,
repo_type="space",
space_sdk="docker",
private=False,
exist_ok=True
)
print(f"Space created: {repo_id}")
except Exception as e:
print(f"Space may already exist: {e}")
# Upload all files
api.upload_folder(
folder_path="./cka-kubernetes-practice",
repo_id=repo_id,
repo_type="space"
)
print("")
print("╔══════════════════════════════════════════════════════════╗")
print("║ ✅ Deployment complete! ║")
print(f"║ 🌐 URL: https://huggingface.co/spaces/{repo_id:<20}║")
print("║ ⏳ Build takes ~3-5 minutes on HuggingFace ║")
print("║ 📺 Check build logs in the Space's 'Logs' tab ║")
print("╚══════════════════════════════════════════════════════════╝")
if __name__ == "__main__":
deploy()
|