File size: 3,433 Bytes
fbb1eb0
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
"""
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")