kia-command-center / upload /deploy_space.py
kiafa's picture
Premium UI/UX Overhaul & Optimization Update
b96f3a5 verified
Raw
History Blame Contribute Delete
2.92 kB
"""
KIA Deploy to HuggingFace Spaces
Uploads the entire project (minus heavy local data) as a Docker Space.
"""
import os
import sys
sys.path.append(os.path.dirname(os.path.dirname(os.path.abspath(__file__))))
from huggingface_hub import HfApi, upload_folder
from scraper.config import HF_TOKEN
def deploy_to_spaces():
print("=" * 60)
print(" KIA — DEPLOYING TO HUGGING FACE SPACES")
print("=" * 60)
api = HfApi(token=HF_TOKEN)
user_info = api.whoami()
username = user_info["name"]
print(f"Authenticated as: {username}")
space_id = f"{username}/kia-command-center"
print(f"\nEnsuring Space '{space_id}' exists...")
api.create_repo(
repo_id=space_id,
repo_type="space",
space_sdk="docker",
exist_ok=True,
private=False
)
# Set the HF_TOKEN as a Space secret so the API can use it at runtime
try:
api.add_space_secret(
repo_id=space_id,
key="HF_TOKEN",
value=HF_TOKEN,
)
print("HF_TOKEN secret configured in Space.")
except Exception as e:
print(f"Warning: Could not set secret (may already exist): {e}")
print(f"\nUploading KIA Command Center to {space_id}...")
# Files/folders to EXCLUDE from the upload
ignore_list = [
".git",
"**/.git/**",
"**/__pycache__/**",
"**/node_modules/**",
"data/raw/**", # Raw scraped data — not needed at runtime
"data/cleaned/**", # Cleaned data — not needed at runtime
"data/chroma_db/**", # ChromaDB will rebuild on startup from dataset
".env", # Never upload secrets!
"**/venv/**",
"*.crdownload",
"temp_*.wav",
"**/*.glb",
"**/*.gltf",
"shp_ai.log",
"scratch/**", # Development scratch files
"finetune/**", # Fine-tuning scripts — not needed for demo
]
# Get the project root (one level up from upload/)
project_root = os.path.dirname(os.path.dirname(os.path.abspath(__file__)))
upload_url = upload_folder(
folder_path=project_root,
repo_id=space_id,
repo_type="space",
ignore_patterns=ignore_list,
token=HF_TOKEN,
)
print("\n" + "=" * 60)
print(" [OK] DEPLOYMENT SUCCESSFUL!")
print("=" * 60)
print(f"\nDataset: https://huggingface.co/datasets/{username}/kia-dataset")
print(f"Space: https://huggingface.co/spaces/{space_id}")
print(f"\nThe Space is now building. It should be live in 3-5 minutes.")
print(f"Check build logs at: https://huggingface.co/spaces/{space_id}/logs/build")
print("=" * 60)
if __name__ == "__main__":
deploy_to_spaces()