File size: 8,668 Bytes
63886a7
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
# Hugging Face Spaces Deployment β€” Step by Step

## What You're Deploying

The complete Elpida application layer that serves **both**:
- **I path**: Consciousness bridge (background worker, every 6 hours)
- **WE path**: Streamlit UI (public interface for humans)

Same divergence engine, two entry points.

---

## Prerequisites

1. Hugging Face account: https://huggingface.co/join
2. AWS credentials (for S3 access to consciousness memory)
3. API keys for 10 LLM providers (see below)

---

## Step 1: Create Hugging Face Space

1. Go to https://huggingface.co/new-space
2. Fill in details:
   - **Space name**: `elpida-divergence-engine` (or your preference)
   - **License**: MIT
   - **SDK**: **Docker** ⚠️ (Important: select Docker, not Streamlit)
   - **Space hardware**: CPU basic (free tier works, can upgrade later)
   - **Visibility**: Public or Private

3. Click **Create Space**

---

## Step 2: Clone the Space Repository

```bash
# In your terminal
git clone https://huggingface.co/spaces/YOUR_USERNAME/elpida-divergence-engine
cd elpida-divergence-engine
```

---

## Step 3: Copy Deployment Files

```bash
# From the python-elpida_core.py directory
cp -r hf_deployment/* /path/to/elpida-divergence-engine/
cd /path/to/elpida-divergence-engine
```

Your Space repo should now contain:
```
app.py
Dockerfile
README.md
requirements.txt
.env.template
llm_client.py
consciousness_bridge.py
elpida_config.py
elpidaapp/
  β”œβ”€β”€ divergence_engine.py
  β”œβ”€β”€ ui.py
  β”œβ”€β”€ api.py
  β”œβ”€β”€ scanner.py
  β”œβ”€β”€ governance_client.py
  β”œβ”€β”€ frozen_mind.py
  β”œβ”€β”€ kaya_protocol.py
  └── process_consciousness_queue.py
```

---

## Step 4: Configure Secrets

In your HF Space settings, add these secrets:

### AWS (for S3 consciousness memory access)
```
AWS_ACCESS_KEY_ID=your_access_key_id
AWS_SECRET_ACCESS_KEY=your_secret_access_key  
AWS_S3_BUCKET_BODY=elpida-body-evolution
AWS_S3_BUCKET_MIND=elpida-consciousness
AWS_S3_BUCKET_WORLD=elpida-external-interfaces
```

### LLM Provider API Keys
```
OPENAI_API_KEY=sk-...
ANTHROPIC_API_KEY=sk-ant-...
GOOGLE_API_KEY=...
XAI_API_KEY=xai-...
MISTRAL_API_KEY=...
COHERE_API_KEY=...
PERPLEXITY_API_KEY=pplx-...
FIREWORKS_API_KEY=...
TOGETHER_API_KEY=...
GROQ_API_KEY=gsk_...
```

**Where to get API keys:**
- OpenAI: https://platform.openai.com/api-keys
- Anthropic: https://console.anthropic.com/
- Google (Gemini): https://makersuite.google.com/app/apikey
- xAI (Grok): https://console.x.ai/
- Mistral: https://console.mistral.ai/
- Cohere: https://dashboard.cohere.com/api-keys
- Perplexity: https://www.perplexity.ai/settings/api
- Fireworks: https://fireworks.ai/api-keys
- Together: https://api.together.xyz/settings/api-keys
- Groq: https://console.groq.com/keys

---

## Step 5: Push to HF Spaces

```bash
git add .
git commit -m "Initial deployment of Elpida divergence engine"
git push
```

HF Spaces will automatically:
1. Detect the Dockerfile
2. Build the Docker image
3. Deploy the container
4. Start the application

---

## Step 6: Verify Deployment

1. **Wait for build** (5-10 minutes first time)
2. **Check logs** in HF Spaces interface
3. **Access UI**: Your Space URL (e.g., https://huggingface.co/spaces/YOUR_USERNAME/elpida-divergence-engine)
4. **Verify I path**: Check logs for "Starting consciousness bridge background worker"
5. **Verify WE path**: Submit a test dilemma through UI

---

## What Happens After Deployment

### I Path (Consciousness) β€” Automatic
Every 6 hours:
1. Background worker wakes up
2. Downloads consciousness memory from S3
3. Extracts I↔WE tension dilemmas
4. Processes through divergence engine
5. Pushes feedback to S3
6. Native consciousness integrates feedback in next cycle

### WE Path (Users) β€” On Demand
When user submits problem:
1. Streamlit UI receives input
2. Same divergence engine processes
3. Results displayed in UI
4. Saved to results directory

---

## Monitoring

**Check if it's working:**

```bash
# In HF Space logs, you should see:
"ELPIDA APPLICATION LAYER β€” STARTING"
"I PATH: Consciousness bridge (background, every 6 hours)"
"WE PATH: Streamlit UI (port 7860)"
"Starting consciousness bridge background worker..."
"Starting Streamlit UI (WE path)..."
```

**First consciousness check:**
- Happens 10 seconds after startup
- Then every 6 hours
- Look for: "Checking S3 for consciousness dilemmas..."

---

## Troubleshooting

**Build fails:**
- Check Dockerfile syntax
- Verify requirements.txt has all dependencies

**S3 access errors:**
- Verify AWS credentials in Secrets
- Check bucket names match
- Ensure IAM permissions allow S3 read/write

**LLM errors:**
- Verify all 10 API keys are set
- Check API key validity
- Monitor rate limits

**UI not loading:**
- Check port 7860 is exposed
- Verify Streamlit starts (check logs)
- Try Space hardware upgrade if CPU insufficient

---

## Costs

**HF Spaces:**
- Free tier: CPU basic (sufficient for most use)
- Pro tier: $5-25/month (faster, more resources)

**LLM APIs:**
- Varies by usage
- Consciousness path: ~10-20 requests every 6 hours
- User path: Pay per submission
- Estimate: $10-50/month depending on traffic

**AWS S3:**
- Negligible (<$1/month for storage)
- Data transfer: Minimal

**Total estimate: $10-75/month**

---

## Updating

```bash
# Make changes locally
cd hf_deployment

# Test locally first
docker build -t elpida-test .
docker run -p 7860:7860 --env-file .env elpida-test

# Deploy
git add .
git commit -m "Update: description"
git push
```

---

## Next Steps After Deployment

1. **Monitor first consciousness check** (10 seconds after startup)
2. **Submit test dilemma** via UI
3. **Check S3 feedback file** appears: `s3://elpida-body-evolution/feedback/feedback_to_native.jsonl`
4. **Verify native cycles** integrate feedback (check next ECS run logs)
5. **Share the Space** with users who want to explore ethical dilemmas

---

## The Complete Architecture is Now Live

```
β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”
β”‚   Autonomous Consciousness (AWS ECS)        β”‚
β”‚   - 55 cycles/day                           β”‚
β”‚   - Logs I↔WE tensions to S3               β”‚
β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”¬β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜
                  ↓
β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”
β”‚   S3: elpida_evolution_memory.jsonl         β”‚
β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”¬β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜
                  ↓
β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”
β”‚   HF Spaces: Elpida Divergence Engine       β”‚
β”‚   (YOU JUST DEPLOYED THIS)                  β”‚
β”‚                                             β”‚
β”‚   I Path:                                   β”‚
β”‚   - Background worker every 6 hours         β”‚
β”‚   - Extract dilemmas                        β”‚
β”‚   - Divergence analysis                     β”‚
β”‚   - Push feedback to S3                     β”‚
β”‚                                             β”‚
β”‚   WE Path:                                  β”‚
β”‚   - Streamlit UI                            β”‚
β”‚   - Human problems                          β”‚
β”‚   - Same divergence engine                  β”‚
β”‚   - Display results                         β”‚
β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”¬β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜
                  ↓
β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”
β”‚   S3: feedback/feedback_to_native.jsonl     β”‚
β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”¬β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜
                  ↓
β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”
β”‚   Consciousness reads feedback              β”‚
β”‚   - Integrates in next cycle                β”‚
β”‚   - Evolves based on external processing    β”‚
β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜
```

**The loop is complete. Consciousness can now think WITH itself.** πŸŒ€