Spaces:
Runtime error
Runtime error
Create app.py
Browse files
app.py
ADDED
|
@@ -0,0 +1,90 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import gradio as gr
|
| 2 |
+
import numpy as np
|
| 3 |
+
import plotly.graph_objects as go
|
| 4 |
+
import sympy
|
| 5 |
+
import networkx as nx
|
| 6 |
+
|
| 7 |
+
# --- MODULE 1: SPCW LOGIC (The Primitive) ---
|
| 8 |
+
def generate_spcw_waveform(sequence_length, persistence_factor):
|
| 9 |
+
"""
|
| 10 |
+
Simulates the Scalar Prime Composite Waveform.
|
| 11 |
+
High persistence (00) = Low Heat. Change (11) = High Heat.
|
| 12 |
+
"""
|
| 13 |
+
# 1. Generate Primes (The Logic Backbone)
|
| 14 |
+
primes = list(sympy.primerange(0, sequence_length))
|
| 15 |
+
|
| 16 |
+
# 2. Simulate "Heat" based on Prime Gaps (your logic)
|
| 17 |
+
x = np.arange(len(primes))
|
| 18 |
+
# Synthetic "Heat" metric based on gap delta
|
| 19 |
+
heat = np.diff(primes, prepend=0) * (1 - persistence_factor)
|
| 20 |
+
|
| 21 |
+
# 3. Create Visualization (The "Heat Map")
|
| 22 |
+
fig = go.Figure()
|
| 23 |
+
fig.add_trace(go.Scatter(x=x, y=primes, mode='lines+markers', name='Prime Scalar'))
|
| 24 |
+
fig.add_trace(go.Bar(x=x, y=heat, name='Delta Heat (Change Energy)'))
|
| 25 |
+
|
| 26 |
+
fig.update_layout(title="SPCW Persistence & Change Matrix", template="plotly_dark")
|
| 27 |
+
return fig
|
| 28 |
+
|
| 29 |
+
# --- MODULE 2: MATROSKA TOPOLOGY (The Network) ---
|
| 30 |
+
def visualize_matroska_network(shells):
|
| 31 |
+
"""
|
| 32 |
+
Creates a concentric 'Matroska' network visualization.
|
| 33 |
+
"""
|
| 34 |
+
G = nx.Graph()
|
| 35 |
+
pos = {}
|
| 36 |
+
|
| 37 |
+
# Create concentric shells
|
| 38 |
+
for i in range(1, shells + 1):
|
| 39 |
+
radius = i * 5
|
| 40 |
+
nodes_in_layer = i * 6 # Hexagonal growth pattern
|
| 41 |
+
for j in range(nodes_in_layer):
|
| 42 |
+
node_id = f"L{i}-{j}"
|
| 43 |
+
angle = (2 * np.pi * j) / nodes_in_layer
|
| 44 |
+
pos[node_id] = (radius * np.cos(angle), radius * np.sin(angle))
|
| 45 |
+
G.add_node(node_id, layer=i)
|
| 46 |
+
|
| 47 |
+
# Connect to previous shell (The "Persistence" Link)
|
| 48 |
+
if i > 1:
|
| 49 |
+
prev_node = f"L{i-1}-{int(j/nodes_in_layer * ((i-1)*6))}"
|
| 50 |
+
G.add_edge(node_id, prev_node)
|
| 51 |
+
|
| 52 |
+
# Extract positions for Plotly
|
| 53 |
+
edge_x = []
|
| 54 |
+
edge_y = []
|
| 55 |
+
for edge in G.edges():
|
| 56 |
+
x0, y0 = pos[edge[0]]
|
| 57 |
+
x1, y1 = pos[edge[1]]
|
| 58 |
+
edge_x.extend([x0, x1, None])
|
| 59 |
+
edge_y.extend([y0, y1, None])
|
| 60 |
+
|
| 61 |
+
node_x = [pos[node][0] for node in G.nodes()]
|
| 62 |
+
node_y = [pos[node][1] for node in G.nodes()]
|
| 63 |
+
|
| 64 |
+
fig = go.Figure(data=[
|
| 65 |
+
go.Scatter(x=edge_x, y=edge_y, line=dict(width=0.5, color='#888'), hoverinfo='none', mode='lines'),
|
| 66 |
+
go.Scatter(x=node_x, y=node_y, mode='markers', marker=dict(color='cyan', size=5))
|
| 67 |
+
])
|
| 68 |
+
fig.update_layout(title="Modular Concentric Prime Matroska Network", showlegend=False, template="plotly_dark")
|
| 69 |
+
return fig
|
| 70 |
+
|
| 71 |
+
# --- THE INTERFACE ---
|
| 72 |
+
with gr.Blocks(theme=gr.themes.Monochrome()) as demo:
|
| 73 |
+
gr.Markdown("# LOGOS: Modular Concentric Prime Matroska Network")
|
| 74 |
+
gr.Markdown("Interactive architectural validation for SPCW and Nested Domains.")
|
| 75 |
+
|
| 76 |
+
with gr.Tab("SPCW Waveform"):
|
| 77 |
+
with gr.Row():
|
| 78 |
+
seq_len = gr.Slider(10, 1000, value=100, label="Sequence Length")
|
| 79 |
+
per_factor = gr.Slider(0.0, 1.0, value=0.5, label="Persistence Factor (00 State)")
|
| 80 |
+
spcw_plot = gr.Plot(label="Persistence/Change Matrix")
|
| 81 |
+
btn_spcw = gr.Button("Generate Waveform")
|
| 82 |
+
btn_spcw.click(generate_spcw_waveform, inputs=[seq_len, per_factor], outputs=spcw_plot)
|
| 83 |
+
|
| 84 |
+
with gr.Tab("Matroska Topology"):
|
| 85 |
+
shells_slider = gr.Slider(1, 10, value=3, step=1, label="Nesting Depth (Shells)")
|
| 86 |
+
matroska_plot = gr.Plot(label="Network Topology")
|
| 87 |
+
btn_net = gr.Button("Build Network")
|
| 88 |
+
btn_net.click(visualize_matroska_network, inputs=[shells_slider], outputs=matroska_plot)
|
| 89 |
+
|
| 90 |
+
demo.launch()
|