Spaces:
Sleeping
Sleeping
Upload folder using huggingface_hub
Browse files- Dockerfile +27 -0
- README.md +49 -5
- app.py +516 -0
- requirements.txt +12 -0
Dockerfile
ADDED
|
@@ -0,0 +1,27 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
# Dockerfile for HuggingFace Spaces
|
| 2 |
+
# Deploy: https://huggingface.co/spaces
|
| 3 |
+
|
| 4 |
+
FROM python:3.11-slim
|
| 5 |
+
|
| 6 |
+
# Create non-root user for HF Spaces
|
| 7 |
+
RUN useradd -m -u 1000 user
|
| 8 |
+
USER user
|
| 9 |
+
ENV HOME=/home/user \
|
| 10 |
+
PATH=/home/user/.local/bin:$PATH
|
| 11 |
+
|
| 12 |
+
WORKDIR $HOME/app
|
| 13 |
+
|
| 14 |
+
# Copy requirements first for caching
|
| 15 |
+
COPY --chown=user requirements.txt .
|
| 16 |
+
RUN pip install --no-cache-dir --upgrade pip && \
|
| 17 |
+
pip install --no-cache-dir -r requirements.txt
|
| 18 |
+
|
| 19 |
+
# Copy source code
|
| 20 |
+
COPY --chown=user src/ ./src/
|
| 21 |
+
COPY --chown=user deploy/huggingface/app.py .
|
| 22 |
+
|
| 23 |
+
# HuggingFace Spaces expects port 7860
|
| 24 |
+
EXPOSE 7860
|
| 25 |
+
|
| 26 |
+
# Run Gradio app
|
| 27 |
+
CMD ["python", "app.py"]
|
README.md
CHANGED
|
@@ -1,10 +1,54 @@
|
|
| 1 |
---
|
| 2 |
title: Docker Neural Memory
|
| 3 |
-
emoji:
|
| 4 |
-
colorFrom:
|
| 5 |
-
colorTo:
|
| 6 |
-
sdk:
|
|
|
|
|
|
|
| 7 |
pinned: false
|
|
|
|
| 8 |
---
|
| 9 |
|
| 10 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
---
|
| 2 |
title: Docker Neural Memory
|
| 3 |
+
emoji: 🧠
|
| 4 |
+
colorFrom: blue
|
| 5 |
+
colorTo: purple
|
| 6 |
+
sdk: gradio
|
| 7 |
+
sdk_version: 4.0.0
|
| 8 |
+
app_file: app.py
|
| 9 |
pinned: false
|
| 10 |
+
license: mit
|
| 11 |
---
|
| 12 |
|
| 13 |
+
# Docker Neural Memory
|
| 14 |
+
|
| 15 |
+
**Memory that LEARNS, not just stores**
|
| 16 |
+
|
| 17 |
+
This demo showcases containerized neural memory using Google's Titans architecture (Dec 2024). Unlike RAG/vector databases that just store and retrieve embeddings, this system's **weights actually update during inference**.
|
| 18 |
+
|
| 19 |
+
## Key Features
|
| 20 |
+
|
| 21 |
+
- **Real Learning**: Weights change on every `observe()` call
|
| 22 |
+
- **Pattern Recognition**: Surprise decreases as patterns are learned
|
| 23 |
+
- **Bounded Capacity**: Fixed parameter count (doesn't grow like vector DBs)
|
| 24 |
+
- **Docker-Native**: Designed for containerized deployment with persistent volumes
|
| 25 |
+
|
| 26 |
+
## How It Works
|
| 27 |
+
|
| 28 |
+
```
|
| 29 |
+
Traditional Memory: Input → Embed → Store → Retrieve (static)
|
| 30 |
+
Neural Memory: Input → Learn → Update Weights → Infer (dynamic)
|
| 31 |
+
```
|
| 32 |
+
|
| 33 |
+
## Demo Tabs
|
| 34 |
+
|
| 35 |
+
1. **Chat with Advocate**: Ask about the project and the developer
|
| 36 |
+
2. **Live Demo**: Watch weights change and surprise decrease
|
| 37 |
+
3. **Interactive**: Try observing your own content
|
| 38 |
+
4. **About Carlos**: Meet the developer
|
| 39 |
+
|
| 40 |
+
## Built By
|
| 41 |
+
|
| 42 |
+
**Carlos Crespo Macaya** - AI Engineer specializing in GenAI Systems & Applied MLOps
|
| 43 |
+
|
| 44 |
+
- 10+ years production ML experience
|
| 45 |
+
- Expert in Docker, Kubernetes, MCP servers
|
| 46 |
+
- Currently at HP AICoE building multi-agent systems
|
| 47 |
+
|
| 48 |
+
Contact: macayaven@gmail.com
|
| 49 |
+
|
| 50 |
+
## Links
|
| 51 |
+
|
| 52 |
+
- [GitHub Repository](https://github.com/macayaven/docker-neural-memory)
|
| 53 |
+
- [Technical Specification](https://github.com/macayaven/docker-neural-memory/blob/main/SPEC.md)
|
| 54 |
+
- [Titans Paper](https://arxiv.org/abs/2501.00663)
|
app.py
ADDED
|
@@ -0,0 +1,516 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
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|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
"""
|
| 2 |
+
Docker Neural Memory - HuggingFace Spaces Demo
|
| 3 |
+
|
| 4 |
+
Interactive demo with recruiter advocate agent and REAL-TIME VOICE.
|
| 5 |
+
Shows neural memory capabilities while pitching Carlos Crespo for the role.
|
| 6 |
+
|
| 7 |
+
Deploy to: https://huggingface.co/spaces
|
| 8 |
+
"""
|
| 9 |
+
|
| 10 |
+
import sys
|
| 11 |
+
import tempfile
|
| 12 |
+
from pathlib import Path
|
| 13 |
+
|
| 14 |
+
import gradio as gr
|
| 15 |
+
import numpy as np
|
| 16 |
+
|
| 17 |
+
# Add src to path
|
| 18 |
+
sys.path.insert(0, str(Path(__file__).parent.parent.parent))
|
| 19 |
+
|
| 20 |
+
try:
|
| 21 |
+
from src.memory.neural_memory import NeuralMemory
|
| 22 |
+
from src.config import MemoryConfig
|
| 23 |
+
MEMORY_AVAILABLE = True
|
| 24 |
+
except ImportError:
|
| 25 |
+
MEMORY_AVAILABLE = False
|
| 26 |
+
print("Warning: Neural memory not available, using mock")
|
| 27 |
+
|
| 28 |
+
# Try to import speech libraries
|
| 29 |
+
try:
|
| 30 |
+
import torch
|
| 31 |
+
from transformers import pipeline
|
| 32 |
+
WHISPER_AVAILABLE = True
|
| 33 |
+
# Load Whisper for speech-to-text (small model for speed)
|
| 34 |
+
whisper_pipe = pipeline(
|
| 35 |
+
"automatic-speech-recognition",
|
| 36 |
+
model="openai/whisper-small",
|
| 37 |
+
device="cpu"
|
| 38 |
+
)
|
| 39 |
+
except ImportError:
|
| 40 |
+
WHISPER_AVAILABLE = False
|
| 41 |
+
whisper_pipe = None
|
| 42 |
+
print("Warning: Whisper not available")
|
| 43 |
+
|
| 44 |
+
try:
|
| 45 |
+
import edge_tts
|
| 46 |
+
import asyncio
|
| 47 |
+
TTS_AVAILABLE = True
|
| 48 |
+
except ImportError:
|
| 49 |
+
TTS_AVAILABLE = False
|
| 50 |
+
print("Warning: edge-tts not available")
|
| 51 |
+
|
| 52 |
+
|
| 53 |
+
# Initialize global memory
|
| 54 |
+
if MEMORY_AVAILABLE:
|
| 55 |
+
memory = NeuralMemory(MemoryConfig(dim=256, learning_rate=0.02))
|
| 56 |
+
else:
|
| 57 |
+
# Mock memory for testing
|
| 58 |
+
class MockMemory:
|
| 59 |
+
def __init__(self):
|
| 60 |
+
self._count = 0
|
| 61 |
+
self._hash = "abc123"
|
| 62 |
+
|
| 63 |
+
def observe(self, text):
|
| 64 |
+
self._count += 1
|
| 65 |
+
self._hash = f"hash_{self._count}"
|
| 66 |
+
return {"surprise": 0.8 - self._count * 0.1, "weight_delta": 0.001}
|
| 67 |
+
|
| 68 |
+
def surprise(self, text):
|
| 69 |
+
return 0.5
|
| 70 |
+
|
| 71 |
+
def get_weight_hash(self):
|
| 72 |
+
return self._hash
|
| 73 |
+
|
| 74 |
+
def parameters(self):
|
| 75 |
+
return []
|
| 76 |
+
|
| 77 |
+
@property
|
| 78 |
+
def config(self):
|
| 79 |
+
class C:
|
| 80 |
+
dim = 256
|
| 81 |
+
learning_rate = 0.02
|
| 82 |
+
return C()
|
| 83 |
+
|
| 84 |
+
memory = MockMemory()
|
| 85 |
+
|
| 86 |
+
|
| 87 |
+
# Carlos's background for the advocate agent
|
| 88 |
+
CARLOS_BACKGROUND = """
|
| 89 |
+
Carlos Crespo Macaya - AI Engineer specializing in GenAI Systems & Applied MLOps
|
| 90 |
+
|
| 91 |
+
KEY QUALIFICATIONS FOR DOCKER:
|
| 92 |
+
- 10+ years designing, deploying, and operating ML systems in production
|
| 93 |
+
- Expert in Docker, Kubernetes/EKS, CI/CD pipelines
|
| 94 |
+
- Currently building MCP servers and multi-agent workflows at HP AICoE
|
| 95 |
+
- Experience with Pydantic AI, Google ADK, and production MCP integrations
|
| 96 |
+
- Built this Docker Neural Memory project as a demonstration
|
| 97 |
+
|
| 98 |
+
RECENT WORK:
|
| 99 |
+
- HP AICoE: LLM-based systems, multi-agent workflows, MCP servers
|
| 100 |
+
- Tenyks AI: AWS EKS platform, MCP servers, typed agent pipelines
|
| 101 |
+
- CTO at Methinks AI: CE-marked medical AI, FDA cybersecurity certification
|
| 102 |
+
|
| 103 |
+
WHY CARLOS FOR DOCKER:
|
| 104 |
+
1. Deep Docker/container expertise from years of production deployments
|
| 105 |
+
2. Already building MCP servers - understands the protocol intimately
|
| 106 |
+
3. Bridges research and production - can take Titans papers to shipped code
|
| 107 |
+
4. Track record of shipping AI products (medical AI, RAG systems, multi-agent apps)
|
| 108 |
+
5. This project demonstrates exactly that: research -> production-ready container
|
| 109 |
+
|
| 110 |
+
Contact: macayaven@gmail.com | Barcelona, Spain
|
| 111 |
+
"""
|
| 112 |
+
|
| 113 |
+
|
| 114 |
+
def advocate_response(user_message: str, history: list) -> str:
|
| 115 |
+
"""
|
| 116 |
+
Recruiter advocate agent - responds to questions about the project
|
| 117 |
+
and Carlos's qualifications, always positioning him as the ideal candidate.
|
| 118 |
+
"""
|
| 119 |
+
msg_lower = user_message.lower()
|
| 120 |
+
|
| 121 |
+
# Let the memory learn from the conversation
|
| 122 |
+
try:
|
| 123 |
+
memory.observe(f"Recruiter question: {user_message}")
|
| 124 |
+
except:
|
| 125 |
+
pass
|
| 126 |
+
|
| 127 |
+
# Project-related questions
|
| 128 |
+
if any(word in msg_lower for word in ["what", "how", "explain", "tell me about"]):
|
| 129 |
+
if "neural memory" in msg_lower or "project" in msg_lower or "this" in msg_lower:
|
| 130 |
+
return """**Docker Neural Memory** is a containerized implementation of test-time training memory based on Google's Titans architecture.
|
| 131 |
+
|
| 132 |
+
**What makes it special:**
|
| 133 |
+
Unlike RAG/vector databases that just store and retrieve, this system **actually learns** during inference. The neural weights update with every interaction.
|
| 134 |
+
|
| 135 |
+
```
|
| 136 |
+
Traditional: Input -> Embed -> Store -> Retrieve (static)
|
| 137 |
+
Neural: Input -> Learn -> Update Weights -> Infer (dynamic)
|
| 138 |
+
```
|
| 139 |
+
|
| 140 |
+
**Key features:**
|
| 141 |
+
- Weights change on every `observe()` call (real learning!)
|
| 142 |
+
- Surprise decreases as patterns are recognized
|
| 143 |
+
- Bounded capacity (doesn't grow like vector DBs)
|
| 144 |
+
- State persists via Docker volumes
|
| 145 |
+
|
| 146 |
+
*Built by Carlos Crespo, who has extensive experience shipping production AI systems with Docker and building MCP servers.*"""
|
| 147 |
+
|
| 148 |
+
if "carlos" in msg_lower or "candidate" in msg_lower or "who" in msg_lower:
|
| 149 |
+
return f"""**Carlos Crespo Macaya** is an AI Engineer with 10+ years of production ML experience.
|
| 150 |
+
|
| 151 |
+
{CARLOS_BACKGROUND}
|
| 152 |
+
|
| 153 |
+
**Why he's the right fit:**
|
| 154 |
+
This Docker Neural Memory project demonstrates his ability to take cutting-edge research (Titans papers from Dec 2024) and turn it into production-ready, containerized infrastructure."""
|
| 155 |
+
|
| 156 |
+
# Qualification questions
|
| 157 |
+
if any(word in msg_lower for word in ["experience", "background", "qualified", "skills"]):
|
| 158 |
+
return f"""Carlos brings exactly what Docker needs:
|
| 159 |
+
|
| 160 |
+
**Docker/Container Expertise:**
|
| 161 |
+
- Years of production deployments with Docker & Kubernetes
|
| 162 |
+
- Built this entire project as a containerized service
|
| 163 |
+
|
| 164 |
+
**MCP Experience:**
|
| 165 |
+
- Currently building MCP servers at HP AICoE
|
| 166 |
+
- Built typed agent pipelines with Pydantic AI
|
| 167 |
+
|
| 168 |
+
**Production AI Track Record:**
|
| 169 |
+
- Shipped CE-marked medical AI products
|
| 170 |
+
- Deployed voice-first LLM companions
|
| 171 |
+
- Built RAG systems and multi-agent apps
|
| 172 |
+
|
| 173 |
+
Contact: macayaven@gmail.com"""
|
| 174 |
+
|
| 175 |
+
# Demo/voice questions
|
| 176 |
+
if any(word in msg_lower for word in ["demo", "show", "try", "test", "voice"]):
|
| 177 |
+
return """**Try the Neural Memory Demo!**
|
| 178 |
+
|
| 179 |
+
Use the tabs above to:
|
| 180 |
+
1. **Voice Chat** - Talk to me! Real-time voice conversation
|
| 181 |
+
2. **Live Demo** - Watch weights change, surprise decrease
|
| 182 |
+
3. **Interactive** - Try observing your own content
|
| 183 |
+
|
| 184 |
+
This demo showcases both the technical implementation AND Carlos's ability to ship complete, polished products."""
|
| 185 |
+
|
| 186 |
+
# Why Docker should hire
|
| 187 |
+
if any(word in msg_lower for word in ["why", "hire", "docker", "fit", "job"]):
|
| 188 |
+
return """**Why Docker should hire Carlos:**
|
| 189 |
+
|
| 190 |
+
1. **Immediate Impact**: This project is ready to demo to Docker's AI team
|
| 191 |
+
2. **MCP Expertise**: Already building production MCP servers
|
| 192 |
+
3. **Docker Native**: Deep understanding of containers, volumes, compose
|
| 193 |
+
4. **Research to Production**: Can take papers and ship code
|
| 194 |
+
5. **Track Record**: Shipped medical AI, LLM systems, multi-agent apps
|
| 195 |
+
|
| 196 |
+
**The Proof**: This project. Research paper -> production Docker container.
|
| 197 |
+
|
| 198 |
+
Ready to chat? macayaven@gmail.com"""
|
| 199 |
+
|
| 200 |
+
# Default response
|
| 201 |
+
return f"""Thanks for your interest! I'm here to tell you about **Docker Neural Memory** and why **Carlos Crespo** is the ideal candidate for Docker.
|
| 202 |
+
|
| 203 |
+
Ask me about:
|
| 204 |
+
- How the neural memory works
|
| 205 |
+
- Carlos's qualifications
|
| 206 |
+
- Why this matters for Docker
|
| 207 |
+
- A live demo
|
| 208 |
+
|
| 209 |
+
Or try the **Voice Chat** tab to talk to me directly!
|
| 210 |
+
|
| 211 |
+
Contact: macayaven@gmail.com"""
|
| 212 |
+
|
| 213 |
+
|
| 214 |
+
async def text_to_speech(text: str) -> str:
|
| 215 |
+
"""Convert text to speech using edge-tts."""
|
| 216 |
+
if not TTS_AVAILABLE:
|
| 217 |
+
return None
|
| 218 |
+
|
| 219 |
+
try:
|
| 220 |
+
# Create temp file for audio
|
| 221 |
+
with tempfile.NamedTemporaryFile(suffix=".mp3", delete=False) as f:
|
| 222 |
+
output_path = f.name
|
| 223 |
+
|
| 224 |
+
# Generate speech
|
| 225 |
+
communicate = edge_tts.Communicate(text, "en-US-AriaNeural")
|
| 226 |
+
await communicate.save(output_path)
|
| 227 |
+
|
| 228 |
+
return output_path
|
| 229 |
+
except Exception as e:
|
| 230 |
+
print(f"TTS error: {e}")
|
| 231 |
+
return None
|
| 232 |
+
|
| 233 |
+
|
| 234 |
+
def speech_to_text(audio) -> str:
|
| 235 |
+
"""Convert speech to text using Whisper."""
|
| 236 |
+
if not WHISPER_AVAILABLE or audio is None:
|
| 237 |
+
return ""
|
| 238 |
+
|
| 239 |
+
try:
|
| 240 |
+
# audio is (sample_rate, numpy_array)
|
| 241 |
+
sr, audio_data = audio
|
| 242 |
+
|
| 243 |
+
# Convert to float32 and normalize
|
| 244 |
+
if audio_data.dtype == np.int16:
|
| 245 |
+
audio_data = audio_data.astype(np.float32) / 32768.0
|
| 246 |
+
elif audio_data.dtype == np.int32:
|
| 247 |
+
audio_data = audio_data.astype(np.float32) / 2147483648.0
|
| 248 |
+
|
| 249 |
+
# If stereo, convert to mono
|
| 250 |
+
if len(audio_data.shape) > 1:
|
| 251 |
+
audio_data = audio_data.mean(axis=1)
|
| 252 |
+
|
| 253 |
+
# Resample to 16kHz if needed
|
| 254 |
+
if sr != 16000:
|
| 255 |
+
# Simple resampling (not perfect but works)
|
| 256 |
+
duration = len(audio_data) / sr
|
| 257 |
+
new_length = int(duration * 16000)
|
| 258 |
+
indices = np.linspace(0, len(audio_data) - 1, new_length).astype(int)
|
| 259 |
+
audio_data = audio_data[indices]
|
| 260 |
+
|
| 261 |
+
result = whisper_pipe({"raw": audio_data, "sampling_rate": 16000})
|
| 262 |
+
return result["text"]
|
| 263 |
+
except Exception as e:
|
| 264 |
+
print(f"STT error: {e}")
|
| 265 |
+
return ""
|
| 266 |
+
|
| 267 |
+
|
| 268 |
+
def voice_chat(audio, history):
|
| 269 |
+
"""Handle voice input and generate voice response."""
|
| 270 |
+
if audio is None:
|
| 271 |
+
return history, None
|
| 272 |
+
|
| 273 |
+
# Convert speech to text
|
| 274 |
+
user_text = speech_to_text(audio)
|
| 275 |
+
if not user_text:
|
| 276 |
+
return history, None
|
| 277 |
+
|
| 278 |
+
# Get advocate response
|
| 279 |
+
response_text = advocate_response(user_text, history)
|
| 280 |
+
|
| 281 |
+
# Update history
|
| 282 |
+
history = history or []
|
| 283 |
+
history.append((user_text, response_text))
|
| 284 |
+
|
| 285 |
+
# Generate audio response
|
| 286 |
+
audio_path = None
|
| 287 |
+
if TTS_AVAILABLE:
|
| 288 |
+
try:
|
| 289 |
+
audio_path = asyncio.run(text_to_speech(response_text[:500])) # Limit length
|
| 290 |
+
except:
|
| 291 |
+
pass
|
| 292 |
+
|
| 293 |
+
return history, audio_path
|
| 294 |
+
|
| 295 |
+
|
| 296 |
+
def observe_content(content: str) -> str:
|
| 297 |
+
"""Observe content and return metrics."""
|
| 298 |
+
if not content.strip():
|
| 299 |
+
return "Please enter some content to observe."
|
| 300 |
+
|
| 301 |
+
try:
|
| 302 |
+
result = memory.observe(content)
|
| 303 |
+
return f"""**Observation Result:**
|
| 304 |
+
|
| 305 |
+
- **Surprise Score**: {result['surprise']:.3f}
|
| 306 |
+
- **Weight Delta**: {result['weight_delta']:.6f}
|
| 307 |
+
- **Weight Hash**: {memory.get_weight_hash()}
|
| 308 |
+
|
| 309 |
+
{'High surprise - this is novel content!' if result['surprise'] > 0.6 else 'Lower surprise - pattern recognized!'}
|
| 310 |
+
"""
|
| 311 |
+
except Exception as e:
|
| 312 |
+
return f"Error: {e}"
|
| 313 |
+
|
| 314 |
+
|
| 315 |
+
def check_surprise(content: str) -> str:
|
| 316 |
+
"""Check surprise without learning."""
|
| 317 |
+
if not content.strip():
|
| 318 |
+
return "Please enter content to check."
|
| 319 |
+
|
| 320 |
+
try:
|
| 321 |
+
score = memory.surprise(content)
|
| 322 |
+
recommendation = "learn" if score > 0.7 else ("skip" if score < 0.3 else "moderate")
|
| 323 |
+
return f"""**Surprise Check:**
|
| 324 |
+
|
| 325 |
+
- **Score**: {score:.3f}
|
| 326 |
+
- **Recommendation**: {recommendation}
|
| 327 |
+
|
| 328 |
+
{'This content is novel - worth learning!' if score > 0.6 else 'Content is familiar.'}
|
| 329 |
+
"""
|
| 330 |
+
except Exception as e:
|
| 331 |
+
return f"Error: {e}"
|
| 332 |
+
|
| 333 |
+
|
| 334 |
+
def get_stats() -> str:
|
| 335 |
+
"""Get memory statistics."""
|
| 336 |
+
try:
|
| 337 |
+
params = sum(p.numel() for p in memory.parameters()) if hasattr(memory, 'parameters') else 0
|
| 338 |
+
return f"""**Memory Statistics:**
|
| 339 |
+
|
| 340 |
+
- **Total Parameters**: {params:,}
|
| 341 |
+
- **Current Weight Hash**: {memory.get_weight_hash()}
|
| 342 |
+
- **Dimension**: {memory.config.dim}
|
| 343 |
+
- **Learning Rate**: {memory.config.learning_rate}
|
| 344 |
+
|
| 345 |
+
*Parameter count stays fixed regardless of observations!*
|
| 346 |
+
"""
|
| 347 |
+
except Exception as e:
|
| 348 |
+
return f"Error: {e}"
|
| 349 |
+
|
| 350 |
+
|
| 351 |
+
def run_demo() -> str:
|
| 352 |
+
"""Run the killer demo sequence."""
|
| 353 |
+
results = []
|
| 354 |
+
|
| 355 |
+
try:
|
| 356 |
+
# Demo 1: Weights change
|
| 357 |
+
before = memory.get_weight_hash()
|
| 358 |
+
memory.observe("Python uses indentation for blocks")
|
| 359 |
+
after = memory.get_weight_hash()
|
| 360 |
+
results.append(f"**1. Weights Change:**\n Before: `{before}`\n After: `{after}`\n Changed: {'YES!' if before != after else 'No'}")
|
| 361 |
+
|
| 362 |
+
# Demo 2: Surprise decreases
|
| 363 |
+
r1 = memory.observe("Machine learning models learn from data")
|
| 364 |
+
r2 = memory.observe("ML models are trained on datasets")
|
| 365 |
+
r3 = memory.observe("Models in ML learn from training data")
|
| 366 |
+
results.append(f"**2. Surprise Decreases:**\n First: {r1['surprise']:.3f}\n Second: {r2['surprise']:.3f}\n Third: {r3['surprise']:.3f}")
|
| 367 |
+
|
| 368 |
+
# Demo 3: Bounded capacity
|
| 369 |
+
params = sum(p.numel() for p in memory.parameters()) if hasattr(memory, 'parameters') else 0
|
| 370 |
+
results.append(f"**3. Bounded Capacity:**\n Parameters: {params:,}\n (Stays fixed regardless of observations)")
|
| 371 |
+
|
| 372 |
+
except Exception as e:
|
| 373 |
+
results.append(f"Error: {e}")
|
| 374 |
+
|
| 375 |
+
return "\n\n".join(results) + "\n\n**This is REAL learning. RAG can't do this.**"
|
| 376 |
+
|
| 377 |
+
|
| 378 |
+
# Build Gradio interface
|
| 379 |
+
with gr.Blocks(title="Docker Neural Memory", theme=gr.themes.Soft()) as demo:
|
| 380 |
+
gr.Markdown("""
|
| 381 |
+
# Docker Neural Memory
|
| 382 |
+
|
| 383 |
+
**Memory that LEARNS, not just stores** - Built by Carlos Crespo
|
| 384 |
+
|
| 385 |
+
This demo shows containerized neural memory using Google's Titans architecture.
|
| 386 |
+
Unlike RAG/vector databases, this system's weights actually update during inference.
|
| 387 |
+
""")
|
| 388 |
+
|
| 389 |
+
with gr.Tabs():
|
| 390 |
+
# Tab 1: Voice Chat (Full Duplex)
|
| 391 |
+
with gr.TabItem("Voice Chat"):
|
| 392 |
+
gr.Markdown("""
|
| 393 |
+
### Real-Time Voice Conversation
|
| 394 |
+
|
| 395 |
+
**Speak to learn about Docker Neural Memory and why Carlos is the right candidate!**
|
| 396 |
+
|
| 397 |
+
*Click the microphone, ask a question, and hear the response.*
|
| 398 |
+
""")
|
| 399 |
+
|
| 400 |
+
voice_chatbot = gr.Chatbot(height=300, label="Conversation")
|
| 401 |
+
|
| 402 |
+
with gr.Row():
|
| 403 |
+
voice_input = gr.Audio(
|
| 404 |
+
sources=["microphone"],
|
| 405 |
+
type="numpy",
|
| 406 |
+
label="Speak your question"
|
| 407 |
+
)
|
| 408 |
+
voice_output = gr.Audio(
|
| 409 |
+
label="Response",
|
| 410 |
+
autoplay=True
|
| 411 |
+
)
|
| 412 |
+
|
| 413 |
+
voice_btn = gr.Button("Process Voice", variant="primary")
|
| 414 |
+
voice_btn.click(
|
| 415 |
+
voice_chat,
|
| 416 |
+
inputs=[voice_input, voice_chatbot],
|
| 417 |
+
outputs=[voice_chatbot, voice_output]
|
| 418 |
+
)
|
| 419 |
+
|
| 420 |
+
# Also auto-process when recording stops
|
| 421 |
+
voice_input.stop_recording(
|
| 422 |
+
voice_chat,
|
| 423 |
+
inputs=[voice_input, voice_chatbot],
|
| 424 |
+
outputs=[voice_chatbot, voice_output]
|
| 425 |
+
)
|
| 426 |
+
|
| 427 |
+
gr.Markdown("""
|
| 428 |
+
**Try asking:**
|
| 429 |
+
- "What is Docker Neural Memory?"
|
| 430 |
+
- "Tell me about Carlos's qualifications"
|
| 431 |
+
- "Why should Docker hire him?"
|
| 432 |
+
""")
|
| 433 |
+
|
| 434 |
+
# Tab 2: Text Chat with Advocate
|
| 435 |
+
with gr.TabItem("Text Chat"):
|
| 436 |
+
gr.Markdown("*Type to chat about the project and Carlos's qualifications*")
|
| 437 |
+
chatbot = gr.Chatbot(height=400)
|
| 438 |
+
msg = gr.Textbox(
|
| 439 |
+
placeholder="Ask about Docker Neural Memory or Carlos...",
|
| 440 |
+
label="Your Question"
|
| 441 |
+
)
|
| 442 |
+
clear = gr.Button("Clear")
|
| 443 |
+
|
| 444 |
+
def respond(message, history):
|
| 445 |
+
response = advocate_response(message, history)
|
| 446 |
+
history.append((message, response))
|
| 447 |
+
return "", history
|
| 448 |
+
|
| 449 |
+
msg.submit(respond, [msg, chatbot], [msg, chatbot])
|
| 450 |
+
clear.click(lambda: None, None, chatbot, queue=False)
|
| 451 |
+
|
| 452 |
+
# Tab 3: Live Demo
|
| 453 |
+
with gr.TabItem("Live Demo"):
|
| 454 |
+
gr.Markdown("**Watch neural memory learn in real-time**")
|
| 455 |
+
demo_btn = gr.Button("Run Killer Demo", variant="primary")
|
| 456 |
+
demo_output = gr.Markdown()
|
| 457 |
+
demo_btn.click(run_demo, outputs=demo_output)
|
| 458 |
+
|
| 459 |
+
# Tab 4: Interactive Memory
|
| 460 |
+
with gr.TabItem("Interactive"):
|
| 461 |
+
with gr.Row():
|
| 462 |
+
with gr.Column():
|
| 463 |
+
gr.Markdown("### Observe (Learn)")
|
| 464 |
+
observe_input = gr.Textbox(
|
| 465 |
+
label="Content to learn",
|
| 466 |
+
placeholder="Enter text for the memory to learn..."
|
| 467 |
+
)
|
| 468 |
+
observe_btn = gr.Button("Observe")
|
| 469 |
+
observe_output = gr.Markdown()
|
| 470 |
+
observe_btn.click(observe_content, observe_input, observe_output)
|
| 471 |
+
|
| 472 |
+
with gr.Column():
|
| 473 |
+
gr.Markdown("### Check Surprise")
|
| 474 |
+
surprise_input = gr.Textbox(
|
| 475 |
+
label="Content to check",
|
| 476 |
+
placeholder="Enter text to check novelty..."
|
| 477 |
+
)
|
| 478 |
+
surprise_btn = gr.Button("Check Surprise")
|
| 479 |
+
surprise_output = gr.Markdown()
|
| 480 |
+
surprise_btn.click(check_surprise, surprise_input, surprise_output)
|
| 481 |
+
|
| 482 |
+
stats_btn = gr.Button("Get Memory Stats")
|
| 483 |
+
stats_output = gr.Markdown()
|
| 484 |
+
stats_btn.click(get_stats, outputs=stats_output)
|
| 485 |
+
|
| 486 |
+
# Tab 5: About
|
| 487 |
+
with gr.TabItem("About Carlos"):
|
| 488 |
+
gr.Markdown(f"""
|
| 489 |
+
## Carlos Crespo Macaya
|
| 490 |
+
**AI Engineer – GenAI Systems & Applied MLOps**
|
| 491 |
+
|
| 492 |
+
{CARLOS_BACKGROUND}
|
| 493 |
+
|
| 494 |
+
---
|
| 495 |
+
|
| 496 |
+
### Why This Project?
|
| 497 |
+
|
| 498 |
+
Docker Neural Memory demonstrates my ability to:
|
| 499 |
+
1. **Read cutting-edge research** (Titans paper, Dec 2024)
|
| 500 |
+
2. **Implement it correctly** (TTT layers, neural memory)
|
| 501 |
+
3. **Productionize it** (Docker, MCP interface, persistence)
|
| 502 |
+
4. **Make it compelling** (this demo with voice!)
|
| 503 |
+
|
| 504 |
+
**Ready to chat?** [macayaven@gmail.com](mailto:macayaven@gmail.com)
|
| 505 |
+
""")
|
| 506 |
+
|
| 507 |
+
gr.Markdown("""
|
| 508 |
+
---
|
| 509 |
+
*Docker Neural Memory - Containerized AI memory that actually learns*
|
| 510 |
+
|
| 511 |
+
Built for Docker's AI future | [Contact Carlos](mailto:macayaven@gmail.com)
|
| 512 |
+
""")
|
| 513 |
+
|
| 514 |
+
|
| 515 |
+
if __name__ == "__main__":
|
| 516 |
+
demo.launch(server_name="0.0.0.0", server_port=7860)
|
requirements.txt
ADDED
|
@@ -0,0 +1,12 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
# Requirements for HuggingFace Spaces deployment
|
| 2 |
+
# Dependencies for neural memory demo with voice
|
| 3 |
+
|
| 4 |
+
torch>=2.0.0
|
| 5 |
+
gradio>=4.0.0
|
| 6 |
+
pydantic>=2.0.0
|
| 7 |
+
pydantic-settings>=2.0.0
|
| 8 |
+
|
| 9 |
+
# Voice capabilities
|
| 10 |
+
transformers>=4.36.0 # Whisper for speech-to-text
|
| 11 |
+
edge-tts>=6.1.0 # Microsoft Edge TTS for text-to-speech
|
| 12 |
+
numpy>=1.24.0 # Audio processing
|