Spaces:
Runtime error
Runtime error
Update app.py
Browse files
app.py
CHANGED
|
@@ -4,10 +4,12 @@ import plotly.graph_objects as go
|
|
| 4 |
import sympy
|
| 5 |
import cv2
|
| 6 |
import time
|
|
|
|
|
|
|
| 7 |
from collections import Counter
|
| 8 |
|
| 9 |
# ==========================================
|
| 10 |
-
# PART 1:
|
| 11 |
# ==========================================
|
| 12 |
|
| 13 |
def get_gpf(n):
|
|
@@ -25,224 +27,211 @@ def get_gpf(n):
|
|
| 25 |
gpf = n
|
| 26 |
return gpf
|
| 27 |
|
| 28 |
-
def
|
| 29 |
"""
|
| 30 |
-
Visualizes the
|
| 31 |
-
|
| 32 |
-
- Layout: Radial Mod 10 (Clockwise from Top).
|
| 33 |
-
- Connections: Composites tethered to their GPF Base.
|
| 34 |
"""
|
| 35 |
-
|
|
|
|
| 36 |
|
| 37 |
-
|
| 38 |
-
|
| 39 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 40 |
|
| 41 |
-
# 1. Calculate Positions (Mod 10 Dial)
|
| 42 |
for n in range(1, max_integer + 1):
|
| 43 |
-
|
| 44 |
-
angle = np.pi/2 - (2 * np.pi * (n % 10)) / 10
|
| 45 |
radius = n
|
| 46 |
-
x = radius * np.cos(angle)
|
| 47 |
-
y = radius * np.sin(angle)
|
| 48 |
positions[n] = (x, y)
|
| 49 |
-
|
| 50 |
-
|
| 51 |
-
|
| 52 |
-
|
| 53 |
-
gpf_map[n] = gpf
|
| 54 |
-
prime_children_count[gpf] += 1
|
| 55 |
|
| 56 |
-
# 2. Draw Connectivity (The Tessellation)
|
| 57 |
if show_links:
|
| 58 |
edge_x, edge_y = [], []
|
| 59 |
for n, base in gpf_map.items():
|
| 60 |
if base in positions:
|
| 61 |
x0, y0 = positions[n]
|
| 62 |
x1, y1 = positions[base]
|
| 63 |
-
edge_x.extend([x0, x1, None])
|
| 64 |
-
|
| 65 |
-
|
| 66 |
-
fig.add_trace(go.Scatter(
|
| 67 |
-
x=edge_x, y=edge_y,
|
| 68 |
-
mode='lines',
|
| 69 |
-
line=dict(color='rgba(100, 100, 100, 0.15)', width=0.5),
|
| 70 |
-
hoverinfo='none',
|
| 71 |
-
name='GPF Gravity'
|
| 72 |
-
))
|
| 73 |
|
| 74 |
-
# 3. Draw Nodes
|
| 75 |
prime_x, prime_y, prime_size, prime_text = [], [], [], []
|
| 76 |
comp_x, comp_y, comp_text = [], [], []
|
| 77 |
|
| 78 |
for n in range(1, max_integer + 1):
|
| 79 |
x, y = positions[n]
|
| 80 |
if sympy.isprime(n) or n == 1:
|
| 81 |
-
prime_x.append(x)
|
| 82 |
-
|
| 83 |
-
weight = prime_children_count[n]
|
| 84 |
-
# Logarithmic sizing based on "Gravity" (number of composites anchored)
|
| 85 |
-
size = 5 + (np.log(weight + 1) * 6)
|
| 86 |
prime_size.append(size)
|
| 87 |
-
prime_text.append(f"
|
| 88 |
else:
|
| 89 |
-
comp_x.append(x)
|
| 90 |
-
|
| 91 |
-
comp_text.append(f"Composite: {n}<br>Base: {gpf_map.get(n)}")
|
| 92 |
-
|
| 93 |
-
fig.add_trace(go.Scatter(
|
| 94 |
-
x=comp_x, y=comp_y,
|
| 95 |
-
mode='markers',
|
| 96 |
-
marker=dict(size=3, color='#ff0055', opacity=0.5), # Red dust
|
| 97 |
-
text=comp_text, hoverinfo='text', name='Composites'
|
| 98 |
-
))
|
| 99 |
|
| 100 |
-
fig.add_trace(go.Scatter(
|
| 101 |
-
|
| 102 |
-
mode='markers',
|
| 103 |
-
marker=dict(size=prime_size, color='#00ffea', line=dict(width=1, color='white')), # Cyan anchors
|
| 104 |
-
text=prime_text, hoverinfo='text', name='Primes'
|
| 105 |
-
))
|
| 106 |
|
| 107 |
-
# 4. Draw Radial Spokes
|
| 108 |
for i in range(10):
|
| 109 |
angle = np.pi/2 - (2 * np.pi * i) / 10
|
| 110 |
-
fig.add_trace(go.Scatter(
|
| 111 |
-
x=[0, max_integer * 1.1 * np.cos(angle)],
|
| 112 |
-
y=[0, max_integer * 1.1 * np.sin(angle)],
|
| 113 |
-
mode='lines',
|
| 114 |
-
line=dict(color='#333', width=1, dash='dot'),
|
| 115 |
-
showlegend=False
|
| 116 |
-
))
|
| 117 |
|
| 118 |
-
fig.update_layout(
|
| 119 |
-
title=f"Radial Prime-Indexed Topology (Max: {max_integer})",
|
| 120 |
-
template="plotly_dark",
|
| 121 |
-
xaxis=dict(showgrid=False, zeroline=False, visible=False),
|
| 122 |
-
yaxis=dict(showgrid=False, zeroline=False, visible=False),
|
| 123 |
-
width=800, height=800,
|
| 124 |
-
showlegend=True
|
| 125 |
-
)
|
| 126 |
return fig
|
| 127 |
|
| 128 |
def visualize_gpf_counts(sequence_length):
|
| 129 |
-
"""Visualizes
|
| 130 |
gpf_counts = Counter()
|
| 131 |
for n in range(4, sequence_length):
|
| 132 |
-
if not sympy.isprime(n):
|
| 133 |
-
gpf = get_gpf(n)
|
| 134 |
-
gpf_counts[gpf] += 1
|
| 135 |
-
|
| 136 |
sorted_gpfs = sorted(gpf_counts.keys())
|
| 137 |
counts = [gpf_counts[p] for p in sorted_gpfs]
|
| 138 |
-
|
| 139 |
-
fig =
|
| 140 |
-
x=sorted_gpfs, y=counts,
|
| 141 |
-
marker_color='#ff7f00', # LOGOS Orange
|
| 142 |
-
name="Composite Count"
|
| 143 |
-
))
|
| 144 |
-
|
| 145 |
-
fig.update_layout(
|
| 146 |
-
title="Composite Density by Greatest Prime Factor (GPF)",
|
| 147 |
-
xaxis_title="Prime Base (P)",
|
| 148 |
-
yaxis_title="Composites Anchored",
|
| 149 |
-
template="plotly_dark",
|
| 150 |
-
xaxis=dict(type='category')
|
| 151 |
-
)
|
| 152 |
return fig
|
| 153 |
|
| 154 |
# ==========================================
|
| 155 |
-
# PART 2: DSP ENGINE (
|
| 156 |
# ==========================================
|
| 157 |
|
| 158 |
def calculate_ssim(img1, img2):
|
| 159 |
-
"""Calculates Structural Similarity
|
| 160 |
-
C1 = (0.01 * 255)**2
|
| 161 |
-
|
| 162 |
-
img1 = img1.astype(np.float64)
|
| 163 |
-
img2 = img2.astype(np.float64)
|
| 164 |
kernel = cv2.getGaussianKernel(11, 1.5)
|
| 165 |
window = np.outer(kernel, kernel.transpose())
|
| 166 |
-
mu1 = cv2.filter2D(img1, -1, window)[5:-5, 5:-5]
|
| 167 |
-
|
| 168 |
-
mu1_sq = mu1**2
|
| 169 |
-
mu2_sq = mu2**2
|
| 170 |
-
mu1_mu2 = mu1 * mu2
|
| 171 |
sigma1_sq = cv2.filter2D(img1**2, -1, window)[5:-5, 5:-5] - mu1_sq
|
| 172 |
sigma2_sq = cv2.filter2D(img2**2, -1, window)[5:-5, 5:-5] - mu2_sq
|
| 173 |
-
sigma12 = cv2.filter2D(img1
|
| 174 |
-
|
| 175 |
-
return ssim_map.mean()
|
| 176 |
|
| 177 |
-
def
|
| 178 |
"""
|
| 179 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
| 180 |
"""
|
| 181 |
if image is None: return None, None, "No Signal"
|
| 182 |
|
| 183 |
-
# 1. Pre-process
|
| 184 |
-
if len(image.shape) == 3:
|
| 185 |
-
|
| 186 |
-
else:
|
| 187 |
-
gray = image
|
| 188 |
h, w = gray.shape
|
| 189 |
|
| 190 |
-
# 2.
|
| 191 |
-
|
| 192 |
-
|
| 193 |
-
|
| 194 |
-
|
| 195 |
-
|
| 196 |
-
|
| 197 |
-
|
| 198 |
start_time = time.time()
|
| 199 |
atoms = []
|
|
|
|
| 200 |
|
|
|
|
| 201 |
def recursive_bake(x, y, w, h):
|
| 202 |
-
|
|
|
|
| 203 |
if region.size == 0: return
|
| 204 |
|
| 205 |
-
|
| 206 |
-
heat = np.std(region)
|
| 207 |
|
| 208 |
-
# Split Decision (
|
| 209 |
-
if
|
| 210 |
hw, hh = w // 2, h // 2
|
| 211 |
recursive_bake(x, y, hw, hh)
|
| 212 |
recursive_bake(x+hw, y, w-hw, hh)
|
| 213 |
recursive_bake(x, y+hh, hw, h-hh)
|
| 214 |
recursive_bake(x+hw, y+hh, w-hw, h-hh)
|
| 215 |
else:
|
| 216 |
-
#
|
| 217 |
avg_val = int(np.mean(region))
|
| 218 |
atoms.append((x, y, w, h, avg_val))
|
|
|
|
|
|
|
|
|
|
| 219 |
|
| 220 |
recursive_bake(0, 0, w, h)
|
| 221 |
latency = (time.time() - start_time) * 1000 # ms
|
| 222 |
|
| 223 |
-
# 4.
|
| 224 |
reconstructed = np.zeros_like(gray)
|
| 225 |
heatmap_vis = np.zeros((h, w, 3), dtype=np.uint8)
|
| 226 |
|
| 227 |
for (x, y, cw, ch, val) in atoms:
|
| 228 |
reconstructed[y:y+ch, x:x+cw] = val
|
| 229 |
-
# Visualization:
|
| 230 |
is_hot = cw < 16
|
| 231 |
color = (255, 0, 85) if is_hot else (0, 255, 234)
|
| 232 |
-
cv2.rectangle(heatmap_vis, (x, y), (x+cw, y+ch), color, 1)
|
| 233 |
|
| 234 |
-
# 5.
|
| 235 |
-
ssim = calculate_ssim(gray, reconstructed)
|
| 236 |
-
comp_ratio = 100 * (1 - (len(atoms) * 5) / (w * h))
|
|
|
|
|
|
|
|
|
|
| 237 |
|
| 238 |
stats = (
|
| 239 |
-
f"
|
| 240 |
-
f"
|
| 241 |
-
f"
|
| 242 |
-
f"
|
| 243 |
-
f"
|
| 244 |
-
f"
|
| 245 |
-
f"
|
|
|
|
|
|
|
| 246 |
)
|
| 247 |
|
| 248 |
return cv2.cvtColor(reconstructed, cv2.COLOR_GRAY2RGB), heatmap_vis, stats
|
|
@@ -253,44 +242,49 @@ def run_logos_pipeline(image, heat_tolerance, noise_level):
|
|
| 253 |
|
| 254 |
def build_demo():
|
| 255 |
with gr.Blocks(theme=gr.themes.Monochrome()) as demo:
|
| 256 |
-
gr.Markdown("# LOGOS: Systems Architecture
|
| 257 |
-
gr.Markdown("Validating **
|
| 258 |
|
| 259 |
with gr.Tabs():
|
| 260 |
-
# TAB 1:
|
| 261 |
-
with gr.Tab("1.
|
| 262 |
-
gr.Markdown("
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 263 |
with gr.Row():
|
| 264 |
rad_len = gr.Slider(100, 2000, value=500, label="Integer Range")
|
| 265 |
-
link_toggle = gr.Checkbox(value=True, label="Show
|
| 266 |
net_plot = gr.Plot(label="Radial View")
|
| 267 |
btn_net = gr.Button("Build Network")
|
| 268 |
btn_net.click(visualize_prime_network, inputs=[rad_len, link_toggle], outputs=net_plot)
|
| 269 |
|
| 270 |
-
# TAB
|
| 271 |
-
with gr.Tab("
|
| 272 |
gr.Markdown("Analyzing the 'Heat' generated by each Prime Base.")
|
| 273 |
gpf_len = gr.Slider(100, 10000, value=2500, label="Stream Depth")
|
| 274 |
gpf_plot = gr.Plot(label="GPF Distribution")
|
| 275 |
btn_gpf = gr.Button("Calculate Density")
|
| 276 |
btn_gpf.click(visualize_gpf_counts, inputs=[gpf_len], outputs=gpf_plot)
|
| 277 |
|
| 278 |
-
# TAB
|
| 279 |
-
with gr.Tab("
|
| 280 |
-
gr.Markdown("
|
| 281 |
with gr.Row():
|
| 282 |
with gr.Column():
|
| 283 |
-
|
| 284 |
-
tol = gr.Slider(0.01, 0.5, value=0.1, label="Heat Tolerance (Persistence)")
|
| 285 |
-
noise = gr.Slider(0.0, 5.0, value=0.0, label="Noise Injection (Interference)")
|
| 286 |
btn_run = gr.Button("TRANSMIT STREAM", variant="primary")
|
| 287 |
-
out_stats = gr.Textbox(label="Telemetry", lines=
|
| 288 |
|
| 289 |
with gr.Column():
|
| 290 |
out_img = gr.Image(label="Reconstructed Signal")
|
| 291 |
-
out_heat = gr.Image(label="
|
| 292 |
|
| 293 |
-
btn_run.click(
|
| 294 |
|
| 295 |
return demo
|
| 296 |
|
|
|
|
| 4 |
import sympy
|
| 5 |
import cv2
|
| 6 |
import time
|
| 7 |
+
import sys
|
| 8 |
+
import os
|
| 9 |
from collections import Counter
|
| 10 |
|
| 11 |
# ==========================================
|
| 12 |
+
# PART 1: THEORETICAL PRIMITIVES
|
| 13 |
# ==========================================
|
| 14 |
|
| 15 |
def get_gpf(n):
|
|
|
|
| 27 |
gpf = n
|
| 28 |
return gpf
|
| 29 |
|
| 30 |
+
def visualize_potentiality_flow():
|
| 31 |
"""
|
| 32 |
+
Visualizes the 'Arrow' logic: Mod 10 digits directing flow into Prime Potentiality.
|
| 33 |
+
Uses a Sankey Diagram to show 1, 3, 7, 9 as the only valid paths to 'P_n'.
|
|
|
|
|
|
|
| 34 |
"""
|
| 35 |
+
# Nodes: [0: Source] -> [1-10: Digits 0-9] -> [11: Composite Sink] -> [12: Prime Potential]
|
| 36 |
+
labels = ["Integer Stream"] + [f"Ends in {i}" for i in range(10)] + ["Composite Sink (Ground)", "Prime Potential (P_n)"]
|
| 37 |
|
| 38 |
+
sources = []
|
| 39 |
+
targets = []
|
| 40 |
+
values = []
|
| 41 |
+
colors = []
|
| 42 |
+
|
| 43 |
+
# Link Source to Digits
|
| 44 |
+
for i in range(10):
|
| 45 |
+
sources.append(0)
|
| 46 |
+
targets.append(i + 1)
|
| 47 |
+
values.append(10)
|
| 48 |
+
colors.append("#444") # Neutral stream
|
| 49 |
+
|
| 50 |
+
# Link Digits to Destination
|
| 51 |
+
prime_lanes = [1, 3, 7, 9] # Digits 1, 3, 7, 9
|
| 52 |
+
|
| 53 |
+
for i in range(10):
|
| 54 |
+
sources.append(i + 1)
|
| 55 |
+
if i in prime_lanes:
|
| 56 |
+
targets.append(12) # To Prime Potential
|
| 57 |
+
values.append(10)
|
| 58 |
+
colors.append("#00ffea") # Cyan Signal
|
| 59 |
+
else:
|
| 60 |
+
targets.append(11) # To Composite Sink
|
| 61 |
+
values.append(10)
|
| 62 |
+
colors.append("#ff0055") # Red Ground
|
| 63 |
+
|
| 64 |
+
fig = go.Figure(data=[go.Sankey(
|
| 65 |
+
node = dict(
|
| 66 |
+
pad = 15, thickness = 20,
|
| 67 |
+
line = dict(color = "black", width = 0.5),
|
| 68 |
+
label = labels,
|
| 69 |
+
color = ["white"] + ["#333"]*10 + ["#ff0055", "#00ffea"]
|
| 70 |
+
),
|
| 71 |
+
link = dict(
|
| 72 |
+
source = sources, target = targets, value = values, color = colors
|
| 73 |
+
))])
|
| 74 |
+
|
| 75 |
+
fig.update_layout(title="Directed Graph: Mod 10 Prime Constraints", template="plotly_dark", height=600)
|
| 76 |
+
return fig
|
| 77 |
+
|
| 78 |
+
def visualize_prime_network(max_integer, show_links):
|
| 79 |
+
"""Visualizes the Radial Prime Topology with GPF Gravity."""
|
| 80 |
+
fig = go.Figure()
|
| 81 |
+
positions, gpf_map, prime_children_count = {}, {}, Counter()
|
| 82 |
|
|
|
|
| 83 |
for n in range(1, max_integer + 1):
|
| 84 |
+
angle = np.pi/2 - (2 * np.pi * (n % 10)) / 10 # Clockwise from Top
|
|
|
|
| 85 |
radius = n
|
| 86 |
+
x, y = radius * np.cos(angle), radius * np.sin(angle)
|
|
|
|
| 87 |
positions[n] = (x, y)
|
| 88 |
+
if n > 1 and not sympy.isprime(n):
|
| 89 |
+
gpf = get_gpf(n)
|
| 90 |
+
gpf_map[n] = gpf
|
| 91 |
+
prime_children_count[gpf] += 1
|
|
|
|
|
|
|
| 92 |
|
|
|
|
| 93 |
if show_links:
|
| 94 |
edge_x, edge_y = [], []
|
| 95 |
for n, base in gpf_map.items():
|
| 96 |
if base in positions:
|
| 97 |
x0, y0 = positions[n]
|
| 98 |
x1, y1 = positions[base]
|
| 99 |
+
edge_x.extend([x0, x1, None]); edge_y.extend([y0, y1, None])
|
| 100 |
+
fig.add_trace(go.Scatter(x=edge_x, y=edge_y, mode='lines', line=dict(color='rgba(100,100,100,0.15)', width=0.5), hoverinfo='none', name='GPF Gravity'))
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 101 |
|
|
|
|
| 102 |
prime_x, prime_y, prime_size, prime_text = [], [], [], []
|
| 103 |
comp_x, comp_y, comp_text = [], [], []
|
| 104 |
|
| 105 |
for n in range(1, max_integer + 1):
|
| 106 |
x, y = positions[n]
|
| 107 |
if sympy.isprime(n) or n == 1:
|
| 108 |
+
prime_x.append(x); prime_y.append(y)
|
| 109 |
+
size = 5 + (np.log(prime_children_count[n] + 1) * 6)
|
|
|
|
|
|
|
|
|
|
| 110 |
prime_size.append(size)
|
| 111 |
+
prime_text.append(f"PRIME: {n}<br>Gravity: {prime_children_count[n]}")
|
| 112 |
else:
|
| 113 |
+
comp_x.append(x); comp_y.append(y)
|
| 114 |
+
comp_text.append(f"Composite: {n}")
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 115 |
|
| 116 |
+
fig.add_trace(go.Scatter(x=comp_x, y=comp_y, mode='markers', marker=dict(size=3, color='#ff0055', opacity=0.5), text=comp_text, hoverinfo='text', name='Composites'))
|
| 117 |
+
fig.add_trace(go.Scatter(x=prime_x, y=prime_y, mode='markers', marker=dict(size=prime_size, color='#00ffea', line=dict(width=1, color='white')), text=prime_text, hoverinfo='text', name='Primes'))
|
|
|
|
|
|
|
|
|
|
|
|
|
| 118 |
|
|
|
|
| 119 |
for i in range(10):
|
| 120 |
angle = np.pi/2 - (2 * np.pi * i) / 10
|
| 121 |
+
fig.add_trace(go.Scatter(x=[0, max_integer * 1.1 * np.cos(angle)], y=[0, max_integer * 1.1 * np.sin(angle)], mode='lines', line=dict(color='#222', width=1, dash='dot'), showlegend=False))
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 122 |
|
| 123 |
+
fig.update_layout(title=f"Radial Prime-Indexed Topology (Max: {max_integer})", template="plotly_dark", height=800, width=800, xaxis=dict(visible=False), yaxis=dict(visible=False))
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 124 |
return fig
|
| 125 |
|
| 126 |
def visualize_gpf_counts(sequence_length):
|
| 127 |
+
"""Visualizes GPF Density."""
|
| 128 |
gpf_counts = Counter()
|
| 129 |
for n in range(4, sequence_length):
|
| 130 |
+
if not sympy.isprime(n): gpf_counts[get_gpf(n)] += 1
|
|
|
|
|
|
|
|
|
|
| 131 |
sorted_gpfs = sorted(gpf_counts.keys())
|
| 132 |
counts = [gpf_counts[p] for p in sorted_gpfs]
|
| 133 |
+
fig = go.Figure(data=go.Bar(x=sorted_gpfs, y=counts, marker_color='#ff7f00', name="Composite Count"))
|
| 134 |
+
fig.update_layout(title="Composite Density by GPF Base", xaxis_title="Prime Base", yaxis_title="Count", template="plotly_dark", xaxis=dict(type='category'))
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 135 |
return fig
|
| 136 |
|
| 137 |
# ==========================================
|
| 138 |
+
# PART 2: DSP ENGINE (AUTOMATED)
|
| 139 |
# ==========================================
|
| 140 |
|
| 141 |
def calculate_ssim(img1, img2):
|
| 142 |
+
"""Calculates Structural Similarity (Quality Metric)."""
|
| 143 |
+
C1, C2 = (0.01 * 255)**2, (0.03 * 255)**2
|
| 144 |
+
img1, img2 = img1.astype(np.float64), img2.astype(np.float64)
|
|
|
|
|
|
|
| 145 |
kernel = cv2.getGaussianKernel(11, 1.5)
|
| 146 |
window = np.outer(kernel, kernel.transpose())
|
| 147 |
+
mu1, mu2 = cv2.filter2D(img1, -1, window)[5:-5, 5:-5], cv2.filter2D(img2, -1, window)[5:-5, 5:-5]
|
| 148 |
+
mu1_sq, mu2_sq, mu1_mu2 = mu1**2, mu2**2, mu1*mu2
|
|
|
|
|
|
|
|
|
|
| 149 |
sigma1_sq = cv2.filter2D(img1**2, -1, window)[5:-5, 5:-5] - mu1_sq
|
| 150 |
sigma2_sq = cv2.filter2D(img2**2, -1, window)[5:-5, 5:-5] - mu2_sq
|
| 151 |
+
sigma12 = cv2.filter2D(img1*img2, -1, window)[5:-5, 5:-5] - mu1_mu2
|
| 152 |
+
return ((2 * mu1_mu2 + C1) * (2 * sigma12 + C2)) / ((mu1_sq + mu2_sq + C1) * (sigma1_sq + sigma2_sq + C2))
|
|
|
|
| 153 |
|
| 154 |
+
def run_logos_auto_bake(image):
|
| 155 |
"""
|
| 156 |
+
AUTOMATED BAKER: No sliders.
|
| 157 |
+
1. Calculates internal entropy (Global Variance).
|
| 158 |
+
2. Sets heat tolerance automatically.
|
| 159 |
+
3. Decomposes stream.
|
| 160 |
+
4. Validates Delta Heat Checksum.
|
| 161 |
"""
|
| 162 |
if image is None: return None, None, "No Signal"
|
| 163 |
|
| 164 |
+
# 1. Pre-process (Grayscale)
|
| 165 |
+
if len(image.shape) == 3: gray = cv2.cvtColor(image, cv2.COLOR_RGB2GRAY)
|
| 166 |
+
else: gray = image
|
|
|
|
|
|
|
| 167 |
h, w = gray.shape
|
| 168 |
|
| 169 |
+
# 2. INTERNAL HEAT CALCULATION (Automatic Tolerance)
|
| 170 |
+
global_variance = np.std(gray)
|
| 171 |
+
# Heuristic: Higher variance needs higher tolerance to prevent over-splitting,
|
| 172 |
+
# OR lower tolerance to capture detail?
|
| 173 |
+
# LOGOS Logic: We want to capture the CHANGE.
|
| 174 |
+
# Fixed ratio based on the "Hades Frame" success.
|
| 175 |
+
auto_tolerance = global_variance * 0.15
|
| 176 |
+
|
| 177 |
start_time = time.time()
|
| 178 |
atoms = []
|
| 179 |
+
delta_heat_sum = 0
|
| 180 |
|
| 181 |
+
# 3. RECURSIVE DISSOLUTION
|
| 182 |
def recursive_bake(x, y, w, h):
|
| 183 |
+
nonlocal delta_heat_sum
|
| 184 |
+
region = gray[y:y+h, x:x+w]
|
| 185 |
if region.size == 0: return
|
| 186 |
|
| 187 |
+
local_heat = np.std(region)
|
|
|
|
| 188 |
|
| 189 |
+
# Split Decision (Phase Change)
|
| 190 |
+
if local_heat > auto_tolerance and w > 4:
|
| 191 |
hw, hh = w // 2, h // 2
|
| 192 |
recursive_bake(x, y, hw, hh)
|
| 193 |
recursive_bake(x+hw, y, w-hw, hh)
|
| 194 |
recursive_bake(x, y+hh, hw, h-hh)
|
| 195 |
recursive_bake(x+hw, y+hh, w-hw, h-hh)
|
| 196 |
else:
|
| 197 |
+
# PERSIST ATOM (00 State)
|
| 198 |
avg_val = int(np.mean(region))
|
| 199 |
atoms.append((x, y, w, h, avg_val))
|
| 200 |
+
# Delta Heat: The "Energy" lost by averaging this block
|
| 201 |
+
# In a real video stream, this confirms the package integrity
|
| 202 |
+
delta_heat_sum += local_heat
|
| 203 |
|
| 204 |
recursive_bake(0, 0, w, h)
|
| 205 |
latency = (time.time() - start_time) * 1000 # ms
|
| 206 |
|
| 207 |
+
# 4. RECONSTRUCTION
|
| 208 |
reconstructed = np.zeros_like(gray)
|
| 209 |
heatmap_vis = np.zeros((h, w, 3), dtype=np.uint8)
|
| 210 |
|
| 211 |
for (x, y, cw, ch, val) in atoms:
|
| 212 |
reconstructed[y:y+ch, x:x+cw] = val
|
| 213 |
+
# Visualization: Red=High Freq (Change), Cyan=Low Freq (Persist)
|
| 214 |
is_hot = cw < 16
|
| 215 |
color = (255, 0, 85) if is_hot else (0, 255, 234)
|
| 216 |
+
cv2.rectangle(heatmap_vis, (x, y), (x+cw, y+ch), color, -1 if is_hot else 1)
|
| 217 |
|
| 218 |
+
# 5. TELEMETRY & CHECKSUM
|
| 219 |
+
ssim = calculate_ssim(gray, reconstructed).mean()
|
| 220 |
+
comp_ratio = 100 * (1 - (len(atoms) * 5) / (w * h))
|
| 221 |
+
|
| 222 |
+
# The Checksum: Does the heat match the atom count?
|
| 223 |
+
checksum_valid = "PASS" if delta_heat_sum > 0 else "FAIL"
|
| 224 |
|
| 225 |
stats = (
|
| 226 |
+
f"LOGOS TELEMETRY [AUTO-PILOT]\n"
|
| 227 |
+
f"----------------------------\n"
|
| 228 |
+
f"Global Entropy: {global_variance:.2f}\n"
|
| 229 |
+
f"Auto-Tolerance: {auto_tolerance:.2f}\n"
|
| 230 |
+
f"Stream Latency: {latency:.1f} ms\n"
|
| 231 |
+
f"Atom Count: {len(atoms)}\n"
|
| 232 |
+
f"Compression: {comp_ratio:.1f}%\n"
|
| 233 |
+
f"SSIM Fidelity: {ssim:.4f}\n"
|
| 234 |
+
f"Delta Heat Checksum: {checksum_valid} ({int(delta_heat_sum)})"
|
| 235 |
)
|
| 236 |
|
| 237 |
return cv2.cvtColor(reconstructed, cv2.COLOR_GRAY2RGB), heatmap_vis, stats
|
|
|
|
| 242 |
|
| 243 |
def build_demo():
|
| 244 |
with gr.Blocks(theme=gr.themes.Monochrome()) as demo:
|
| 245 |
+
gr.Markdown("# LOGOS: Systems Architecture & DSP Validator")
|
| 246 |
+
gr.Markdown("Validating **Directed Prime Constraints**, **Radial Topology**, and **Automated Stream Dissolution**.")
|
| 247 |
|
| 248 |
with gr.Tabs():
|
| 249 |
+
# TAB 1: THEORY
|
| 250 |
+
with gr.Tab("1. Prime Potentiality (Directed Flow)"):
|
| 251 |
+
gr.Markdown("Visualizing the digit constraints (1, 3, 7, 9) that direct the stream into Prime Potential.")
|
| 252 |
+
btn_flow = gr.Button("Generate Flow Graph")
|
| 253 |
+
flow_plot = gr.Plot(label="Sankey Diagram")
|
| 254 |
+
btn_flow.click(visualize_potentiality_flow, outputs=flow_plot)
|
| 255 |
+
|
| 256 |
+
# TAB 2: TOPOLOGY
|
| 257 |
+
with gr.Tab("2. Radial Prime Network"):
|
| 258 |
+
gr.Markdown("The **Natural Tessellation**: Composites anchored to their GPF Base.")
|
| 259 |
with gr.Row():
|
| 260 |
rad_len = gr.Slider(100, 2000, value=500, label="Integer Range")
|
| 261 |
+
link_toggle = gr.Checkbox(value=True, label="Show GPF Gravity")
|
| 262 |
net_plot = gr.Plot(label="Radial View")
|
| 263 |
btn_net = gr.Button("Build Network")
|
| 264 |
btn_net.click(visualize_prime_network, inputs=[rad_len, link_toggle], outputs=net_plot)
|
| 265 |
|
| 266 |
+
# TAB 3: ANALYSIS
|
| 267 |
+
with gr.Tab("3. GPF Density"):
|
| 268 |
gr.Markdown("Analyzing the 'Heat' generated by each Prime Base.")
|
| 269 |
gpf_len = gr.Slider(100, 10000, value=2500, label="Stream Depth")
|
| 270 |
gpf_plot = gr.Plot(label="GPF Distribution")
|
| 271 |
btn_gpf = gr.Button("Calculate Density")
|
| 272 |
btn_gpf.click(visualize_gpf_counts, inputs=[gpf_len], outputs=gpf_plot)
|
| 273 |
|
| 274 |
+
# TAB 4: THE LAB (AUTO)
|
| 275 |
+
with gr.Tab("4. Auto-Stream Baker"):
|
| 276 |
+
gr.Markdown("**No Sliders.** The system analyzes image entropy and sets the Heat Threshold automatically.")
|
| 277 |
with gr.Row():
|
| 278 |
with gr.Column():
|
| 279 |
+
inp_img = gr.Image(label="Source Signal (Drop 'Hades Frame' Here)", type="numpy", height=300)
|
|
|
|
|
|
|
| 280 |
btn_run = gr.Button("TRANSMIT STREAM", variant="primary")
|
| 281 |
+
out_stats = gr.Textbox(label="DSP Telemetry", lines=7)
|
| 282 |
|
| 283 |
with gr.Column():
|
| 284 |
out_img = gr.Image(label="Reconstructed Signal")
|
| 285 |
+
out_heat = gr.Image(label="Dissolution Map (Delta Heat)")
|
| 286 |
|
| 287 |
+
btn_run.click(run_logos_auto_bake, inputs=[inp_img], outputs=[out_img, out_heat, out_stats])
|
| 288 |
|
| 289 |
return demo
|
| 290 |
|