import os import subprocess from pathlib import Path from huggingface_hub import HfApi def upload_space(): """Uploads the entire KIA Command Center to Hugging Face Spaces""" # Load .env manually since we might not have a package initialized env_file = Path(".env") if env_file.exists(): with open(env_file, "r") as f: for line in f: if line.startswith("HF_TOKEN="): os.environ["HF_TOKEN"] = line.strip().split("=")[1] token = os.environ.get("HF_TOKEN") if not token: print("ERROR: HF_TOKEN not found in environment or .env file.") print("Please ensure your token is set with Write permissions.") return api = HfApi(token=token) try: # Verify repo access me = api.whoami() username = me['name'] print(f"Authenticated as: {username}") repo_id = f"{username}/kia-command-center" print(f"Initializing upload to Hugging Face Space: {repo_id}") print(f"Ensuring repository {repo_id} exists...") api.create_repo(repo_id=repo_id, repo_type="space", space_sdk="docker", exist_ok=True) print("Pushing HF_TOKEN secret to the space...") try: api.add_space_secret(repo_id=repo_id, key="HF_TOKEN", value=token) print("Secret pushed successfully.") except Exception as e: print(f"Warning: Failed to set secret. Make sure it's set manually if required (Error: {e})") print("Uploading files... (This may take a minute or two)") api.upload_folder( folder_path=".", repo_id=repo_id, repo_type="space", commit_message="Premium UI/UX Overhaul & Optimization Update", ignore_patterns=[ ".git", ".env", "venv", "node_modules", "frontend/node_modules", "__pycache__", "*.pyc", "data/raw", "data/cleaned", "data/chroma_db", "scratch", "finetune", "temp_*", "*.crdownload", "*.glb", "*.gltf" ] ) print(f"Success! The Command Center is now live at: https://huggingface.co/spaces/{repo_id}") except Exception as e: print(f"Upload failed: {e}") if __name__ == "__main__": # Run upload upload_space()