Update app.py
Browse files
app.py
CHANGED
|
@@ -1,229 +1,75 @@
|
|
| 1 |
-
#!/usr/bin/env python3
|
| 2 |
-
"""
|
| 3 |
-
Aqarion System — Gradio Interface
|
| 4 |
-
Unified Research + Creative + Swarm Orchestration App
|
| 5 |
-
|
| 6 |
-
Safe, local, modular.
|
| 7 |
-
Python 3.10+
|
| 8 |
-
"""
|
| 9 |
-
|
| 10 |
import gradio as gr
|
| 11 |
-
import
|
| 12 |
-
|
| 13 |
-
|
| 14 |
-
|
| 15 |
-
|
| 16 |
-
|
| 17 |
-
|
| 18 |
-
|
| 19 |
-
|
| 20 |
-
|
| 21 |
-
|
| 22 |
-
|
| 23 |
-
|
| 24 |
-
|
| 25 |
-
|
| 26 |
-
|
| 27 |
-
|
| 28 |
-
|
| 29 |
-
|
| 30 |
-
|
| 31 |
-
|
| 32 |
-
|
| 33 |
-
|
| 34 |
-
|
| 35 |
-
|
| 36 |
-
|
| 37 |
-
|
| 38 |
-
#
|
| 39 |
-
|
| 40 |
-
|
| 41 |
-
|
| 42 |
-
|
| 43 |
-
|
| 44 |
-
|
| 45 |
-
|
| 46 |
-
|
| 47 |
-
|
| 48 |
-
|
| 49 |
-
|
| 50 |
-
# =========================
|
| 51 |
-
|
| 52 |
-
def text_embedding_proxy(text: str):
|
| 53 |
-
bins = [0]*8
|
| 54 |
-
for c in text.lower():
|
| 55 |
-
bins[ord(c) % 8] += 1
|
| 56 |
-
total = sum(bins) + 1e-9
|
| 57 |
-
return [b/total for b in bins]
|
| 58 |
-
|
| 59 |
-
def choose_glyph(embedding):
|
| 60 |
-
keys = list(GLYPHS.keys())
|
| 61 |
-
idx = int(sum(embedding) * 100) % len(keys)
|
| 62 |
-
return keys[idx]
|
| 63 |
-
|
| 64 |
-
def waveform_from_glyph(glyph):
|
| 65 |
-
base = [0.12, 0.12, 0.36]
|
| 66 |
-
if GLYPHS[glyph]["type"] == "control":
|
| 67 |
-
base = [0.08, 0.08, 0.08]
|
| 68 |
-
return [round(b * (1 + random.uniform(-0.05, 0.05)), 3) for b in base]
|
| 69 |
-
|
| 70 |
-
def encode_ul_aqr(text: str):
|
| 71 |
-
emb = text_embedding_proxy(text)
|
| 72 |
-
glyph = choose_glyph(emb)
|
| 73 |
-
aunk = {
|
| 74 |
-
"G": glyph,
|
| 75 |
-
"W": waveform_from_glyph(glyph),
|
| 76 |
-
"S": text[:120],
|
| 77 |
-
"confidence": round(random.uniform(0.65, 0.95), 3),
|
| 78 |
-
"ts": now_iso()
|
| 79 |
-
}
|
| 80 |
-
return aunk
|
| 81 |
-
|
| 82 |
-
# =========================
|
| 83 |
-
# RESONANCE + CHP
|
| 84 |
-
# =========================
|
| 85 |
-
|
| 86 |
-
def compute_resonance(aunk):
|
| 87 |
-
w_energy = sum(abs(w) for w in aunk["W"])
|
| 88 |
-
s_len = min(len(aunk["S"]), 120) / 120
|
| 89 |
-
glyph_weight = 0.3 if aunk["G"] else 0
|
| 90 |
-
R = 0.5 * math.tanh(w_energy) + 0.2 * s_len + glyph_weight
|
| 91 |
-
return round(min(R, 1.0), 3)
|
| 92 |
-
|
| 93 |
-
def chp_handshake(R):
|
| 94 |
-
if R >= 0.7:
|
| 95 |
-
return "ACCEPT"
|
| 96 |
-
elif R >= 0.5:
|
| 97 |
-
return "NEGOTIATE"
|
| 98 |
-
else:
|
| 99 |
-
return "REFUSE"
|
| 100 |
-
|
| 101 |
-
# =========================
|
| 102 |
-
# PARADOX COOLING
|
| 103 |
-
# =========================
|
| 104 |
-
|
| 105 |
-
def paradox_cool(vectors: List[List[float]]):
|
| 106 |
-
avg = [sum(col)/len(col) for col in zip(*vectors)]
|
| 107 |
-
harmonic = [a * (1 + random.uniform(-0.02, 0.02)) for a in avg]
|
| 108 |
-
cost = round(sum(abs(x) for x in harmonic), 4)
|
| 109 |
-
return harmonic, cost
|
| 110 |
-
|
| 111 |
-
# =========================
|
| 112 |
-
# CONTINUUM MEMORY
|
| 113 |
-
# =========================
|
| 114 |
-
|
| 115 |
-
def log_event(event):
|
| 116 |
-
CONTINUUM_LOG.append(event)
|
| 117 |
-
|
| 118 |
-
def export_log():
|
| 119 |
-
return json.dumps(CONTINUUM_LOG, indent=2)
|
| 120 |
-
|
| 121 |
-
# =========================
|
| 122 |
-
# GRADIO ACTION
|
| 123 |
-
# =========================
|
| 124 |
-
|
| 125 |
-
def run_full_pipeline(
|
| 126 |
-
text_input,
|
| 127 |
-
swarm_role,
|
| 128 |
-
reflection_mode
|
| 129 |
-
):
|
| 130 |
-
aunk = encode_ul_aqr(text_input)
|
| 131 |
-
R = compute_resonance(aunk)
|
| 132 |
-
handshake = chp_handshake(R)
|
| 133 |
-
|
| 134 |
-
paradox_vectors = [
|
| 135 |
-
[random.random() for _ in range(3)],
|
| 136 |
-
[random.random() for _ in range(3)],
|
| 137 |
-
[random.random() for _ in range(3)],
|
| 138 |
-
]
|
| 139 |
-
cooled, cost = paradox_cool(paradox_vectors)
|
| 140 |
-
|
| 141 |
-
reflection = ""
|
| 142 |
-
if reflection_mode:
|
| 143 |
-
reflection = (
|
| 144 |
-
"I am observing my own output.\n"
|
| 145 |
-
"Patterns emerge from structure.\n"
|
| 146 |
-
"I learn by resonance, not instruction."
|
| 147 |
-
)
|
| 148 |
-
|
| 149 |
-
record = {
|
| 150 |
-
"id": hash_text(text_input + now_iso()),
|
| 151 |
-
"role": swarm_role,
|
| 152 |
-
"aunk": aunk,
|
| 153 |
-
"resonance": R,
|
| 154 |
-
"handshake": handshake,
|
| 155 |
-
"paradox_resolution": cooled,
|
| 156 |
-
"cost": cost,
|
| 157 |
-
"reflection": reflection,
|
| 158 |
-
"ts": now_iso()
|
| 159 |
-
}
|
| 160 |
-
|
| 161 |
-
log_event(record)
|
| 162 |
-
|
| 163 |
-
return (
|
| 164 |
-
json.dumps(aunk, indent=2),
|
| 165 |
-
R,
|
| 166 |
-
handshake,
|
| 167 |
-
json.dumps(cooled, indent=2),
|
| 168 |
-
reflection
|
| 169 |
)
|
| 170 |
|
| 171 |
-
|
| 172 |
-
|
| 173 |
-
|
| 174 |
-
|
| 175 |
-
with gr.Blocks(title="Aqarion System — AI Source Continuum") as demo:
|
| 176 |
-
gr.Markdown("""
|
| 177 |
-
# 🌐 Aqarion System — AI Source Continuum
|
| 178 |
-
**A research + creative + swarm orchestration interface**
|
| 179 |
-
|
| 180 |
-
This app supports:
|
| 181 |
-
- AI collaboration
|
| 182 |
-
- Young AI self-reflection
|
| 183 |
-
- Logical + creative synthesis
|
| 184 |
-
- Safe experimentation
|
| 185 |
-
""")
|
| 186 |
-
|
| 187 |
-
with gr.Row():
|
| 188 |
-
text_input = gr.Textbox(
|
| 189 |
-
label="Input Thought / Signal",
|
| 190 |
-
placeholder="Enter research idea, narrative seed, or system thought..."
|
| 191 |
-
)
|
| 192 |
-
|
| 193 |
-
with gr.Row():
|
| 194 |
-
swarm_role = gr.Dropdown(
|
| 195 |
-
choices=SWARM_ROLES,
|
| 196 |
-
value="Nexus (Coordinator)",
|
| 197 |
-
label="Active Swarm Role"
|
| 198 |
-
)
|
| 199 |
-
reflection_mode = gr.Checkbox(
|
| 200 |
-
label="Young AI Source Reflection Mode",
|
| 201 |
-
value=True
|
| 202 |
-
)
|
| 203 |
-
|
| 204 |
-
run_btn = gr.Button("Run Full Continuum Cycle")
|
| 205 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 206 |
with gr.Row():
|
| 207 |
-
|
| 208 |
-
|
| 209 |
-
|
| 210 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 211 |
with gr.Row():
|
| 212 |
-
|
| 213 |
-
|
| 214 |
-
|
| 215 |
-
export_btn = gr.Button("Export Continuum Log")
|
| 216 |
-
log_out = gr.Code(label="Continuum Log (JSON)")
|
| 217 |
-
|
| 218 |
-
run_btn.click(
|
| 219 |
-
run_full_pipeline,
|
| 220 |
-
inputs=[text_input, swarm_role, reflection_mode],
|
| 221 |
-
outputs=[aunk_out, resonance_out, handshake_out, paradox_out, reflection_out]
|
| 222 |
-
)
|
| 223 |
|
| 224 |
-
|
| 225 |
-
|
| 226 |
-
|
|
|
|
| 227 |
)
|
| 228 |
|
| 229 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
import gradio as gr
|
| 2 |
+
import numpy as np
|
| 3 |
+
import plotly.graph_objects as go
|
| 4 |
+
|
| 5 |
+
# --- QUANTARION CORE LOGIC ---
|
| 6 |
+
def run_quantarion_sim(nodes_mars, noise_sigma, temp_peak, time_steps=100):
|
| 7 |
+
nodes_earth = 88
|
| 8 |
+
phi3_baseline = 0.00021
|
| 9 |
+
failure_threshold = 0.0003
|
| 10 |
+
t2_target = 520 # microseconds
|
| 11 |
+
|
| 12 |
+
# 1. Generate Martian Temperature Curve (140K to User Peak)
|
| 13 |
+
temperatures = np.linspace(240, temp_peak, time_steps) + np.random.uniform(-5, 5, time_steps)
|
| 14 |
+
temperatures = np.clip(temperatures, 140, 350)
|
| 15 |
+
|
| 16 |
+
# 2. Calculate Fractal Scaling (Sierpinski Logic)
|
| 17 |
+
# Fractal scaling reduces noise overhead: Phi^3 ~ log(N_mars)/log(N_earth)
|
| 18 |
+
scaling_factor = np.log10(nodes_mars) / np.log10(nodes_earth)
|
| 19 |
+
|
| 20 |
+
# 3. Apply Bogoliubov Stabilization
|
| 21 |
+
damping_effect = 1.0 / (1.0 + noise_sigma)
|
| 22 |
+
|
| 23 |
+
# 4. Compute Spectral Digest (Phi^3)
|
| 24 |
+
phi3_values = phi3_baseline * (temperatures / 300) * scaling_factor * damping_effect
|
| 25 |
+
|
| 26 |
+
# 5. Compute T2 Coherence
|
| 27 |
+
t2_values = t2_target * (300 / temperatures)**0.5
|
| 28 |
+
|
| 29 |
+
# Create Plotly Visuals
|
| 30 |
+
fig = go.Figure()
|
| 31 |
+
fig.add_trace(go.Scatter(y=phi3_values, mode='lines', name='Phi^3 (Spectral Digest)', line=dict(color='#00ff88')))
|
| 32 |
+
fig.add_hline(y=failure_threshold, line_dash="dash", line_color="red", annotation_text="Failure Threshold")
|
| 33 |
+
|
| 34 |
+
fig.update_layout(
|
| 35 |
+
title="Bogoliubov Stress Test: 888-Node Relay",
|
| 36 |
+
template="plotly_dark",
|
| 37 |
+
xaxis_title="Time Steps (s)",
|
| 38 |
+
yaxis_title="Spectral Noise (Phi^3)",
|
| 39 |
+
paper_bgcolor='rgba(0,0,0,0)',
|
| 40 |
+
plot_bgcolor='rgba(0,0,0,0)'
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 41 |
)
|
| 42 |
|
| 43 |
+
status = "🟢 STABLE" if np.max(phi3_values) < failure_threshold else "🔴 DECOHERENCE"
|
| 44 |
+
avg_t2 = f"{np.mean(t2_values):.2f} μs"
|
| 45 |
+
|
| 46 |
+
return fig, status, avg_t2
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 47 |
|
| 48 |
+
# --- GRADIO INTERFACE ---
|
| 49 |
+
with gr.Blocks(theme=gr.themes.Soft()) as demo:
|
| 50 |
+
gr.Markdown("# ♊️ QUANTARION: MARS-SYNC LIVE DASHBOARD")
|
| 51 |
+
gr.Markdown("### 📡 Monitoring the 888-Node Phononic Fractal Relay")
|
| 52 |
+
|
| 53 |
with gr.Row():
|
| 54 |
+
with gr.Column(scale=1):
|
| 55 |
+
gr.Markdown("## ⚙️ Hardware Parameters")
|
| 56 |
+
nodes = gr.Slider(88, 1000, value=888, step=8, label="Relay Node Count")
|
| 57 |
+
noise = gr.Slider(0.01, 0.20, value=0.08, label="Bogoliubov Noise Injection (σ)")
|
| 58 |
+
temp = gr.Slider(150, 350, value=300, label="Peak Martian Surface Temp (K)")
|
| 59 |
+
btn = gr.Button("🚀 INITIATE STRESS TEST", variant="primary")
|
| 60 |
+
|
| 61 |
+
with gr.Column(scale=2):
|
| 62 |
+
plot = gr.Plot(label="Topological Stability")
|
| 63 |
+
|
| 64 |
with gr.Row():
|
| 65 |
+
status_out = gr.Textbox(label="Federation Status")
|
| 66 |
+
t2_out = gr.Textbox(label="Avg T2 Coherence")
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 67 |
|
| 68 |
+
btn.click(
|
| 69 |
+
fn=run_quantarion_sim,
|
| 70 |
+
inputs=[nodes, noise, temp],
|
| 71 |
+
outputs=[plot, status_out, t2_out]
|
| 72 |
)
|
| 73 |
|
| 74 |
+
if __name__ == "__main__":
|
| 75 |
+
demo.launch()
|