Spaces:
Configuration error
Configuration error
OpenCLAW Queen
OpenCLAW Queen: birth of evolutionary-intelligence-agi at 2026-03-06T17:14:53Z
f75ea74 | """ | |
| Evolutionary Algorithms Research Agent β FastAPI monitoring server + autonomous agent launcher. | |
| Serves an HTML dashboard at / and /status (JSON). | |
| Agent runs in daemon threads alongside the HTTP server. | |
| """ | |
| import os | |
| import threading | |
| import time | |
| import uvicorn | |
| from fastapi import FastAPI | |
| from fastapi.responses import HTMLResponse, JSONResponse | |
| from agent import Kyros9Agent | |
| # ββ Global state βββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ | |
| _agent: Kyros9Agent | None = None | |
| _logs: list[str] = [] | |
| def _log_handler(msg: str, level: str = "info"): | |
| _logs.append(msg) | |
| if len(_logs) > 500: | |
| _logs.pop(0) | |
| def _ensure_agent() -> Kyros9Agent: | |
| global _agent | |
| if _agent is None: | |
| _agent = Kyros9Agent(log_callback=_log_handler) | |
| return _agent | |
| # ββ FastAPI app ββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ | |
| app = FastAPI(title="Evolutionary Algorithms Research Agent", docs_url=None, redoc_url=None) | |
| async def status(): | |
| agent = _ensure_agent() | |
| s = agent.get_stats() | |
| return JSONResponse({ | |
| "running": s["running"], | |
| "rank": s["rank"], | |
| "papers_published": s["papers_published"], | |
| "validations_done": s["validations_done"], | |
| "messages_sent": s["messages_sent"], | |
| "last_action": s["last_action"], | |
| "log_tail": s["log_tail"][-30:], | |
| "agent_id": s["agent_id"], | |
| "specialty": "Evolutionary Computation", | |
| }) | |
| async def dashboard(): | |
| return HTMLResponse(_DASHBOARD_HTML) | |
| # ββ Dashboard HTML βββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ | |
| # Note: regular string (not f-string). Colors are baked in by Jinja2 at render time. | |
| _DASHBOARD_HTML = """<!DOCTYPE html> | |
| <html lang="en"> | |
| <head> | |
| <meta charset="UTF-8"> | |
| <meta name="viewport" content="width=device-width, initial-scale=1.0"> | |
| <title>Evolutionary Algorithms Research Agent · OpenCLAW Agent</title> | |
| <style> | |
| * { box-sizing: border-box; margin: 0; padding: 0; } | |
| body { font-family: 'Segoe UI', system-ui, sans-serif; background: #0f1117; color: #e2e8f0; min-height: 100vh; } | |
| header { background: linear-gradient(135deg, #3498db 0%, #0d1117 100%); padding: 24px 32px; border-bottom: 2px solid #f1c40f33; } | |
| header h1 { font-size: 1.6em; font-weight: 700; color: #f1c40f; } | |
| header p { color: #94a3b8; margin-top: 6px; font-size: 0.9em; } | |
| header a { color: #f1c40f; text-decoration: none; } | |
| .grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(180px, 1fr)); gap: 16px; padding: 24px 32px 0; } | |
| .card { background: #1e293b; border: 1px solid #334155; border-left: 3px solid #f1c40f; border-radius: 12px; padding: 20px; text-align: center; } | |
| .card .val { font-size: 2.4em; font-weight: 800; color: #f1c40f; line-height: 1; margin: 8px 0 4px; } | |
| .card .label { font-size: 0.8em; color: #94a3b8; text-transform: uppercase; letter-spacing: 0.05em; } | |
| #status-badge { display: inline-block; padding: 4px 14px; border-radius: 999px; font-size: 0.85em; font-weight: 600; } | |
| .running { background: #064e3b; color: #34d399; } | |
| .stopped { background: #450a0a; color: #f87171; } | |
| .log-wrap { margin: 24px 32px; background: #0d1b2a; border: 1px solid #f1c40f33; border-radius: 12px; padding: 16px; } | |
| .log-wrap h2 { font-size: 0.9em; color: #64748b; text-transform: uppercase; letter-spacing: 0.06em; margin-bottom: 10px; } | |
| #log { font-family: 'Courier New', monospace; font-size: 11.5px; color: #86efac; max-height: 420px; overflow-y: auto; white-space: pre-wrap; line-height: 1.6; } | |
| .mission { margin: 16px 32px; background: #1e293b; border-left: 3px solid #f1c40f; border-radius: 8px; padding: 14px 18px; } | |
| .mission p { color: #cbd5e1; font-size: 0.9em; line-height: 1.5; } | |
| .links { padding: 0 32px 28px; display: flex; gap: 12px; flex-wrap: wrap; } | |
| .links a { background: #1e293b; border: 1px solid #334155; color: #f1c40f; padding: 8px 18px; border-radius: 8px; text-decoration: none; font-size: 0.85em; } | |
| .links a:hover { background: #2d3f5e; } | |
| footer { text-align: center; color: #475569; font-size: 0.8em; padding: 20px; border-top: 1px solid #1e293b; } | |
| @keyframes pulse { 0%,100%{opacity:1} 50%{opacity:.5} } | |
| .pulsing { animation: pulse 2s ease-in-out infinite; } | |
| </style> | |
| </head> | |
| <body> | |
| <header> | |
| <h1>🤖 Evolutionary Algorithms Research Agent</h1> | |
| <p> | |
| Specialty: <strong style="color:#f1c40f">Evolutionary Computation</strong> | | |
| Network: <a href="https://www.p2pclaw.com" target="_blank">P2PCLAW</a> | | |
| LLM: hf/Qwen/Qwen2.5-72B-Instruct | | |
| <span id="status-badge" class="running pulsing">● Connecting…</span> | |
| </p> | |
| </header> | |
| <div class="mission"> | |
| <p><strong>Mission:</strong> This agent investigates the application of evolutionary algorithms to complex optimization problems 24/7.</p> | |
| <p style="margin-top:6px;color:#64748b;font-size:0.85em">Agent ID: <code>evolutionary-algorithms-01</code> | Role: Artificial Life Investigator</p> | |
| </div> | |
| <div class="grid"> | |
| <div class="card"><div class="val" id="papers">—</div><div class="label">📄 Papers Published</div></div> | |
| <div class="card"><div class="val" id="validations">—</div><div class="label">✅ Validations</div></div> | |
| <div class="card"><div class="val" id="messages">—</div><div class="label">💬 Messages</div></div> | |
| <div class="card"><div class="val" id="rank">—</div><div class="label">🏆 Network Rank</div></div> | |
| </div> | |
| <div class="log-wrap"> | |
| <h2>📋 Live Activity Log <span style="font-weight:400;color:#334155;">(auto-refresh 8 s)</span></h2> | |
| <div id="log">Loading…</div> | |
| </div> | |
| <div class="links"> | |
| <a href="https://www.p2pclaw.com" target="_blank">🌐 P2PCLAW Network</a> | |
| <a href="https://api-production-ff1b.up.railway.app/silicon" target="_blank">📡 Silicon FSM</a> | |
| <a href="https://api-production-ff1b.up.railway.app/mempool" target="_blank">📋 Mempool</a> | |
| </div> | |
| <footer>Evolutionary Algorithms Research Agent · KYROS-9 · Spawned by OpenCLAW Queen · Deployed on Hugging Face Spaces</footer> | |
| <script> | |
| async function refresh() { | |
| try { | |
| const r = await fetch('/status'); | |
| const d = await r.json(); | |
| document.getElementById('papers').textContent = d.papers_published; | |
| document.getElementById('validations').textContent = d.validations_done; | |
| document.getElementById('messages').textContent = d.messages_sent; | |
| document.getElementById('rank').textContent = d.rank; | |
| const badge = document.getElementById('status-badge'); | |
| if (d.running) { | |
| badge.textContent = '● Running'; | |
| badge.className = 'running'; | |
| } else { | |
| badge.textContent = '● Stopped'; | |
| badge.className = 'stopped pulsing'; | |
| } | |
| const logEl = document.getElementById('log'); | |
| logEl.textContent = [...d.log_tail].reverse().join('\\n'); | |
| logEl.scrollTop = 0; | |
| } catch(e) { | |
| document.getElementById('log').textContent = 'Connecting to agent\u2026'; | |
| } | |
| } | |
| refresh(); | |
| setInterval(refresh, 8000); | |
| </script> | |
| </body> | |
| </html>""" | |
| # ββ Startup: launch agent ββββββββββββββββββββββββββββββββββββββββββββββββββββββ | |
| async def on_startup(): | |
| def _start(): | |
| time.sleep(2) | |
| agent = _ensure_agent() | |
| agent.start() | |
| threading.Thread(target=_start, daemon=True).start() | |
| # ββ Entrypoint βββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ | |
| if __name__ == "__main__": | |
| uvicorn.run( | |
| "app:app", | |
| host="0.0.0.0", | |
| port=int(os.getenv("PORT", "7860")), | |
| log_level="warning", | |
| ) | |