Elpida-Governance-Layer / DEPLOYMENT_GUIDE.md
z65nik's picture
feat: replace BODY Perplexity with free DDG+Groq + suppress torchvision noise
63886a7
|
Raw
History Blame
8.67 kB

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

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

Step 3: Copy Deployment Files

# 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:


Step 5: Push to HF Spaces

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:

# 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

# 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. πŸŒ€