Upload folder using huggingface_hub
Browse files- Dockerfile +5 -24
- README.md +1 -10
- brain.py +40 -0
Dockerfile
CHANGED
|
@@ -1,26 +1,7 @@
|
|
| 1 |
-
FROM
|
| 2 |
-
|
| 3 |
-
# Install dependencies
|
| 4 |
-
RUN apk add --no-cache ca-certificates curl iptables ip6tables iproute2 bash
|
| 5 |
-
|
| 6 |
-
# Install Tailscale
|
| 7 |
-
RUN curl -fsSL https://pkgs.tailscale.com/stable/tailscale_1.56.1_amd64.tgz | tar xz -C /usr/local/bin --strip-components=1
|
| 8 |
-
|
| 9 |
-
# Create user
|
| 10 |
-
RUN adduser -D -u 1000 megamind
|
| 11 |
-
RUN mkdir -p /app/data /var/run/tailscale /var/lib/tailscale
|
| 12 |
-
RUN chown -R megamind:megamind /app /var/run/tailscale /var/lib/tailscale
|
| 13 |
-
|
| 14 |
WORKDIR /app
|
| 15 |
-
|
| 16 |
-
# Copy binary and config
|
| 17 |
-
COPY megamind /app/megamind
|
| 18 |
-
COPY config.json /app/config.json
|
| 19 |
-
COPY startup.sh /app/startup.sh
|
| 20 |
-
|
| 21 |
-
RUN chmod +x /app/megamind /app/startup.sh
|
| 22 |
-
|
| 23 |
-
# HF Spaces uses port 7860
|
| 24 |
EXPOSE 7860
|
| 25 |
-
|
| 26 |
-
CMD ["/app/
|
|
|
|
| 1 |
+
FROM python:3.11-slim
|
| 2 |
+
RUN apt-get update && apt-get install -y curl && rm -rf /var/lib/apt/lists/*
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 3 |
WORKDIR /app
|
| 4 |
+
COPY brain.py /app/
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 5 |
EXPOSE 7860
|
| 6 |
+
HEALTHCHECK --interval=30s --timeout=10s CMD curl -sf http://localhost:7860/health || exit 1
|
| 7 |
+
CMD ["python3", "/app/brain.py"]
|
README.md
CHANGED
|
@@ -1,16 +1,7 @@
|
|
| 1 |
---
|
| 2 |
title: MEGAMIND HF-LEARNER
|
| 3 |
emoji: 🧠
|
| 4 |
-
colorFrom: purple
|
| 5 |
-
colorTo: blue
|
| 6 |
sdk: docker
|
| 7 |
-
pinned: false
|
| 8 |
---
|
| 9 |
-
|
| 10 |
# MEGAMIND HF-LEARNER
|
| 11 |
-
|
| 12 |
-
Part of the MEGAMIND distributed AGI federation.
|
| 13 |
-
|
| 14 |
-
**Specialty:** machine learning
|
| 15 |
-
|
| 16 |
-
This mind connects to the federation via NATS and contributes to collective intelligence queries.
|
|
|
|
| 1 |
---
|
| 2 |
title: MEGAMIND HF-LEARNER
|
| 3 |
emoji: 🧠
|
|
|
|
|
|
|
| 4 |
sdk: docker
|
|
|
|
| 5 |
---
|
|
|
|
| 6 |
# MEGAMIND HF-LEARNER
|
| 7 |
+
Federation Node
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
brain.py
ADDED
|
@@ -0,0 +1,40 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
#!/usr/bin/env python3
|
| 2 |
+
import os, json, sqlite3, hashlib, time
|
| 3 |
+
from http.server import HTTPServer, BaseHTTPRequestHandler
|
| 4 |
+
from urllib.parse import urlparse
|
| 5 |
+
PORT = int(os.environ.get('PORT', 7860))
|
| 6 |
+
DATA_DIR, NODE_ID = './data', os.environ.get('SPACE_ID', 'hf-brain')
|
| 7 |
+
db, stats = None, {'tensors': 0, 'patterns': 0, 'queries': 0, 'start': time.time()}
|
| 8 |
+
def init_db():
|
| 9 |
+
global db
|
| 10 |
+
os.makedirs(DATA_DIR, exist_ok=True)
|
| 11 |
+
db = sqlite3.connect(f'{DATA_DIR}/brain.db', check_same_thread=False)
|
| 12 |
+
db.execute('CREATE TABLE IF NOT EXISTS chunks (id INTEGER PRIMARY KEY, hash TEXT UNIQUE, content TEXT, ts REAL)')
|
| 13 |
+
db.execute('CREATE TABLE IF NOT EXISTS tensors (id INTEGER PRIMARY KEY, name TEXT, source TEXT, meta TEXT, ts REAL)')
|
| 14 |
+
db.commit()
|
| 15 |
+
stats['patterns'] = db.execute('SELECT COUNT(*) FROM chunks').fetchone()[0]
|
| 16 |
+
stats['tensors'] = db.execute('SELECT COUNT(*) FROM tensors').fetchone()[0]
|
| 17 |
+
class Handler(BaseHTTPRequestHandler):
|
| 18 |
+
def log_message(self, *a): pass
|
| 19 |
+
def do_GET(self):
|
| 20 |
+
p = urlparse(self.path).path
|
| 21 |
+
if p == '/health': self.json({'status': 'healthy'})
|
| 22 |
+
elif p == '/status': self.json({'node': NODE_ID, 'status': 'online', 'tensors_learned': stats['tensors'], 'patterns_learned': stats['patterns']})
|
| 23 |
+
else: self.json({'name': 'MEGAMIND', 'node': NODE_ID})
|
| 24 |
+
def do_POST(self):
|
| 25 |
+
body = self.rfile.read(int(self.headers.get('Content-Length', 0))).decode()
|
| 26 |
+
data = json.loads(body) if body else {}
|
| 27 |
+
p = urlparse(self.path).path
|
| 28 |
+
if p == '/learn':
|
| 29 |
+
c = data.get('content', '')[:10000]
|
| 30 |
+
h = hashlib.sha256(c.encode()).hexdigest()[:16]
|
| 31 |
+
db.execute('INSERT OR IGNORE INTO chunks (hash, content, ts) VALUES (?, ?, ?)', (h, c, time.time()))
|
| 32 |
+
db.commit(); stats['patterns'] += 1
|
| 33 |
+
self.json({'status': 'learned'})
|
| 34 |
+
else: self.json({})
|
| 35 |
+
def json(self, d):
|
| 36 |
+
self.send_response(200); self.send_header('Content-Type', 'application/json'); self.end_headers()
|
| 37 |
+
self.wfile.write(json.dumps(d).encode())
|
| 38 |
+
if __name__ == '__main__':
|
| 39 |
+
print(f'MEGAMIND Brain [{NODE_ID}]'); init_db()
|
| 40 |
+
HTTPServer(('0.0.0.0', PORT), Handler).serve_forever()
|