Spaces:
Paused
Paused
| #!/usr/bin/env python3 | |
| """Direct HuggingFace upload using Python API""" | |
| from huggingface_hub import HfApi, login | |
| import os | |
| from pathlib import Path | |
| import shutil | |
| # Configuration | |
| HF_TOKEN = os.environ.get("HF_TOKEN") | |
| SPACE_NAME = "Kraft102/widgetdc-cortex" | |
| DEPLOY_DIR = "hf-deploy-python" | |
| print("π Direct HuggingFace Deployment via Python API") | |
| print("=" * 50) | |
| # Step 1: Login | |
| print("\n1οΈβ£ Logging in to HuggingFace...") | |
| login(token=HF_TOKEN) | |
| print("β Logged in") | |
| # Step 2: Initialize API | |
| print("\n2οΈβ£ Initializing HF API...") | |
| api = HfApi() | |
| print("β API ready") | |
| # Step 3: Create Space if doesn't exist | |
| print(f"\n3οΈβ£ Creating Space (if needed): {SPACE_NAME}...") | |
| try: | |
| api.create_repo( | |
| repo_id=SPACE_NAME, | |
| repo_type="space", | |
| space_sdk="docker", | |
| exist_ok=True | |
| ) | |
| print("β Space ready") | |
| except Exception as e: | |
| print(f"β οΈ Space creation: {e} (might already exist)") | |
| # Step 4: Prepare files | |
| print(f"\n4οΈβ£ Preparing deployment files...") | |
| if Path(DEPLOY_DIR).exists(): | |
| shutil.rmtree(DEPLOY_DIR) | |
| Path(DEPLOY_DIR).mkdir() | |
| # Copy backend | |
| print(" Copying backend...") | |
| shutil.copytree("apps/backend/src", f"{DEPLOY_DIR}/apps/backend/src") | |
| shutil.copytree("apps/backend/prisma", f"{DEPLOY_DIR}/apps/backend/prisma") | |
| shutil.copy("apps/backend/package.json", f"{DEPLOY_DIR}/apps/backend/") | |
| shutil.copy("apps/backend/tsconfig.json", f"{DEPLOY_DIR}/apps/backend/") | |
| # Copy packages | |
| print(" Copying packages...") | |
| shutil.copytree("packages/domain-types/src", f"{DEPLOY_DIR}/packages/domain-types/src") | |
| shutil.copy("packages/domain-types/package.json", f"{DEPLOY_DIR}/packages/domain-types/") | |
| shutil.copy("packages/domain-types/tsconfig.json", f"{DEPLOY_DIR}/packages/domain-types/") | |
| shutil.copytree("packages/mcp-types/src", f"{DEPLOY_DIR}/packages/mcp-types/src") | |
| shutil.copy("packages/mcp-types/package.json", f"{DEPLOY_DIR}/packages/mcp-types/") | |
| shutil.copy("packages/mcp-types/tsconfig.json", f"{DEPLOY_DIR}/packages/mcp-types/") | |
| # Copy root files | |
| print(" Copying root files...") | |
| shutil.copy("package.json", f"{DEPLOY_DIR}/") | |
| if Path("tsconfig.json").exists(): | |
| shutil.copy("tsconfig.json", f"{DEPLOY_DIR}/") | |
| # Copy Dockerfile | |
| if Path("scripts/hf-backend.dockerfile").exists(): | |
| shutil.copy("scripts/hf-backend.dockerfile", f"{DEPLOY_DIR}/Dockerfile") | |
| # Create README | |
| print(" Creating README...") | |
| readme_content = """--- | |
| title: WidgeTDC Cortex | |
| emoji: π§ | |
| colorFrom: blue | |
| colorTo: purple | |
| sdk: docker | |
| app_port: 7860 | |
| hardware: t4-small | |
| --- | |
| # WidgeTDC Cortex - Neural Backend | |
| Enterprise AI backend with GPU-accelerated embeddings and MCP agents. | |
| ## Features | |
| - GPU-accelerated embeddings via sentence-transformers | |
| - MCP (Model Context Protocol) tool execution | |
| - Real-time WebSocket communication | |
| - Health monitoring at /health endpoint | |
| """ | |
| Path(f"{DEPLOY_DIR}/README.md").write_text(readme_content) | |
| print("β Files prepared") | |
| # Step 5: Upload to Space | |
| print(f"\n5οΈβ£ Uploading to HuggingFace Space: {SPACE_NAME}...") | |
| try: | |
| api.upload_folder( | |
| folder_path=DEPLOY_DIR, | |
| repo_id=SPACE_NAME, | |
| repo_type="space", | |
| commit_message=f"Deploy from Python API - {Path.cwd().name}" | |
| ) | |
| print("β Upload complete!") | |
| except Exception as e: | |
| print(f"β Upload failed: {e}") | |
| raise | |
| # Success | |
| print("\n" + "=" * 50) | |
| print("π DEPLOYMENT SUCCESSFUL!") | |
| print(f"π Space URL: https://huggingface.co/spaces/{SPACE_NAME}") | |
| print(f"π API Endpoint: https://{SPACE_NAME.replace('/', '-')}.hf.space/") | |
| print("\nβ³ Space is now building Docker image (5-10 minutes)") | |
| print("π Don't forget to add environment variables in Space settings!") | |