Spaces:
Paused
Paused
| """ | |
| WidgeTDC Cortex - Automated Hugging Face Space Deployment | |
| Uses huggingface_hub API to create and configure Space | |
| """ | |
| import os | |
| import subprocess | |
| from huggingface_hub import HfApi, create_repo | |
| from pathlib import Path | |
| # Configuration | |
| SPACE_NAME = "widgetdc-cortex" | |
| USERNAME = "Kraft102" | |
| REPO_ID = f"{USERNAME}/{SPACE_NAME}" | |
| print("=" * 60) | |
| print(" NEURAL NETWORK DEPLOYMENT - HUGGING FACE SPACE") | |
| print("=" * 60) | |
| print() | |
| # Initialize API | |
| api = HfApi() | |
| print("[1/5] Creating Hugging Face Space...") | |
| try: | |
| # Create Space repository | |
| repo_url = create_repo( | |
| repo_id=REPO_ID, | |
| repo_type="space", | |
| space_sdk="docker", | |
| private=False, | |
| exist_ok=True | |
| ) | |
| print(f"โ Space created/verified: {repo_url}") | |
| except Exception as e: | |
| print(f"โ ๏ธ Space might already exist or error: {e}") | |
| repo_url = f"https://huggingface.co/spaces/{REPO_ID}" | |
| print(f"\n[2/5] Pushing code to Space...") | |
| repo_path = Path(r"C:\Users\claus\Projects\WidgeTDC\widgetdc-cortex") | |
| os.chdir(repo_path) | |
| # Configure git remote if needed | |
| try: | |
| subprocess.run( | |
| ["git", "remote", "remove", "hf"], | |
| capture_output=True, | |
| check=False | |
| ) | |
| except: | |
| pass | |
| subprocess.run( | |
| ["git", "remote", "add", "hf", f"https://huggingface.co/spaces/{REPO_ID}"], | |
| check=False | |
| ) | |
| # Push to HF | |
| print(" Pushing to Hugging Face...") | |
| result = subprocess.run( | |
| ["git", "push", "hf", "main", "--force"], | |
| capture_output=True, | |
| text=True | |
| ) | |
| if result.returncode == 0: | |
| print("โ Code pushed successfully!") | |
| else: | |
| print(f"โ ๏ธ Push output: {result.stderr}") | |
| print(f"\n[3/5] Configuring environment variables...") | |
| # Environment variables to set | |
| secrets = { | |
| "OPENAI_API_KEY": "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", | |
| "DATABASE_URL": "postgresql://neondb_owner:npg_3tJWPqo9kRsf@ep-fancy-field-aedyuut2-pooler.c-2.us-east-2.aws.neon.tech/neondb?channel_binding=require&sslmode=require", | |
| "NEO4J_URI": "neo4j+s://054eff27.databases.neo4j.io", | |
| "NEO4J_USER": "neo4j", | |
| "NEO4J_PASSWORD": "Qrt37mkb0xBZ7_ts5tG1J70K2mVDGPMF2L7Njlm7cg8", | |
| "JWT_SECRET": "WidgeTDC_Neural_Key_2025_Secure", | |
| "ANTHROPIC_API_KEY": "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", | |
| "GEMINI_API_KEY": "AIzaSyDsrLIwhYEK4gC1PYqWsMuMgGVi0n02N-w", | |
| "DEEPSEEK_API_KEY": "sk-a3f8e6b48271466b981396dc97fd904a" | |
| } | |
| try: | |
| for key, value in secrets.items(): | |
| api.add_space_secret( | |
| repo_id=REPO_ID, | |
| key=key, | |
| value=value | |
| ) | |
| print(f" โ {key} configured") | |
| except Exception as e: | |
| print(f"โ ๏ธ Could not set secrets via API: {e}") | |
| print(" You may need to set them manually in Space Settings") | |
| print(f"\n[4/5] Space URL:") | |
| print(f" ๐ https://huggingface.co/spaces/{REPO_ID}") | |
| print(f" ๐ Settings: https://huggingface.co/spaces/{REPO_ID}/settings") | |
| print(f"\n[5/5] Deployment initiated!") | |
| print(f" HF will now build Docker image (~5-10 minutes)") | |
| print(f" Watch build: https://huggingface.co/spaces/{REPO_ID}") | |
| print("\n" + "=" * 60) | |
| print(" DEPLOYMENT STATUS: INITIATED") | |
| print("=" * 60) | |
| print() | |
| print("Next: Wait for build to complete, then test:") | |
| print(f"curl https://{USERNAME}-{SPACE_NAME}.hf.space/health") | |