arimatch1's picture
Upload folder using huggingface_hub
8a1a7c0 verified
Raw History Blame Contribute Delete
1.78 kB
# 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()