Spaces:
Runtime error
Runtime error
GitHub Copilot
commited on
Commit
·
7d38f33
1
Parent(s):
f3ae05d
Merged App (Retry)
Browse files
app.py
CHANGED
|
@@ -1,85 +1,85 @@
|
|
| 1 |
-
"""
|
| 2 |
-
LOGOS v1.0 - Hugging Face Space
|
| 3 |
-
Primary: Chat (casual language)
|
| 4 |
-
Secondary: Mod-10 Tension Web
|
| 5 |
-
"""
|
| 6 |
-
|
| 7 |
import gradio as gr
|
| 8 |
import numpy as np
|
| 9 |
import plotly.graph_objects as go
|
| 10 |
import sympy
|
| 11 |
-
import
|
| 12 |
import os
|
| 13 |
import sys
|
| 14 |
-
import
|
| 15 |
-
import subprocess
|
| 16 |
-
import requests
|
| 17 |
|
|
|
|
| 18 |
current_dir = os.path.dirname(os.path.abspath(__file__))
|
| 19 |
if current_dir not in sys.path:
|
| 20 |
sys.path.insert(0, current_dir)
|
| 21 |
|
| 22 |
-
# --- LOGOS CORE ---
|
| 23 |
-
MTL_AVAILABLE = False
|
| 24 |
try:
|
| 25 |
from logos.mtl.interpreter import MTLInterpreter
|
|
|
|
|
|
|
| 26 |
MTL_AVAILABLE = True
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 27 |
except ImportError:
|
| 28 |
-
|
|
|
|
| 29 |
|
| 30 |
-
|
|
|
|
|
|
|
| 31 |
|
| 32 |
def start_neural_router():
|
|
|
|
| 33 |
try:
|
| 34 |
-
subprocess.Popen(
|
| 35 |
-
[sys.executable, "-m", "logos.server"],
|
| 36 |
env={**os.environ, "PYTHONPATH": current_dir},
|
| 37 |
-
stdout=subprocess.
|
|
|
|
|
|
|
|
|
|
| 38 |
)
|
| 39 |
-
|
| 40 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 41 |
|
| 42 |
threading.Thread(target=start_neural_router, daemon=True).start()
|
| 43 |
|
| 44 |
-
#
|
| 45 |
-
|
| 46 |
-
# =============================================================================
|
| 47 |
-
def chat_handler(message, history):
|
| 48 |
-
"""Handle casual language input."""
|
| 49 |
-
if not message.strip():
|
| 50 |
-
return history
|
| 51 |
-
|
| 52 |
-
history = history + [[message, None]]
|
| 53 |
-
msg = message.lower().strip()
|
| 54 |
-
|
| 55 |
try:
|
| 56 |
-
|
| 57 |
-
|
| 58 |
-
resp = requests.post(f"{ROUTER_URL}/v1/chat/completions", json=payload, timeout=60)
|
| 59 |
-
if resp.status_code == 200:
|
| 60 |
-
bot = resp.json()['choices'][0]['message']['content']
|
| 61 |
-
else:
|
| 62 |
-
bot = "Router unavailable. Start: python -m logos.server"
|
| 63 |
except:
|
| 64 |
-
|
| 65 |
-
|
| 66 |
-
history[-1][1] = bot
|
| 67 |
-
return history
|
| 68 |
|
| 69 |
-
|
| 70 |
-
|
| 71 |
-
|
| 72 |
-
|
| 73 |
-
|
| 74 |
-
"""
|
| 75 |
-
Mod-10 Tension Web - Radial network with connections.
|
| 76 |
-
Each mod-10 lane (1,3,7,9) is a spoke.
|
| 77 |
-
Nodes connected by factor relationships.
|
| 78 |
-
"""
|
| 79 |
-
fig = go.Figure()
|
| 80 |
|
| 81 |
-
|
| 82 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 83 |
def run_mtl_demo() -> str:
|
| 84 |
"""Run a demonstration of MTL capabilities."""
|
| 85 |
if not MTL_AVAILABLE:
|
|
@@ -88,372 +88,142 @@ def run_mtl_demo() -> str:
|
|
| 88 |
try:
|
| 89 |
mtl = MTLInterpreter()
|
| 90 |
output = []
|
| 91 |
-
|
| 92 |
output.append("=== LOGOS MTL DEMONSTRATION ===\n")
|
| 93 |
-
|
| 94 |
-
# Basic arithmetic
|
| 95 |
output.append("[1] Tensor Multiplication")
|
| 96 |
r = mtl.execute('(mult [2] [3])')
|
| 97 |
output.append(f" (mult [2] [3]) = {r} (MECHANISM x RESULT = FLIP)")
|
| 98 |
|
| 99 |
-
# Logic gates
|
| 100 |
output.append("\n[2] Logic Gates")
|
| 101 |
r = mtl.execute('(or [2] [3])')
|
| 102 |
output.append(f" (or [2] [3]) = {r} (LCM - Superposition)")
|
| 103 |
r = mtl.execute('(and [6] [10])')
|
| 104 |
output.append(f" (and [6] [10]) = {r} (GCD - Intersection)")
|
| 105 |
|
| 106 |
-
# Factorial
|
| 107 |
output.append("\n[3] Recursive Function (Factorial)")
|
| 108 |
mtl.execute('(defun factorial (n) (if (lt? n 2) 1 (mult n (factorial (sub n 1)))))')
|
| 109 |
r = mtl.execute('(factorial 5)')
|
| 110 |
output.append(f" (factorial 5) = {r}")
|
| 111 |
|
| 112 |
-
# Synapse
|
| 113 |
output.append("\n[4] Knowledge Graph (Synapse)")
|
| 114 |
r = mtl.execute('(relate [17] [19])')
|
| 115 |
output.append(f" (relate [17] [19]) = {r} (IMAGE x TEXT x RELATE)")
|
| 116 |
|
| 117 |
output.append("\n=== TURING COMPLETENESS VERIFIED ===")
|
| 118 |
-
|
| 119 |
return "\n".join(output)
|
| 120 |
except Exception as e:
|
| 121 |
return f"Demo Error: {str(e)}"
|
| 122 |
|
| 123 |
# --- PHYSICS VISUALIZERS ---
|
| 124 |
def get_prime_topology(max_n=500):
|
| 125 |
-
"""
|
| 126 |
-
LOGOS Concentric Log Polar Cone Topology.
|
| 127 |
-
- Each ring = mod 10 (decade layer)
|
| 128 |
-
- Special lanes: mod 1, 3, 7, 9 (prime-generating residues)
|
| 129 |
-
"""
|
| 130 |
import math
|
| 131 |
fig = go.Figure()
|
| 132 |
-
|
| 133 |
-
# Generate numbers and categorize by mod 10
|
| 134 |
all_nums = list(range(1, max_n))
|
| 135 |
-
|
| 136 |
-
# Color by mod 10 residue class
|
| 137 |
residue_colors = {
|
| 138 |
-
1: '#00ffea',
|
| 139 |
-
|
| 140 |
-
7: '#ffff00', # Yellow - Prime lane
|
| 141 |
-
9: '#00ff00', # Green - Prime lane
|
| 142 |
-
0: '#333333', # Gray - Even decade
|
| 143 |
-
2: '#333333', 4: '#333333', 5: '#333333',
|
| 144 |
-
6: '#333333', 8: '#333333'
|
| 145 |
}
|
| 146 |
-
|
| 147 |
-
|
| 148 |
-
|
| 149 |
-
|
| 150 |
-
|
| 151 |
-
# Log polar coordinates
|
| 152 |
-
# r = log10(n) gives concentric rings per decade
|
| 153 |
-
# theta = (n mod 10) * 36 degrees + offset for spread
|
| 154 |
-
r = [math.log10(n) if n > 0 else 0 for n in nums_in_class]
|
| 155 |
-
theta = [(n % 100) * 3.6 for n in nums_in_class] # Spread within decade
|
| 156 |
-
|
| 157 |
-
# Mark primes
|
| 158 |
-
is_prime = [sympy.isprime(n) for n in nums_in_class]
|
| 159 |
sizes = [12 if p else 4 for p in is_prime]
|
| 160 |
colors = [residue_colors[residue] if p else '#555555' for p in is_prime]
|
| 161 |
-
|
| 162 |
fig.add_trace(go.Scatterpolar(
|
| 163 |
-
r=r,
|
| 164 |
-
|
| 165 |
-
|
| 166 |
-
marker=dict(
|
| 167 |
-
color=colors,
|
| 168 |
-
size=sizes,
|
| 169 |
-
line=dict(color='white', width=0.3),
|
| 170 |
-
opacity=0.8
|
| 171 |
-
),
|
| 172 |
-
text=[f"{n} (mod10={residue})" for n in nums_in_class],
|
| 173 |
-
hoverinfo='text',
|
| 174 |
name=f'Mod {residue}'
|
| 175 |
))
|
| 176 |
-
|
| 177 |
-
# Add ring labels for decades
|
| 178 |
-
for decade in [10, 100]:
|
| 179 |
-
r_ring = math.log10(decade)
|
| 180 |
-
theta_ring = list(range(0, 360, 10))
|
| 181 |
-
fig.add_trace(go.Scatterpolar(
|
| 182 |
-
r=[r_ring] * len(theta_ring),
|
| 183 |
-
theta=theta_ring,
|
| 184 |
-
mode='lines',
|
| 185 |
-
line=dict(color='rgba(255,255,255,0.2)', width=1, dash='dot'),
|
| 186 |
-
showlegend=False
|
| 187 |
-
))
|
| 188 |
-
|
| 189 |
fig.update_layout(
|
| 190 |
-
|
| 191 |
-
|
| 192 |
-
|
| 193 |
-
|
| 194 |
-
|
| 195 |
-
polar=dict(
|
| 196 |
-
radialaxis=dict(
|
| 197 |
-
visible=True,
|
| 198 |
-
range=[0, 3],
|
| 199 |
-
ticktext=['1', '10', '100', '1000'],
|
| 200 |
-
tickvals=[0, 1, 2, 3],
|
| 201 |
-
gridcolor='rgba(255,255,255,0.1)'
|
| 202 |
-
),
|
| 203 |
-
angularaxis=dict(
|
| 204 |
-
visible=True,
|
| 205 |
-
gridcolor='rgba(255,255,255,0.1)'
|
| 206 |
-
),
|
| 207 |
-
bgcolor='rgba(11,15,25,0.9)'
|
| 208 |
-
),
|
| 209 |
-
margin=dict(l=40, r=40, t=40, b=40),
|
| 210 |
-
height=550,
|
| 211 |
-
title=dict(
|
| 212 |
-
text="LOGOS Log Polar Cone (Mod 10 Rings)",
|
| 213 |
-
font=dict(color='white')
|
| 214 |
-
)
|
| 215 |
)
|
| 216 |
return fig
|
| 217 |
|
| 218 |
-
def
|
| 219 |
-
"""
|
| 220 |
-
|
| 221 |
-
|
| 222 |
-
|
| 223 |
-
|
| 224 |
-
|
| 225 |
-
|
| 226 |
-
|
| 227 |
-
|
| 228 |
-
|
| 229 |
-
19: (180, "TEXT", "#00aaff"), # Blue
|
| 230 |
-
23: (252, "AUDIO", "#ff8800"), # Orange
|
| 231 |
-
29: (324, "SIGNAL", "#ff0088"), # Pink
|
| 232 |
-
}
|
| 233 |
-
|
| 234 |
-
# Draw connection lines (factors)
|
| 235 |
-
connection_traces = []
|
| 236 |
-
for p1, (a1, n1, c1) in genesis.items():
|
| 237 |
-
for p2, (a2, n2, c2) in genesis.items():
|
| 238 |
-
if p1 < p2:
|
| 239 |
-
# Composite = p1 * p2
|
| 240 |
-
composite = p1 * p2
|
| 241 |
-
# Draw faint connection line
|
| 242 |
-
r1, r2 = math.log10(p1 + 1) * 0.8, math.log10(p2 + 1) * 0.8
|
| 243 |
-
fig.add_trace(go.Scatterpolar(
|
| 244 |
-
r=[r1, r2],
|
| 245 |
-
theta=[a1, a2],
|
| 246 |
-
mode='lines',
|
| 247 |
-
line=dict(color='rgba(100,100,150,0.15)', width=1),
|
| 248 |
-
showlegend=False,
|
| 249 |
-
hoverinfo='skip'
|
| 250 |
-
))
|
| 251 |
-
|
| 252 |
-
# Draw prime nodes on spokes
|
| 253 |
-
for prime, (angle, name, color) in genesis.items():
|
| 254 |
-
if prime == 2:
|
| 255 |
-
r = 0.1 # Center
|
| 256 |
-
size = 40
|
| 257 |
-
else:
|
| 258 |
-
r = math.log10(prime) * 0.8
|
| 259 |
-
size = 25
|
| 260 |
-
|
| 261 |
-
fig.add_trace(go.Scatterpolar(
|
| 262 |
-
r=[r],
|
| 263 |
-
theta=[angle],
|
| 264 |
-
mode='markers+text',
|
| 265 |
-
marker=dict(color=color, size=size, line=dict(color='white', width=2)),
|
| 266 |
-
text=[str(prime)],
|
| 267 |
-
textposition='middle center',
|
| 268 |
-
textfont=dict(color='black' if prime == 2 else 'white', size=10, family='Arial Black'),
|
| 269 |
-
name=name,
|
| 270 |
-
hovertext=f"[{prime}] {name}",
|
| 271 |
-
hoverinfo='text'
|
| 272 |
-
))
|
| 273 |
-
|
| 274 |
-
# Draw mod-10 lanes as subtle radial lines
|
| 275 |
-
for angle in [0, 36, 72, 108, 144, 180, 216, 252, 288, 324]:
|
| 276 |
-
fig.add_trace(go.Scatterpolar(
|
| 277 |
-
r=[0, 1.8],
|
| 278 |
-
theta=[angle, angle],
|
| 279 |
-
mode='lines',
|
| 280 |
-
line=dict(color='rgba(255,255,255,0.08)', width=1),
|
| 281 |
-
showlegend=False,
|
| 282 |
-
hoverinfo='skip'
|
| 283 |
-
))
|
| 284 |
-
|
| 285 |
-
# Draw concentric rings (decades)
|
| 286 |
-
for r_val in [0.3, 0.7, 1.1, 1.5]:
|
| 287 |
-
theta_ring = list(range(0, 361, 5))
|
| 288 |
-
fig.add_trace(go.Scatterpolar(
|
| 289 |
-
r=[r_val] * len(theta_ring),
|
| 290 |
-
theta=theta_ring,
|
| 291 |
-
mode='lines',
|
| 292 |
-
line=dict(color='rgba(255,255,255,0.1)', width=1),
|
| 293 |
-
showlegend=False,
|
| 294 |
-
hoverinfo='skip'
|
| 295 |
-
))
|
| 296 |
-
|
| 297 |
-
fig.update_layout(
|
| 298 |
-
paper_bgcolor='#0a0e17',
|
| 299 |
-
plot_bgcolor='#0a0e17',
|
| 300 |
-
showlegend=False,
|
| 301 |
-
polar=dict(
|
| 302 |
-
radialaxis=dict(visible=False, range=[0, 1.8]),
|
| 303 |
-
angularaxis=dict(visible=False),
|
| 304 |
-
bgcolor='#0a0e17'
|
| 305 |
-
),
|
| 306 |
-
margin=dict(l=20, r=20, t=50, b=20),
|
| 307 |
-
height=500,
|
| 308 |
-
title=dict(
|
| 309 |
-
text="MOD-10 TENSION WEB",
|
| 310 |
-
font=dict(color='#00ffea', size=14),
|
| 311 |
-
x=0.5
|
| 312 |
-
)
|
| 313 |
-
)
|
| 314 |
-
return fig
|
| 315 |
|
| 316 |
-
#
|
| 317 |
-
|
| 318 |
-
|
| 319 |
-
CSS = """
|
| 320 |
-
.gradio-container { background: #0a0e17 !important; }
|
| 321 |
-
.chat-box { border: 1px solid rgba(0,255,234,0.3); border-radius: 12px; }
|
| 322 |
-
"""
|
| 323 |
|
| 324 |
-
|
| 325 |
-
|
| 326 |
-
|
| 327 |
-
|
| 328 |
-
|
| 329 |
-
|
| 330 |
-
<div style="text-align:center; padding:1rem;">
|
| 331 |
-
<h1 style="color:#00ffea; margin:0;">LOGOS</h1>
|
| 332 |
-
<p style="color:#666; font-size:0.9rem;">Logarithmic Ordering Generation Operating Software</p>
|
| 333 |
</div>
|
| 334 |
-
"""
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 335 |
|
|
|
|
|
|
|
|
|
|
| 336 |
with gr.Tabs():
|
| 337 |
-
|
| 338 |
-
# TAB 1: CHAT
|
| 339 |
-
with gr.TabItem("Chat"):
|
| 340 |
-
chatbot = gr.Chatbot(height=400)
|
| 341 |
-
msg = gr.Textbox(placeholder="Ask me anything...", label="Message")
|
| 342 |
with gr.Row():
|
| 343 |
-
|
| 344 |
-
|
| 345 |
-
=======
|
| 346 |
-
with gr.Column(scale=2):
|
| 347 |
-
mtl_input = gr.Textbox(
|
| 348 |
-
label="MTL Code",
|
| 349 |
-
placeholder="(mult [2] [3])",
|
| 350 |
-
lines=3
|
| 351 |
-
)
|
| 352 |
-
mtl_examples = gr.Examples(
|
| 353 |
-
examples=[
|
| 354 |
-
["(mult [2] [3])"],
|
| 355 |
-
["(or [17] [19])"],
|
| 356 |
-
["(and [6] [10])"],
|
| 357 |
-
["(relate [17] [19])"],
|
| 358 |
-
["(fractran [[5 2] [5 3]] 72)"],
|
| 359 |
-
],
|
| 360 |
-
inputs=mtl_input
|
| 361 |
-
)
|
| 362 |
-
mtl_run = gr.Button("Execute MTL", variant="primary")
|
| 363 |
with gr.Column(scale=1):
|
| 364 |
-
|
| 365 |
-
|
| 366 |
-
|
| 367 |
|
| 368 |
-
|
| 369 |
-
|
| 370 |
-
|
| 371 |
-
|
| 372 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 373 |
with gr.Row():
|
| 374 |
-
|
| 375 |
-
|
| 376 |
-
|
| 377 |
-
|
| 378 |
-
|
| 379 |
-
|
| 380 |
-
| Prime | Concept |
|
| 381 |
-
|-------|---------|
|
| 382 |
-
| [2] | MECHANISM |
|
| 383 |
-
| [3] | RESULT |
|
| 384 |
-
| [5] | CHOICE |
|
| 385 |
-
| [7] | PERSIST |
|
| 386 |
-
| [11] | WHY |
|
| 387 |
-
| [13] | RELATE |
|
| 388 |
-
| [17] | IMAGE |
|
| 389 |
-
| [19] | TEXT |
|
| 390 |
-
| [23] | AUDIO |
|
| 391 |
-
| [29] | SIGNAL |
|
| 392 |
-
|
| 393 |
-
*Every concept is a Prime. Every file is a Number.*
|
| 394 |
-
""")
|
| 395 |
-
|
| 396 |
-
# TAB C: PRIME TOPOLOGY
|
| 397 |
with gr.Tab("Prime Topology"):
|
| 398 |
-
|
| 399 |
-
with gr.Column():
|
| 400 |
-
prime_plot = gr.Plot(value=get_prime_topology(), label="Log Polar Cone")
|
| 401 |
-
with gr.Column():
|
| 402 |
-
gr.Markdown("""
|
| 403 |
-
### LOGOS Log Polar Cone Topology
|
| 404 |
-
|
| 405 |
-
**Concentric rings = Mod 10 decades**
|
| 406 |
-
|
| 407 |
-
**Prime Lanes (Mod 10 residues):**
|
| 408 |
-
- **Cyan (1)**: Numbers ending in 1
|
| 409 |
-
- **Magenta (3)**: Numbers ending in 3
|
| 410 |
-
- **Yellow (7)**: Numbers ending in 7
|
| 411 |
-
- **Green (9)**: Numbers ending in 9
|
| 412 |
-
|
| 413 |
-
Large dots = **Primes** (only end in 1,3,7,9)
|
| 414 |
-
|
| 415 |
-
*Arithmetic is Architecture.*
|
| 416 |
-
""")
|
| 417 |
-
|
| 418 |
-
# TAB D: RECURSIVE REASONING
|
| 419 |
-
with gr.Tab("Chat"):
|
| 420 |
-
with gr.Column(elem_classes=["chat-container"]):
|
| 421 |
-
chatbot = gr.Chatbot(label="LOGOS Router")
|
| 422 |
-
msg = gr.Textbox(label="Message", placeholder="Ask LOGOS...")
|
| 423 |
-
>>>>>>> 512b27f (Fix: LOGOS Log Polar Cone Topology (mod 10 rings, 1/3/7/9 lanes))
|
| 424 |
-
clear = gr.Button("Clear")
|
| 425 |
|
| 426 |
-
|
| 427 |
-
|
| 428 |
-
|
| 429 |
-
|
| 430 |
-
|
| 431 |
-
|
| 432 |
-
|
| 433 |
-
|
| 434 |
-
|
| 435 |
-
|
| 436 |
-
|
| 437 |
-
|
| 438 |
-
|
| 439 |
-
|
| 440 |
-
|
| 441 |
-
# TAB 3: MTL
|
| 442 |
-
with gr.TabItem("MTL"):
|
| 443 |
-
mtl_in = gr.Textbox(label="Code", value="(mult [2] [3])")
|
| 444 |
-
mtl_run = gr.Button("Run")
|
| 445 |
-
mtl_out = gr.Textbox(label="Result")
|
| 446 |
-
|
| 447 |
-
def run_mtl(code):
|
| 448 |
-
if not MTL_AVAILABLE: return "MTL unavailable"
|
| 449 |
-
try:
|
| 450 |
-
return str(MTLInterpreter().execute(code))
|
| 451 |
-
except Exception as e:
|
| 452 |
-
return str(e)
|
| 453 |
-
|
| 454 |
-
mtl_run.click(run_mtl, mtl_in, mtl_out)
|
| 455 |
-
|
| 456 |
-
gr.HTML("<div style='text-align:center;color:#444;font-size:0.8rem;padding:1rem;'>LOGOS v1.0</div>")
|
| 457 |
|
| 458 |
if __name__ == "__main__":
|
| 459 |
-
demo.launch(server_name="0.0.0.0", server_port=7860)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
import gradio as gr
|
| 2 |
import numpy as np
|
| 3 |
import plotly.graph_objects as go
|
| 4 |
import sympy
|
| 5 |
+
import time
|
| 6 |
import os
|
| 7 |
import sys
|
| 8 |
+
from collections import Counter
|
|
|
|
|
|
|
| 9 |
|
| 10 |
+
# Ensure logos package is importable
|
| 11 |
current_dir = os.path.dirname(os.path.abspath(__file__))
|
| 12 |
if current_dir not in sys.path:
|
| 13 |
sys.path.insert(0, current_dir)
|
| 14 |
|
| 15 |
+
# --- LOGOS CORE IMPORTS ---
|
|
|
|
| 16 |
try:
|
| 17 |
from logos.mtl.interpreter import MTLInterpreter
|
| 18 |
+
from logos.memory.prime_db import PrimeTokenDB
|
| 19 |
+
from logos.models.polar_matroska import PolarMatroska
|
| 20 |
MTL_AVAILABLE = True
|
| 21 |
+
print("[LOGOS] MTL Interpreter & Models loaded successfully")
|
| 22 |
+
except ImportError as e:
|
| 23 |
+
MTL_AVAILABLE = False
|
| 24 |
+
print(f"[LOGOS] MTL not available: {e}")
|
| 25 |
+
|
| 26 |
+
try:
|
| 27 |
+
from logos.dsp_bridge import DSPBridge
|
| 28 |
+
from logos.logos_core import PRIME_MODULO
|
| 29 |
+
print(f"[LOGOS] Successfully imported DSPBridge")
|
| 30 |
except ImportError:
|
| 31 |
+
DSPBridge = None
|
| 32 |
+
PRIME_MODULO = 9973
|
| 33 |
|
| 34 |
+
# --- PROTOCOL 26: START NEURAL ROUTER ---
|
| 35 |
+
import threading
|
| 36 |
+
import subprocess
|
| 37 |
|
| 38 |
def start_neural_router():
|
| 39 |
+
print("[SYSTEM] Igniting Neural Router (Port 5000)...")
|
| 40 |
try:
|
| 41 |
+
process = subprocess.Popen(
|
| 42 |
+
[sys.executable, "-m", "logos.server"],
|
| 43 |
env={**os.environ, "PYTHONPATH": current_dir},
|
| 44 |
+
stdout=subprocess.PIPE,
|
| 45 |
+
stderr=subprocess.STDOUT,
|
| 46 |
+
text=True,
|
| 47 |
+
bufsize=1
|
| 48 |
)
|
| 49 |
+
print(f"[OK] Neural Router Process ID: {process.pid}")
|
| 50 |
+
|
| 51 |
+
def stream_logs(p):
|
| 52 |
+
for line in iter(p.stdout.readline, ''):
|
| 53 |
+
print(f"[ROUTER] {line.strip()}")
|
| 54 |
+
|
| 55 |
+
threading.Thread(target=stream_logs, args=(process,), daemon=True).start()
|
| 56 |
+
|
| 57 |
+
except Exception as e:
|
| 58 |
+
print(f"[X] Failed to start Neural Router: {e}")
|
| 59 |
|
| 60 |
threading.Thread(target=start_neural_router, daemon=True).start()
|
| 61 |
|
| 62 |
+
# --- THEME LOADING ---
|
| 63 |
+
def load_css():
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 64 |
try:
|
| 65 |
+
with open(os.path.join(current_dir, "style.css"), "r") as f:
|
| 66 |
+
return f.read()
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 67 |
except:
|
| 68 |
+
return ""
|
|
|
|
|
|
|
|
|
|
| 69 |
|
| 70 |
+
# --- MTL INTERPRETER INTERFACE ---
|
| 71 |
+
def execute_mtl(code: str) -> str:
|
| 72 |
+
"""Execute MTL code and return result."""
|
| 73 |
+
if not MTL_AVAILABLE:
|
| 74 |
+
return "MTL Interpreter not available in this environment"
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 75 |
|
| 76 |
+
try:
|
| 77 |
+
interpreter = MTLInterpreter()
|
| 78 |
+
result = interpreter.execute(code)
|
| 79 |
+
return f"Result: {result}"
|
| 80 |
+
except Exception as e:
|
| 81 |
+
return f"Error: {str(e)}"
|
| 82 |
+
|
| 83 |
def run_mtl_demo() -> str:
|
| 84 |
"""Run a demonstration of MTL capabilities."""
|
| 85 |
if not MTL_AVAILABLE:
|
|
|
|
| 88 |
try:
|
| 89 |
mtl = MTLInterpreter()
|
| 90 |
output = []
|
|
|
|
| 91 |
output.append("=== LOGOS MTL DEMONSTRATION ===\n")
|
|
|
|
|
|
|
| 92 |
output.append("[1] Tensor Multiplication")
|
| 93 |
r = mtl.execute('(mult [2] [3])')
|
| 94 |
output.append(f" (mult [2] [3]) = {r} (MECHANISM x RESULT = FLIP)")
|
| 95 |
|
|
|
|
| 96 |
output.append("\n[2] Logic Gates")
|
| 97 |
r = mtl.execute('(or [2] [3])')
|
| 98 |
output.append(f" (or [2] [3]) = {r} (LCM - Superposition)")
|
| 99 |
r = mtl.execute('(and [6] [10])')
|
| 100 |
output.append(f" (and [6] [10]) = {r} (GCD - Intersection)")
|
| 101 |
|
|
|
|
| 102 |
output.append("\n[3] Recursive Function (Factorial)")
|
| 103 |
mtl.execute('(defun factorial (n) (if (lt? n 2) 1 (mult n (factorial (sub n 1)))))')
|
| 104 |
r = mtl.execute('(factorial 5)')
|
| 105 |
output.append(f" (factorial 5) = {r}")
|
| 106 |
|
|
|
|
| 107 |
output.append("\n[4] Knowledge Graph (Synapse)")
|
| 108 |
r = mtl.execute('(relate [17] [19])')
|
| 109 |
output.append(f" (relate [17] [19]) = {r} (IMAGE x TEXT x RELATE)")
|
| 110 |
|
| 111 |
output.append("\n=== TURING COMPLETENESS VERIFIED ===")
|
|
|
|
| 112 |
return "\n".join(output)
|
| 113 |
except Exception as e:
|
| 114 |
return f"Demo Error: {str(e)}"
|
| 115 |
|
| 116 |
# --- PHYSICS VISUALIZERS ---
|
| 117 |
def get_prime_topology(max_n=500):
|
| 118 |
+
"""LOGOS Concentric Log Polar Cone Topology."""
|
|
|
|
|
|
|
|
|
|
|
|
|
| 119 |
import math
|
| 120 |
fig = go.Figure()
|
|
|
|
|
|
|
| 121 |
all_nums = list(range(1, max_n))
|
|
|
|
|
|
|
| 122 |
residue_colors = {
|
| 123 |
+
1: '#00ffea', 3: '#ff00ff', 7: '#ffff00', 9: '#00ff00',
|
| 124 |
+
0: '#333333', 2: '#333333', 4: '#333333', 6: '#333333', 8: '#333333'
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 125 |
}
|
| 126 |
+
for residue in [1, 3, 7, 9]:
|
| 127 |
+
nums = [n for n in all_nums if n % 10 == residue]
|
| 128 |
+
r = [math.log10(n) if n > 0 else 0 for n in nums]
|
| 129 |
+
theta = [(n % 100) * 3.6 for n in nums]
|
| 130 |
+
is_prime = [sympy.isprime(n) for n in nums]
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 131 |
sizes = [12 if p else 4 for p in is_prime]
|
| 132 |
colors = [residue_colors[residue] if p else '#555555' for p in is_prime]
|
|
|
|
| 133 |
fig.add_trace(go.Scatterpolar(
|
| 134 |
+
r=r, theta=theta, mode='markers',
|
| 135 |
+
marker=dict(size=sizes, color=colors, line=dict(color='white', width=0.3), opacity=0.8),
|
| 136 |
+
text=[f"{n} (mod10={residue})" for n in nums], hoverinfo='text',
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 137 |
name=f'Mod {residue}'
|
| 138 |
))
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 139 |
fig.update_layout(
|
| 140 |
+
template="plotly_dark", paper_bgcolor='rgba(0,0,0,0)', plot_bgcolor='rgba(0,0,0,0)',
|
| 141 |
+
showlegend=True, legend=dict(font=dict(color='white')),
|
| 142 |
+
polar=dict(radialaxis=dict(visible=True, range=[0, 3], tickvals=[0, 1, 2, 3], ticktext=['1', '10', '100', '1000']), angularaxis=dict(visible=True), bgcolor='rgba(11,15,25,0.9)'),
|
| 143 |
+
margin=dict(l=40, r=40, t=40, b=40), height=550,
|
| 144 |
+
title=dict(text="LOGOS Log Polar Cone", font=dict(color='white'))
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 145 |
)
|
| 146 |
return fig
|
| 147 |
|
| 148 |
+
def get_polar_matroska_viz():
|
| 149 |
+
"""Visualizes the Active Knowledge Base (Protocol 35)."""
|
| 150 |
+
if not MTL_AVAILABLE: return None
|
| 151 |
+
try:
|
| 152 |
+
pm = PolarMatroska()
|
| 153 |
+
success = pm.load_knowledge()
|
| 154 |
+
if not success: return None
|
| 155 |
+
return pm.visualize()
|
| 156 |
+
except Exception as e:
|
| 157 |
+
print(f"PM Viz Error: {e}")
|
| 158 |
+
return None
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 159 |
|
| 160 |
+
# --- UI ---
|
| 161 |
+
PROTOCOL_NAME = "LOGOS v2.0 (Stratos)"
|
| 162 |
+
SUBTITLE = "Protocol 35-44: Matroska + Semantics + Cortex + RPC"
|
|
|
|
|
|
|
|
|
|
|
|
|
| 163 |
|
| 164 |
+
def fetch_manifold_diagnostics():
|
| 165 |
+
"""Polls diagnostic state."""
|
| 166 |
+
status = "ONLINE" if MTL_AVAILABLE else "DEGRADED"
|
| 167 |
+
html = f"""
|
| 168 |
+
<div style='background: rgba(0,255,100,0.1); padding: 10px; border: 1px solid #00ff66; border-radius: 5px; color: #00ff66;'>
|
| 169 |
+
LOGOS SYSTEM: {status}
|
|
|
|
|
|
|
|
|
|
| 170 |
</div>
|
| 171 |
+
"""
|
| 172 |
+
return html
|
| 173 |
+
|
| 174 |
+
with gr.Blocks(title="LOGOS Stratos") as demo:
|
| 175 |
+
with gr.Link(rel="stylesheet", href="style.css"): pass
|
| 176 |
+
with gr.Row():
|
| 177 |
+
gr.Markdown(f"# {PROTOCOL_NAME}\n**{SUBTITLE}**")
|
| 178 |
|
| 179 |
+
with gr.Row():
|
| 180 |
+
status_panel = gr.HTML(fetch_manifold_diagnostics())
|
| 181 |
+
|
| 182 |
with gr.Tabs():
|
| 183 |
+
with gr.Tab("Polar Matroska (Protocol 35)"):
|
|
|
|
|
|
|
|
|
|
|
|
|
| 184 |
with gr.Row():
|
| 185 |
+
with gr.Column(scale=3):
|
| 186 |
+
pm_plot = gr.Plot(label="Knowledge Manifold")
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 187 |
with gr.Column(scale=1):
|
| 188 |
+
pm_btn = gr.Button("Build Network", variant="primary")
|
| 189 |
+
pm_stats = gr.Textbox(label="Status")
|
| 190 |
+
gr.Markdown("Visualize the Semantic Heat Map. Radius = Binary Entropy. Theta = Prime Sector.")
|
| 191 |
|
| 192 |
+
def load_pm():
|
| 193 |
+
fig = get_polar_matroska_viz()
|
| 194 |
+
if fig: return fig, "Network Active"
|
| 195 |
+
return None, "Network Failed"
|
| 196 |
+
|
| 197 |
+
pm_btn.click(load_pm, outputs=[pm_plot, pm_stats])
|
| 198 |
+
demo.load(load_pm, outputs=[pm_plot, pm_stats])
|
| 199 |
+
|
| 200 |
+
with gr.Tab("MTL Interpreter"):
|
| 201 |
+
mtl_input = gr.Textbox(label="MTL Code", lines=3, placeholder="(recall \"structure\")")
|
| 202 |
with gr.Row():
|
| 203 |
+
mtl_run = gr.Button("Execute", variant="primary")
|
| 204 |
+
mtl_demo = gr.Button("Run Demo")
|
| 205 |
+
mtl_output = gr.Textbox(label="Result", lines=5)
|
| 206 |
+
mtl_run.click(execute_mtl, inputs=mtl_input, outputs=mtl_output)
|
| 207 |
+
mtl_demo.click(run_mtl_demo, outputs=mtl_output)
|
| 208 |
+
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 209 |
with gr.Tab("Prime Topology"):
|
| 210 |
+
gr.Plot(value=get_prime_topology(), label="Log Polar Cone")
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 211 |
|
| 212 |
+
with gr.Tab("RPC Validator"):
|
| 213 |
+
rpc_input = gr.Textbox(label="Stream (Comma Separated Integers)", placeholder="2, 3, 5, 7, 11")
|
| 214 |
+
rpc_btn = gr.Button("Validate Phase Signal")
|
| 215 |
+
rpc_out = gr.Textbox(label="RPC Score")
|
| 216 |
+
|
| 217 |
+
def val_rpc(txt):
|
| 218 |
+
from logos.analysis.rpc_validator import PhaseSpaceValidator
|
| 219 |
+
try:
|
| 220 |
+
nums = [int(x.strip()) for x in txt.split(',') if x.strip()]
|
| 221 |
+
score = PhaseSpaceValidator().get_rpc_score(nums)
|
| 222 |
+
return f"RPC Score: {score:.4f}"
|
| 223 |
+
except Exception as e:
|
| 224 |
+
return f"Error: {e}"
|
| 225 |
+
|
| 226 |
+
rpc_btn.click(val_rpc, inputs=rpc_input, outputs=rpc_out)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 227 |
|
| 228 |
if __name__ == "__main__":
|
| 229 |
+
demo.launch(server_name="0.0.0.0", server_port=7860, css=load_css())
|