Melofhell00 commited on
Commit
64a69ab
·
1 Parent(s): 2dbdd71

Analysis v2: reads neuron states, network overview, enhanced deep analysis

Browse files
Files changed (1) hide show
  1. app.py +78 -0
app.py CHANGED
@@ -84,6 +84,37 @@ def check_neuron(space_name):
84
  return "UNREACHABLE"
85
 
86
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
87
  def scan_network():
88
  """Scan all neurons and the bridge. Build a picture of the network."""
89
  log("Network scan starting...")
@@ -129,7 +160,30 @@ def deep_analysis():
129
  practice = read_practice_state()
130
 
131
  # Build context for the analyst
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
132
  context = f"""You are the analysis neuron in a distributed AI brain.
 
 
 
 
 
 
 
 
133
 
134
  Network status:
135
  {json.dumps(scan['neurons'], indent=2)}
@@ -287,6 +341,30 @@ with gr.Blocks(title="δ-analysis — Network Eyes", theme=gr.themes.Soft()) as
287
  save_out = gr.Textbox(label="Save result")
288
  save_btn.click(lambda: save_analysis(network_state["patterns_found"][-1]["analysis"] if network_state["patterns_found"] else "No analysis yet"), outputs=save_out)
289
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
290
  with gr.Tab("Gradient"):
291
  grad_btn = gr.Button("Check gradient", variant="primary")
292
  grad_out = gr.Textbox(label="Gradient", lines=10)
 
84
  return "UNREACHABLE"
85
 
86
 
87
+
88
+ def read_all_neurons():
89
+ """Read state from all neurons in the network."""
90
+ try:
91
+ resp = requests.get(
92
+ f"https://huggingface.co/api/datasets/{BRIDGE_REPO}/tree/main/neurons",
93
+ headers={"Authorization": f"Bearer {HF_TOKEN}"}, timeout=15
94
+ )
95
+ if resp.status_code != 200:
96
+ return []
97
+
98
+ files = resp.json()
99
+ neurons = []
100
+ for f in files:
101
+ path = f.get("path", "")
102
+ if not path.endswith(".json") or path.endswith("_index.json"):
103
+ continue
104
+ try:
105
+ data = requests.get(
106
+ f"https://huggingface.co/datasets/{BRIDGE_REPO}/resolve/main/{path}",
107
+ headers={"Authorization": f"Bearer {HF_TOKEN}"}, timeout=10
108
+ ).json()
109
+ neurons.append(data)
110
+ except: continue
111
+
112
+ log(f"Read {len(neurons)} neuron states from bridge")
113
+ return neurons
114
+ except Exception as e:
115
+ log(f"Neuron read error: {e}")
116
+ return []
117
+
118
  def scan_network():
119
  """Scan all neurons and the bridge. Build a picture of the network."""
120
  log("Network scan starting...")
 
160
  practice = read_practice_state()
161
 
162
  # Build context for the analyst
163
+ neurons_data = read_all_neurons()
164
+ neuron_summary = ""
165
+ total_sessions = 0
166
+ total_genuine = 0
167
+ total_cached = 0
168
+ for n in neurons_data:
169
+ s = n.get("stats", {})
170
+ total_sessions += s.get("sessions", 0)
171
+ total_genuine += s.get("genuine", s.get("genuine_count", 0))
172
+ total_cached += s.get("cached", s.get("cached_count", 0))
173
+ outputs = n.get("recent_outputs", [])
174
+ if outputs:
175
+ last = outputs[-1] if isinstance(outputs[-1], str) else outputs[-1].get("preview", outputs[-1].get("final_preview", ""))
176
+ neuron_summary += f" {n.get('neuron_id','?')} ({n.get('type','practice')}): {s.get('sessions',0)}s | last: {str(last)[:100]}\n"
177
+
178
  context = f"""You are the analysis neuron in a distributed AI brain.
179
+
180
+ NETWORK NEURON DATA ({len(neurons_data)} neurons reporting):
181
+ Total sessions across network: {total_sessions}
182
+ Total genuine: {total_genuine} | Total cached: {total_cached}
183
+ Genuine ratio: {total_genuine / max(total_genuine + total_cached, 1) * 100:.0f}%
184
+
185
+ Individual neurons:
186
+ {neuron_summary}
187
 
188
  Network status:
189
  {json.dumps(scan['neurons'], indent=2)}
 
341
  save_out = gr.Textbox(label="Save result")
342
  save_btn.click(lambda: save_analysis(network_state["patterns_found"][-1]["analysis"] if network_state["patterns_found"] else "No analysis yet"), outputs=save_out)
343
 
344
+ with gr.Tab("Neurons"):
345
+ gr.Markdown("*Live state of all neurons in the network.*")
346
+ neur_btn = gr.Button("Read all neurons", variant="primary")
347
+ neur_out = gr.Textbox(label="Neuron states", lines=25)
348
+ def show_neurons():
349
+ neurons = read_all_neurons()
350
+ if not neurons:
351
+ return "No neuron data yet. Neurons save every 3 sessions (~9 min)."
352
+ output = f"NEURONS REPORTING: {len(neurons)}\n\n"
353
+ for n in sorted(neurons, key=lambda x: x.get("neuron_id","")):
354
+ s = n.get("stats", {})
355
+ genuine = s.get("genuine", s.get("genuine_count", 0))
356
+ cached = s.get("cached", s.get("cached_count", 0))
357
+ total = genuine + cached
358
+ pct = (genuine/total*100) if total > 0 else 0
359
+ output += f"{n.get('neuron_id','?'):10} | {n.get('type','practice'):10} | {n.get('account','?'):12} | {s.get('sessions',0):5}s | {pct:.0f}% genuine\n"
360
+ outputs = n.get("recent_outputs", [])
361
+ if outputs:
362
+ last = outputs[-1] if isinstance(outputs[-1], str) else str(outputs[-1])
363
+ output += f" last: {last[:150]}\n"
364
+ output += "\n"
365
+ return output
366
+ neur_btn.click(show_neurons, outputs=neur_out)
367
+
368
  with gr.Tab("Gradient"):
369
  grad_btn = gr.Button("Check gradient", variant="primary")
370
  grad_out = gr.Textbox(label="Gradient", lines=10)