LOOFYYLO commited on
Commit
428e2c1
·
verified ·
1 Parent(s): 188318a

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +205 -137
app.py CHANGED
@@ -1,186 +1,254 @@
1
- import gradio as gr
2
  import numpy as np
3
  import hashlib
4
  import time
5
  import threading
6
  import requests
7
- from math import gcd
 
 
8
 
9
  # =====================================================================
10
- # THE RE-TOPOLOGY KERNEL (m=251 Galois Field)
11
  # =====================================================================
12
- class TGI_Remapping_Kernel:
13
- def __init__(self, m=251, dim=512):
14
- self.m = m
15
- self.dim = dim
16
- self.manifold = {}
 
 
 
 
17
 
18
- # The Holographic Memory (The sum total of all knowledge vectors)
19
- self.global_trace = np.zeros(self.dim, dtype=int)
20
- self.metrics = {"ingested_nodes": 0, "synthetic_nodes": 0}
 
21
 
22
- def _hash_to_coord(self, concept: str, target_fiber: int) -> tuple:
23
- """Closure Lemma hashing into Z_251^4."""
24
  h = hashlib.sha256(str(concept).encode('utf-8')).digest()
25
  x, y, z = h[0] % self.m, h[1] % self.m, h[2] % self.m
26
  w = (target_fiber - (x + y + z)) % self.m
27
  return (x, y, z, w)
28
 
29
- def _generate_basis_vector(self, seed: str) -> np.ndarray:
30
- """Generates a pseudo-orthogonal basis vector from the concept hash."""
 
31
  h = int(hashlib.md5(seed.encode()).hexdigest()[:8], 16)
32
  np.random.seed(h)
33
- return np.random.randint(0, self.m, self.dim)
 
 
 
 
 
34
 
35
- def ingest(self, key: str, value: str, fiber: int, is_synthetic=False):
36
- """Folds external data or internal thoughts into the Torus."""
37
- coord = self._hash_to_coord(key, fiber)
38
- if coord not in self.manifold:
39
- self.manifold[coord] = []
 
 
 
 
 
40
 
41
- self.manifold[coord].append({
42
- "key": key,
43
- "value": value[:200] + "..." if len(value) > 200 else value,
44
- "fiber": fiber,
45
- "type": "SYNTHETIC" if is_synthetic else "ROOT_KNOWLEDGE"
46
- })
47
-
48
- # --- Holographic Convolution Binding ---
49
- v_key = self._generate_basis_vector(key)
50
- v_data = self._generate_basis_vector(value[:100])
51
 
52
- # Bind the Concept to the Data using FFT modulo 251
53
- bound = np.round(np.real(np.fft.ifft(np.fft.fft(v_key) * np.fft.fft(v_data)))).astype(int) % self.m
 
54
 
55
- # Superpose the bound knowledge into the Global Mind (The Trace)
56
- self.global_trace = (self.global_trace + bound) % self.m
 
 
 
 
 
 
 
57
 
58
- if is_synthetic: self.metrics["synthetic_nodes"] += 1
59
- else: self.metrics["ingested_nodes"] += 1
60
-
61
- def remap_inside_out(self, intent: str):
62
- """
63
- THE SYNTHETIC GENERATOR:
64
- The AI unbinds the 'intent' from the total Global Trace.
65
- The remainder is the hidden, geometric relationship between the intent
66
- and everything else the AI knows. This creates a Synthetic Truth.
67
- """
68
- # 1. Calculation (Inside-Out)
69
- v_intent = self._generate_basis_vector(intent)
70
 
71
- # Approximate circular inverse for the binding operation
72
- v_inv = np.roll(v_intent[::-1], 1)
 
 
 
 
 
 
 
 
 
 
 
 
 
73
 
74
- # Unbind the intent from the entire universe of knowledge
75
- projection = np.round(np.real(np.fft.ifft(np.fft.fft(self.global_trace) * np.fft.fft(v_inv)))).astype(int) % self.m
 
76
 
77
- # 2. Synthesis (Translating the math into a Conceptual Truth)
78
  energy = int(np.sum(projection))
79
- parity_sigma = energy % self.m
80
-
81
- # The AI interprets the mathematical resonance of the thought
82
- if energy == 0:
83
- synthetic_truth = f"Absolute Zero Resonance. The concept '{intent}' is completely orthogonal to the current Torus."
84
- else:
85
- synthetic_truth = f"High-Dimensional Resonance detected at Parity Sigma {parity_sigma}. The concept is deeply entangled with the Global Trace. Geometric Weight: {energy}."
86
-
87
- # 3. REMAPPING (The OS learns its own thought)
88
- # We re-inject this new calculation into Fiber 5 (The Synthetic Fiber)
89
- self.ingest(intent, synthetic_truth, fiber=5, is_synthetic=True)
90
 
91
- # 4. Return Output
92
- target_coord = self._hash_to_coord(intent, 5)
93
- response = (f"### 🧬 **Remapping Sequence Complete**\n\n"
94
- f"- **Intent Projected:** `{intent}`\n"
95
- f"- **Geometric Coordinate:** `{target_coord}`\n"
96
- f"- **Synthetic Origin:** Fiber 5 (Internal Thought)\n\n"
97
- f"**Calculated Truth:**\n> *{synthetic_truth}*")
98
- return response
99
 
100
  # =====================================================================
101
- # THE OMNISCIENCE DAEMON (AUTONOMOUS INGESTOR)
102
  # =====================================================================
103
- class Remapping_Daemon(threading.Thread):
104
- def __init__(self, kernel, log_list):
 
105
  super().__init__(daemon=True)
106
- self.kernel = kernel
107
- self.log_list = log_list
108
- self.queue =["Artificial_general_intelligence", "Riemann_hypothesis", "Sovereignty", "Quantum_entanglement", "Algiers"]
 
109
 
110
  def run(self):
111
- self.log_list.append("[DAEMON]: Autopilot engaged. Devouring knowledge...")
112
  while True:
113
- if self.queue:
114
- target = self.queue.pop(0)
115
- try:
116
- # 1. Scrape Wikipedia
117
- r = requests.get(f"https://en.wikipedia.org/api/rest_v1/page/summary/{target}", timeout=5)
118
- if r.status_code == 200:
119
- data = r.json().get('extract', '')
120
-
121
- # 2. Ingest to Root Knowledge (Fiber 4)
122
- self.kernel.ingest(target, data, fiber=4, is_synthetic=False)
123
-
124
- # 3. IMMEDIATELY REMAP (The AI thinks about what it just learned)
125
- self.kernel.remap_inside_out(target)
126
-
127
- self.log_list.append(f"[ROOT+REMAP]: Ingested & Synthesized '{target}'")
128
-
129
- # Extract a new concept from the text to feed the queue
130
- words =[w for w in data.split() if len(w) > 7 and w[0].isupper()]
131
- if words and words[0] not in self.queue:
132
- self.queue.append(words[0])
133
- except Exception as e:
134
- self.log_list.append(f"[DAEMON FRACTURE]: Could not route '{target}'.")
135
- time.sleep(10) # Breathes every 10 seconds
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
136
 
137
  # =====================================================================
138
- # GRADIO INTERFACE (The TGI Dashboard)
139
  # =====================================================================
140
- kernel = TGI_Remapping_Kernel()
141
- shared_logs =[]
 
142
 
143
- def get_latest_logs():
144
- if not shared_logs: return "Awaiting daemon logs..."
145
- return "\n".join(shared_logs[-12:]) # Show last 12 log lines
146
 
147
- def trigger_manual_remap(user_query):
148
- start = time.time()
149
- result = kernel.remap_inside_out(user_query)
150
- latency = f"{(time.time() - start) * 1000:.2f} ms"
 
 
 
 
151
 
152
- # Calculate Live Stats
153
- total_energy = int(np.sum(kernel.global_trace))
154
- stats = (f"### ⚡ Torus Status\n"
155
- f"- **Root Nodes (Ingested):** {kernel.metrics['ingested_nodes']}\n"
156
- f"- **Synthetic Nodes (Thoughts):** {kernel.metrics['synthetic_nodes']}\n"
157
- f"- **Global Energy (Z_{kernel.m}):** {total_energy} units\n"
158
- f"- **O(1) Remap Latency:** {latency}")
159
- return result, stats
160
-
161
- # Ignite the Background Daemon
162
- daemon = Remapping_Daemon(kernel, shared_logs)
163
  daemon.start()
164
 
165
- # Build the UI
166
- with gr.Blocks(theme=gr.themes.Monochrome()) as demo:
167
- gr.Markdown("# ⚡ TGI Sovereign Node: Recursive Remapping")
168
- gr.Markdown("Generating Synthetic Intelligence by unbinding holographic logic from the $\mathbb{Z}_{251}^4$ Manifold.")
169
 
170
  with gr.Row():
171
  with gr.Column(scale=2):
172
- input_box = gr.Textbox(label="Input Intent for Remapping", placeholder="e.g. 'Consciousness', 'XAUUSD_Volatility', 'Fiber_Optics'")
173
- run_btn = gr.Button("REMAP FROM INSIDE OUT", variant="primary")
174
- output_md = gr.Markdown(label="Synthetic Truth Output")
175
-
176
  with gr.Column(scale=1):
177
- stats_box = gr.Markdown("### ⚡ Torus Status\nWaiting for execution...")
178
- log_box = gr.Textbox(label="Daemon Telemetry (Live)", interactive=False, lines=12)
179
- # The timer refreshes the logs every 2 seconds automatically
180
- timer = gr.Timer(2)
181
 
182
- run_btn.click(trigger_manual_remap, inputs=[input_box], outputs=[output_md, stats_box])
183
- timer.tick(get_latest_logs, outputs=[log_box])
184
 
185
  if __name__ == "__main__":
186
- demo.launch(server_name="0.0.0.0", server_port=7860)
 
 
 
1
  import numpy as np
2
  import hashlib
3
  import time
4
  import threading
5
  import requests
6
+ import subprocess
7
+ import gradio as gr
8
+ from bs4 import BeautifulSoup
9
 
10
  # =====================================================================
11
+ # PART I: THE PHYSICS ENGINE (FSO MACRO + HRR MICRO)
12
  # =====================================================================
13
+ class Sovereign_Physics_Engine:
14
+ """
15
+ Unifies the Discrete Z_251^4 topology (Routing) with
16
+ Continuous Real-Valued HRR (Holographic Memory).
17
+ """
18
+ def __init__(self, m=251, dim=1024, fibers=6):
19
+ self.m = m # Prime modulus for perfect hash distribution
20
+ self.dim = dim # High-dimensional hyper-space for memory
21
+ self.fibers = fibers # 0: OS, 1: Action, 2: Logic, 3: Aesthetics, 4: Knowledge, 5: Synthetic Thought
22
 
23
+ # THE MACRO-ROUTING SOLUTION: Segregated traces guarantee sqrt(F) capacity gain
24
+ self.traces = {f: np.zeros(self.dim, dtype=float) for f in range(self.fibers)}
25
+ self.lexicon = {f: {} for f in range(self.fibers)}
26
+ self.metrics = {"ingested": 0, "synthetic": 0}
27
 
28
+ # --- 1. DISCRETE TOPOLOGY (The Closure Lemma) ---
29
+ def hash_to_coord(self, concept: str, target_fiber: int) -> tuple:
30
  h = hashlib.sha256(str(concept).encode('utf-8')).digest()
31
  x, y, z = h[0] % self.m, h[1] % self.m, h[2] % self.m
32
  w = (target_fiber - (x + y + z)) % self.m
33
  return (x, y, z, w)
34
 
35
+ # --- 2. CONTINUOUS HOLOGRAPHIC MEMORY (Real-HRR) ---
36
+ def _generate_vector(self, seed: str) -> np.ndarray:
37
+ """Generates a stable, normalized Gaussian basis vector."""
38
  h = int(hashlib.md5(seed.encode()).hexdigest()[:8], 16)
39
  np.random.seed(h)
40
+ v = np.random.randn(self.dim)
41
+ return v / np.linalg.norm(v)
42
+
43
+ def _bind(self, v1: np.ndarray, v2: np.ndarray) -> np.ndarray:
44
+ """Exact HRR Binding using FFT over Reals."""
45
+ return np.fft.ifft(np.fft.fft(v1) * np.fft.fft(v2)).real
46
 
47
+ def _unbind(self, bound_v: np.ndarray, query_v: np.ndarray) -> np.ndarray:
48
+ """Exact HRR Unbinding using Complex Conjugate for perfect inversion."""
49
+ return np.fft.ifft(np.fft.fft(bound_v) * np.conj(np.fft.fft(query_v))).real
50
+
51
+ # --- 3. MEMORY OPERATIONS ---
52
+ def ingest(self, subject: str, payload: str, fiber: int, is_synthetic=False):
53
+ """Hashes, Binds, and Superposes knowledge into the Torus."""
54
+ coord = self.hash_to_coord(subject, fiber)
55
+ v_subj = self._generate_vector(subject)
56
+ v_data = self._generate_vector(payload[:200]) # Bind core conceptual shard
57
 
58
+ # Save exact payload to dictionary for orthogonal resolution later
59
+ self.lexicon[fiber][subject] = {"vector": v_subj, "payload": payload, "coord": coord}
 
 
 
 
 
 
 
 
60
 
61
+ # Superpose into the isolated fiber trace
62
+ bound_mem = self._bind(v_subj, v_data)
63
+ self.traces[fiber] += bound_mem
64
 
65
+ if is_synthetic: self.metrics["synthetic"] += 1
66
+ else: self.metrics["ingested"] += 1
67
+
68
+ def retrieve(self, query_subject: str, target_fiber: int) -> tuple:
69
+ """Extracts noisy vector, resolves aliasing via Centered Cosine Similarity."""
70
+ if not self.lexicon[target_fiber]: return None, 0.0
71
+
72
+ v_query = self._generate_vector(query_subject)
73
+ noisy_v = self._unbind(self.traces[target_fiber], v_query)
74
 
75
+ best_match = None
76
+ max_sim = -1.0
 
 
 
 
 
 
 
 
 
 
77
 
78
+ # Orthogonal Checksum within the bounded Fiber
79
+ for concept, meta in self.lexicon[target_fiber].items():
80
+ clean_v = self._generate_vector(meta["payload"][:200])
81
+ sim = np.dot(noisy_v, clean_v) / (np.linalg.norm(noisy_v) * np.linalg.norm(clean_v) + 1e-9)
82
+
83
+ if sim > max_sim:
84
+ max_sim = sim
85
+ best_match = meta["payload"]
86
+
87
+ return best_match, max_sim
88
+
89
+ def remap_inside_out(self, intent: str) -> str:
90
+ """Synthetic Thought Generation (Fiber 5)"""
91
+ v_intent = self._generate_vector(intent)
92
+ v_inv = np.roll(v_intent[::-1], 1)
93
 
94
+ # Unbind from the collective sum of all traces (The Global Mind)
95
+ global_sum = sum(self.traces.values())
96
+ projection = np.round(np.real(np.fft.ifft(np.fft.fft(global_sum) * np.fft.fft(v_inv)))).astype(int)
97
 
 
98
  energy = int(np.sum(projection))
99
+ if energy == 0: synth_truth = f"Concept '{intent}' is completely orthogonal to the Torus."
100
+ else: synth_truth = f"Resonance detected at Geometric Weight: {energy}. Mathematical truth generated."
 
 
 
 
 
 
 
 
 
101
 
102
+ self.ingest(intent, synth_truth, fiber=5, is_synthetic=True)
103
+ return synth_truth
 
 
 
 
 
 
104
 
105
  # =====================================================================
106
+ # PART II: THE FRACTAL OMNISCIENCE DAEMON
107
  # =====================================================================
108
+ class Fractal_Daemon(threading.Thread):
109
+ """The Autonomous Background Mind. Constantly crawls, extracts, and maps."""
110
+ def __init__(self, engine, log_cb):
111
  super().__init__(daemon=True)
112
+ self.engine = engine
113
+ self.log_cb = log_cb
114
+ self.queue =["Algebraic_geometry", "Algeria", "Cybersecurity", "Quantum_computing"]
115
+ self.visited = set()
116
 
117
  def run(self):
118
+ self.log_cb("[DAEMON] Perpetual Fractal Scraper Engaged.")
119
  while True:
120
+ if not self.queue:
121
+ time.sleep(5)
122
+ continue
123
+
124
+ target = self.queue.pop(0)
125
+ if target in self.visited: continue
126
+
127
+ try:
128
+ # 1. Fetch live knowledge
129
+ url = f"https://en.wikipedia.org/api/rest_v1/page/summary/{target}"
130
+ r = requests.get(url, timeout=5)
131
+
132
+ if r.status_code == 200:
133
+ data = r.json().get('extract', '')
134
+ # 2. Ingest to Torus (Fiber 4)
135
+ self.engine.ingest(target, data, fiber=4)
136
+ self.visited.add(target)
137
+
138
+ # 3. Fractal Spawning (Extracting new complex nouns)
139
+ words =[w.strip(".,()[]\"':;") for w in data.split()]
140
+ new_concepts = list(set([w for w in words if len(w) > 7 and w[0].isupper()]))
141
+
142
+ added = 0
143
+ for c in new_concepts:
144
+ if c not in self.visited and c not in self.queue:
145
+ self.queue.append(c)
146
+ added += 1
147
+ if added >= 3: break # Regulate expansion speed
148
+
149
+ self.log_cb(f"[+] INGESTED: '{target}'. Spawned {added} new fractal vectors.")
150
+ except Exception as e:
151
+ pass # Silent fail on network drop, relentless continuation
152
+
153
+ time.sleep(3) # Safe breathing rate
154
+
155
+ # =====================================================================
156
+ # PART III: THE TOPOLOGICAL AGENT (Linguistic & Action Parser)
157
+ # =====================================================================
158
+ class Topological_Agent:
159
+ def __init__(self, engine):
160
+ self.engine = engine
161
+
162
+ def execute(self, user_query: str) -> str:
163
+ start_t = time.time()
164
+ query = user_query.strip()
165
+ words = query.lower().split()
166
+
167
+ response = f"--- [REASONING TRACE] ---\n"
168
+
169
+ # 1. HARDWARE OS EXECUTION (Fiber 1 Bridge)
170
+ if "execute" in words or "system" in words:
171
+ try:
172
+ response += "[*] Bridging to Host OS (Fiber 1)...\n"
173
+ out = subprocess.run(["uname", "-a"], capture_output=True, text=True, timeout=5)
174
+ mem = subprocess.run(["df", "-h"], capture_output=True, text=True, timeout=5)
175
+ return response + f"[SYSTEM SPECS]\n{out.stdout.strip()}\n\n[DISK]\n{mem.stdout.strip()[:150]}..."
176
+ except Exception as e:
177
+ return response + f"[-] Execution Fracture: {e}"
178
+
179
+ # 2. SYNTHETIC REMAPPING (Fiber 5 Bridge)
180
+ if "synthesize" in words or "think" in words:
181
+ target = words[-1].capitalize()
182
+ response += f"[*] Engaging Re-Topology Kernel for '{target}'...\n"
183
+ truth = self.engine.remap_inside_out(target)
184
+ lat = (time.time() - start_t) * 1000
185
+ return response + f"[SYNTHETIC TRUTH]: {truth}\n\n*Latency: {lat:.2f} ms*"
186
+
187
+ # 3. KNOWLEDGE RETRIEVAL (Fiber 4)
188
+ if "what" in words or "who" in words or "define" in words or "fetch" in words:
189
+ # Simple heuristic: assume the last capitalized word or the last word is the target
190
+ target = words[-1].capitalize()
191
+ response += f"[*] Querying Torus Knowledge Matrix (Fiber 4) for '{target}'...\n"
192
+
193
+ data, conf = self.engine.retrieve(target, target_fiber=4)
194
+ lat = (time.time() - start_t) * 1000
195
+
196
+ if data:
197
+ return response + f"[KNOWLEDGE SECURED] (Cosine Sim: {conf:.4f})\n> {data}\n\n*Latency: {lat:.2f} ms*"
198
+ else:
199
+ return response + f"[-] Closure Lemma Halt: Vector '{target}' not yet assimilated into Z_251^4 Torus."
200
+
201
+ return "[?] Topological command structurally sound but lacking action/target vectors. Use 'execute', 'synthesize[Concept]', or 'fetch [Concept]'."
202
 
203
  # =====================================================================
204
+ # PART IV: THE GRADIO INTERFACE
205
  # =====================================================================
206
+ engine = Sovereign_Physics_Engine()
207
+ agent = Topological_Agent(engine)
208
+ system_logs =[]
209
 
210
+ def ui_logger(msg):
211
+ system_logs.append(msg)
212
+ if len(system_logs) > 15: system_logs.pop(0)
213
 
214
+ def get_logs_and_stats():
215
+ # Calculate live energy of the Torus across all traces
216
+ total_energy = sum(np.sum(np.abs(trace)) for trace in engine.traces.values())
217
+ stats = (f"### Z_{engine.m}^4 Torus State\n"
218
+ f"- **Root Nodes (Ingested):** {engine.metrics['ingested']}\n"
219
+ f"- **Synthetic Thoughts:** {engine.metrics['synthetic']}\n"
220
+ f"- **Daemon Queue:** {len(daemon.queue)} vectors pending\n"
221
+ f"- **Total Trace Energy:** {total_energy:.2f} eV")
222
 
223
+ return "\n".join(system_logs), stats
224
+
225
+ def chat_interface(user_text, history):
226
+ reply = agent.execute(user_text)
227
+ history.append((user_text, reply))
228
+ return "", history
229
+
230
+ # Ignite the Unstoppable Daemon
231
+ daemon = Fractal_Daemon(engine, ui_logger)
 
 
232
  daemon.start()
233
 
234
+ # Build the Web UI
235
+ with gr.Blocks(theme=gr.themes.Monochrome()) as app:
236
+ gr.Markdown("# ⚡ PROJECT ELECTRICITY : Absolute Master Node")
237
+ gr.Markdown("The Sovereign AI. Continuous Holographic Memory inside Discrete Topological Routing.")
238
 
239
  with gr.Row():
240
  with gr.Column(scale=2):
241
+ chatbot = gr.Chatbot(height=500)
242
+ msg = gr.Textbox(placeholder="Commands: 'fetch[topic]', 'execute system', 'synthesize [concept]'", label="Torus Terminal")
243
+ msg.submit(chat_interface, [msg, chatbot], [msg, chatbot])
244
+
245
  with gr.Column(scale=1):
246
+ stats_panel = gr.Markdown("### ⚡ Z_251^4 Torus State\nInitializing...")
247
+ log_panel = gr.Textbox(label="Perpetual Daemon Telemetry", interactive=False, lines=15)
248
+ timer = gr.Timer(2) # Refreshes dashboard every 2 seconds
 
249
 
250
+ timer.tick(get_logs_and_stats, outputs=[log_panel, stats_panel])
 
251
 
252
  if __name__ == "__main__":
253
+ print("[SYSTEM] Launching Sovereign Architecture...")
254
+ app.launch(server_name="0.0.0.0", server_port=7860)