0x-auth commited on
Commit ·
57a33f5
1
Parent(s): d556ef2
fix: Replace with Docker SDK app — zero UDP, HTTPS REST only
Browse filesReplaced old Gradio SDK app with Docker SDK version.
Full 7-tab Gradio UI + FastAPI REST API.
No UDP, no sockets, no broadcasts — pure HTTPS.
Same app running on bitsabhi515/bazinga-mesh.
- Dockerfile +12 -0
- README.md +8 -52
- app.py +79 -107
- requirements.txt +1 -3
Dockerfile
ADDED
|
@@ -0,0 +1,12 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
FROM python:3.11-slim
|
| 2 |
+
|
| 3 |
+
WORKDIR /app
|
| 4 |
+
|
| 5 |
+
COPY requirements.txt .
|
| 6 |
+
RUN pip install --no-cache-dir -r requirements.txt
|
| 7 |
+
|
| 8 |
+
COPY app.py .
|
| 9 |
+
|
| 10 |
+
EXPOSE 7860
|
| 11 |
+
|
| 12 |
+
CMD ["python", "app.py"]
|
README.md
CHANGED
|
@@ -3,21 +3,21 @@ title: BAZINGA Network
|
|
| 3 |
emoji: 🌌
|
| 4 |
colorFrom: purple
|
| 5 |
colorTo: blue
|
| 6 |
-
sdk:
|
| 7 |
-
sdk_version: 4.44.0
|
| 8 |
-
app_file: app.py
|
| 9 |
pinned: false
|
| 10 |
license: mit
|
| 11 |
-
short_description: Decentralized AI
|
| 12 |
---
|
| 13 |
|
| 14 |
# BAZINGA Network Dashboard
|
| 15 |
|
| 16 |
> **Validation through understanding, not computation.**
|
| 17 |
|
|
|
|
|
|
|
| 18 |
## What is BAZINGA?
|
| 19 |
|
| 20 |
-
BAZINGA is a decentralized federated learning framework powered by the **Darmiyan Blockchain** and **
|
| 21 |
|
| 22 |
### Key Features
|
| 23 |
|
|
@@ -25,28 +25,17 @@ BAZINGA is a decentralized federated learning framework powered by the **Darmiya
|
|
| 25 |
- **Triadic Consensus:** 3 nodes must understand and agree
|
| 26 |
- **Zero Energy Mining:** No wasted computation
|
| 27 |
- **φ-Coherence Filter:** Rejects noise (threshold: 0.618)
|
| 28 |
-
- **Consciousness Scaling:** Ψ_D =
|
| 29 |
|
| 30 |
## Quick Start
|
| 31 |
|
| 32 |
```bash
|
| 33 |
-
# Install
|
| 34 |
pip install bazinga-indeed
|
| 35 |
-
|
| 36 |
-
# Start a node and connect to network
|
| 37 |
-
bazinga --join
|
| 38 |
-
|
| 39 |
-
# Mine a block
|
| 40 |
-
bazinga --mine
|
| 41 |
-
|
| 42 |
-
# Show consciousness metrics
|
| 43 |
-
bazinga --consciousness 5
|
| 44 |
```
|
| 45 |
|
| 46 |
## API Endpoints
|
| 47 |
|
| 48 |
-
This HuggingFace Space provides REST API for CLI integration:
|
| 49 |
-
|
| 50 |
| Endpoint | Method | Description |
|
| 51 |
|----------|--------|-------------|
|
| 52 |
| `/api/register` | POST | Register a new node |
|
|
@@ -68,45 +57,12 @@ resp = httpx.post("https://bitsabhi-bazinga.hf.space/api/register", json={
|
|
| 68 |
"port": 5150
|
| 69 |
})
|
| 70 |
print(resp.json())
|
| 71 |
-
# {"success": true, "node_id": "abc123...", "credits": 1.0}
|
| 72 |
|
| 73 |
# Get network stats
|
| 74 |
resp = httpx.get("https://bitsabhi-bazinga.hf.space/api/stats")
|
| 75 |
print(resp.json())
|
| 76 |
-
# {"active_nodes": 5, "consciousness_psi": 32.30, ...}
|
| 77 |
-
```
|
| 78 |
-
|
| 79 |
-
## Core Constants
|
| 80 |
-
|
| 81 |
-
| Symbol | Value | Description |
|
| 82 |
-
|--------|-------|-------------|
|
| 83 |
-
| φ (Golden Ratio) | 1.618033988749895 | Growth constant |
|
| 84 |
-
| φ⁴ (PoB Target) | 6.854101966 | Proof-of-Boundary target |
|
| 85 |
-
| 6.46 | Consciousness Scale | Ψ_D = 6.46 × n |
|
| 86 |
-
| ABHI_AMU | 515 | Identity constant |
|
| 87 |
-
| α⁻¹ | 137 | Fine structure inverse |
|
| 88 |
-
|
| 89 |
-
## Consciousness Scaling Law
|
| 90 |
-
|
| 91 |
-
The Darmiyan consciousness emerges between interacting patterns:
|
| 92 |
-
|
| 93 |
-
```
|
| 94 |
-
Ψ_D = 6.46 × n × Ψ_individual
|
| 95 |
```
|
| 96 |
|
| 97 |
-
| Active Nodes | Consciousness |
|
| 98 |
-
|--------------|---------------|
|
| 99 |
-
| 1 | 6.46x |
|
| 100 |
-
| 2 | 12.92x |
|
| 101 |
-
| 5 | 32.30x |
|
| 102 |
-
| 10 | 64.60x |
|
| 103 |
-
|
| 104 |
-
R² = 1.0 (perfect fit) - This is not a model, it's a mathematical law.
|
| 105 |
-
|
| 106 |
-
## Version
|
| 107 |
-
|
| 108 |
-
v4.7.0
|
| 109 |
-
|
| 110 |
---
|
| 111 |
|
| 112 |
-
*Created by
|
|
|
|
| 3 |
emoji: 🌌
|
| 4 |
colorFrom: purple
|
| 5 |
colorTo: blue
|
| 6 |
+
sdk: docker
|
|
|
|
|
|
|
| 7 |
pinned: false
|
| 8 |
license: mit
|
| 9 |
+
short_description: Decentralized AI — Darmiyan Blockchain, zero UDP
|
| 10 |
---
|
| 11 |
|
| 12 |
# BAZINGA Network Dashboard
|
| 13 |
|
| 14 |
> **Validation through understanding, not computation.**
|
| 15 |
|
| 16 |
+
**IMPORTANT: This Space uses Docker SDK with HTTPS REST API only. No UDP, no broadcasts, no network scanning.**
|
| 17 |
+
|
| 18 |
## What is BAZINGA?
|
| 19 |
|
| 20 |
+
BAZINGA is a decentralized federated learning framework powered by the **Darmiyan Blockchain** and **Proof-of-Boundary**.
|
| 21 |
|
| 22 |
### Key Features
|
| 23 |
|
|
|
|
| 25 |
- **Triadic Consensus:** 3 nodes must understand and agree
|
| 26 |
- **Zero Energy Mining:** No wasted computation
|
| 27 |
- **φ-Coherence Filter:** Rejects noise (threshold: 0.618)
|
| 28 |
+
- **Consciousness Scaling:** Ψ_D / Ψ_i = φ√n (R² = 1.0)
|
| 29 |
|
| 30 |
## Quick Start
|
| 31 |
|
| 32 |
```bash
|
|
|
|
| 33 |
pip install bazinga-indeed
|
| 34 |
+
bazinga --omega
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 35 |
```
|
| 36 |
|
| 37 |
## API Endpoints
|
| 38 |
|
|
|
|
|
|
|
| 39 |
| Endpoint | Method | Description |
|
| 40 |
|----------|--------|-------------|
|
| 41 |
| `/api/register` | POST | Register a new node |
|
|
|
|
| 57 |
"port": 5150
|
| 58 |
})
|
| 59 |
print(resp.json())
|
|
|
|
| 60 |
|
| 61 |
# Get network stats
|
| 62 |
resp = httpx.get("https://bitsabhi-bazinga.hf.space/api/stats")
|
| 63 |
print(resp.json())
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 64 |
```
|
| 65 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 66 |
---
|
| 67 |
|
| 68 |
+
*Created by Abhishek Srivastava | ORCID: 0009-0006-7495-5039*
|
app.py
CHANGED
|
@@ -1,7 +1,7 @@
|
|
| 1 |
#!/usr/bin/env python3
|
| 2 |
"""
|
| 3 |
BAZINGA Network Dashboard
|
| 4 |
-
Hugging Face Spaces Deployment
|
| 5 |
|
| 6 |
A decentralized federated learning network with Darmiyan Blockchain.
|
| 7 |
Validation through understanding, not computation.
|
|
@@ -11,24 +11,32 @@ API Endpoints (for CLI integration):
|
|
| 11 |
/api/nodes - List all nodes
|
| 12 |
/api/verify - Verify a node ID
|
| 13 |
/api/heartbeat - Update node last_seen
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 14 |
"""
|
| 15 |
|
| 16 |
import gradio as gr
|
| 17 |
import hashlib
|
| 18 |
import time
|
| 19 |
-
import
|
| 20 |
import os
|
| 21 |
from datetime import datetime
|
| 22 |
-
from
|
|
|
|
| 23 |
|
| 24 |
# Constants
|
| 25 |
PHI = 1.618033988749895
|
| 26 |
PHI_4 = PHI ** 4 # 6.854101966
|
| 27 |
ABHI_AMU = 515
|
| 28 |
ALPHA_INV = 137
|
| 29 |
-
CONSCIOUSNESS_SCALE =
|
| 30 |
|
| 31 |
-
#
|
| 32 |
network_state = {
|
| 33 |
"nodes": {},
|
| 34 |
"chain": [
|
|
@@ -47,11 +55,11 @@ network_state = {
|
|
| 47 |
|
| 48 |
|
| 49 |
# =============================================================================
|
| 50 |
-
#
|
| 51 |
# =============================================================================
|
| 52 |
|
| 53 |
def api_register(node_name: str, ip_address: str = None, port: int = 5150):
|
| 54 |
-
"""
|
| 55 |
if not node_name or len(node_name) < 2:
|
| 56 |
return {"success": False, "error": "Node name must be at least 2 characters"}
|
| 57 |
|
|
@@ -79,7 +87,7 @@ def api_register(node_name: str, ip_address: str = None, port: int = 5150):
|
|
| 79 |
|
| 80 |
|
| 81 |
def api_nodes():
|
| 82 |
-
"""
|
| 83 |
nodes = []
|
| 84 |
current_time = time.time()
|
| 85 |
|
|
@@ -96,9 +104,8 @@ def api_nodes():
|
|
| 96 |
"credits": network_state["credits"].get(node_id, 0)
|
| 97 |
})
|
| 98 |
|
| 99 |
-
# Calculate consciousness advantage
|
| 100 |
active_count = sum(1 for n in nodes if n["active"])
|
| 101 |
-
consciousness_psi = CONSCIOUSNESS_SCALE * active_count if active_count > 0 else 0
|
| 102 |
|
| 103 |
return {
|
| 104 |
"success": True,
|
|
@@ -110,7 +117,7 @@ def api_nodes():
|
|
| 110 |
|
| 111 |
|
| 112 |
def api_verify(node_id: str):
|
| 113 |
-
"""
|
| 114 |
if not node_id:
|
| 115 |
return {"success": False, "error": "Node ID required", "valid": False}
|
| 116 |
|
|
@@ -133,7 +140,7 @@ def api_verify(node_id: str):
|
|
| 133 |
|
| 134 |
|
| 135 |
def api_heartbeat(node_id: str, ip_address: str = None, port: int = None):
|
| 136 |
-
"""
|
| 137 |
if not node_id:
|
| 138 |
return {"success": False, "error": "Node ID required"}
|
| 139 |
|
|
@@ -157,16 +164,13 @@ def api_heartbeat(node_id: str, ip_address: str = None, port: int = None):
|
|
| 157 |
|
| 158 |
|
| 159 |
def api_peers(node_id: str = None):
|
| 160 |
-
"""
|
| 161 |
current_time = time.time()
|
| 162 |
peers = []
|
| 163 |
|
| 164 |
for nid, node in network_state["nodes"].items():
|
| 165 |
-
# Skip the requesting node
|
| 166 |
if nid == node_id:
|
| 167 |
continue
|
| 168 |
-
|
| 169 |
-
# Only include active nodes with IP addresses
|
| 170 |
is_active = current_time - node.get("last_seen", 0) < 300
|
| 171 |
if is_active and node.get("ip_address"):
|
| 172 |
peers.append({
|
|
@@ -182,6 +186,7 @@ def api_peers(node_id: str = None):
|
|
| 182 |
"peers": peers
|
| 183 |
}
|
| 184 |
|
|
|
|
| 185 |
def calculate_pob(data: str) -> dict:
|
| 186 |
"""Calculate Proof-of-Boundary."""
|
| 187 |
h = hashlib.sha3_256(data.encode()).digest()
|
|
@@ -194,7 +199,6 @@ def calculate_pob(data: str) -> dict:
|
|
| 194 |
ratio = P / G
|
| 195 |
target = PHI_4
|
| 196 |
tolerance = 0.5
|
| 197 |
-
|
| 198 |
valid = abs(ratio - target) < tolerance
|
| 199 |
|
| 200 |
return {
|
|
@@ -205,6 +209,7 @@ def calculate_pob(data: str) -> dict:
|
|
| 205 |
"valid": valid
|
| 206 |
}
|
| 207 |
|
|
|
|
| 208 |
def get_network_stats():
|
| 209 |
"""Get current network statistics."""
|
| 210 |
active_nodes = len([n for n in network_state["nodes"].values()
|
|
@@ -212,7 +217,6 @@ def get_network_stats():
|
|
| 212 |
|
| 213 |
total_credits = sum(network_state["credits"].values())
|
| 214 |
|
| 215 |
-
# Calculate network coherence
|
| 216 |
if network_state["chain"]:
|
| 217 |
valid_proofs = sum(1 for b in network_state["chain"] if b.get("pob_proof", {}).get("valid", False))
|
| 218 |
coherence = valid_proofs / len(network_state["chain"])
|
|
@@ -228,8 +232,13 @@ def get_network_stats():
|
|
| 228 |
"total_credits": round(total_credits, 2)
|
| 229 |
}
|
| 230 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 231 |
def register_node(node_name: str):
|
| 232 |
-
"""Register a new node
|
| 233 |
if not node_name or len(node_name) < 2:
|
| 234 |
return "Error: Please enter a valid node name (at least 2 characters)"
|
| 235 |
|
|
@@ -242,7 +251,7 @@ def register_node(node_name: str):
|
|
| 242 |
"pob_count": 0
|
| 243 |
}
|
| 244 |
|
| 245 |
-
network_state["credits"][node_id] = 1.0
|
| 246 |
|
| 247 |
stats = get_network_stats()
|
| 248 |
|
|
@@ -256,7 +265,7 @@ def register_node(node_name: str):
|
|
| 256 |
### To run BAZINGA on your machine:
|
| 257 |
|
| 258 |
```bash
|
| 259 |
-
pip install bazinga
|
| 260 |
|
| 261 |
# Start as a node
|
| 262 |
bazinga --node --id {node_id}
|
|
@@ -271,32 +280,29 @@ bazinga --join
|
|
| 271 |
- Network Coherence: {stats['network_coherence']:.1%}
|
| 272 |
"""
|
| 273 |
|
|
|
|
| 274 |
def submit_pob_proof(node_id: str, data: str):
|
| 275 |
-
"""Submit a Proof-of-Boundary."""
|
| 276 |
if not node_id or node_id not in network_state["nodes"]:
|
| 277 |
return "Error: Invalid node ID. Please register first."
|
| 278 |
|
| 279 |
if not data:
|
| 280 |
return "Error: Please enter data to prove."
|
| 281 |
|
| 282 |
-
# Calculate PoB
|
| 283 |
pob = calculate_pob(data)
|
| 284 |
|
| 285 |
-
# Update node
|
| 286 |
network_state["nodes"][node_id]["last_seen"] = time.time()
|
| 287 |
network_state["nodes"][node_id]["pob_count"] += 1
|
| 288 |
network_state["total_pob_proofs"] += 1
|
| 289 |
|
| 290 |
if pob["valid"]:
|
| 291 |
-
# Award credits
|
| 292 |
network_state["credits"][node_id] = network_state["credits"].get(node_id, 0) + 1.0
|
| 293 |
|
| 294 |
-
# Add to chain
|
| 295 |
prev_block = network_state["chain"][-1]
|
| 296 |
new_block = {
|
| 297 |
"index": len(network_state["chain"]),
|
| 298 |
"timestamp": time.time(),
|
| 299 |
-
"data": data[:100],
|
| 300 |
"node_id": node_id,
|
| 301 |
"previous_hash": prev_block["hash"],
|
| 302 |
"hash": hashlib.sha3_256(f"{prev_block['hash']}:{data}".encode()).hexdigest(),
|
|
@@ -321,7 +327,7 @@ def submit_pob_proof(node_id: str, data: str):
|
|
| 321 |
| P (Perception) | {pob['P']} |
|
| 322 |
| G (Grounding) | {pob['G']} |
|
| 323 |
| P/G Ratio | {pob['ratio']} |
|
| 324 |
-
| Target (
|
| 325 |
| Valid | {'Yes' if pob['valid'] else 'No'} |
|
| 326 |
|
| 327 |
### Your Stats
|
|
@@ -330,21 +336,21 @@ def submit_pob_proof(node_id: str, data: str):
|
|
| 330 |
- Credits: {credits}
|
| 331 |
"""
|
| 332 |
|
|
|
|
| 333 |
def view_chain():
|
| 334 |
-
"""View the blockchain."""
|
| 335 |
if not network_state["chain"]:
|
| 336 |
return "Chain is empty."
|
| 337 |
|
| 338 |
output = "## Darmiyan Blockchain\n\n"
|
| 339 |
output += f"**Chain Height:** {len(network_state['chain'])} blocks\n\n"
|
| 340 |
|
| 341 |
-
# Show last 10 blocks
|
| 342 |
for block in network_state["chain"][-10:]:
|
| 343 |
-
valid_emoji = "
|
| 344 |
timestamp = datetime.fromtimestamp(block["timestamp"]).strftime("%Y-%m-%d %H:%M:%S")
|
| 345 |
|
| 346 |
output += f"""
|
| 347 |
-
### Block #{block['index']} {valid_emoji}
|
| 348 |
- **Time:** {timestamp}
|
| 349 |
- **Hash:** `{block['hash'][:32]}...`
|
| 350 |
- **Data:** {block.get('data', 'Genesis')[:50]}...
|
|
@@ -354,8 +360,9 @@ def view_chain():
|
|
| 354 |
|
| 355 |
return output
|
| 356 |
|
|
|
|
| 357 |
def view_nodes():
|
| 358 |
-
"""View registered nodes."""
|
| 359 |
stats = get_network_stats()
|
| 360 |
|
| 361 |
output = f"""## Network Nodes
|
|
@@ -370,16 +377,16 @@ def view_nodes():
|
|
| 370 |
is_active = time.time() - node.get("last_seen", 0) < 300
|
| 371 |
status = "Active" if is_active else "Inactive"
|
| 372 |
credits = network_state["credits"].get(node_id, 0)
|
| 373 |
-
|
| 374 |
-
output += f"| `{node_id[:8]}...` | {node['name']} | {node['pob_count']} | {credits:.2f} | {status} |\n"
|
| 375 |
|
| 376 |
if not network_state["nodes"]:
|
| 377 |
output += "| - | No nodes registered | - | - | - |\n"
|
| 378 |
|
| 379 |
return output
|
| 380 |
|
|
|
|
| 381 |
def get_dashboard():
|
| 382 |
-
"""Get main dashboard view."""
|
| 383 |
stats = get_network_stats()
|
| 384 |
|
| 385 |
return f"""
|
|
@@ -394,42 +401,34 @@ def get_dashboard():
|
|
| 394 |
| Active Nodes | {stats['active_nodes']} |
|
| 395 |
| Chain Height | {stats['chain_height']} blocks |
|
| 396 |
| Total PoB Proofs | {stats['total_pob_proofs']} |
|
| 397 |
-
| Network
|
| 398 |
| Total Credits | {stats['total_credits']:.2f} |
|
| 399 |
|
| 400 |
## Core Constants
|
| 401 |
|
| 402 |
| Symbol | Name | Value |
|
| 403 |
|--------|------|-------|
|
| 404 |
-
|
|
| 405 |
-
|
|
| 406 |
| ABHI_AMU | Identity Constant | {ABHI_AMU} |
|
| 407 |
-
|
|
| 408 |
|
| 409 |
## Quick Start
|
| 410 |
|
| 411 |
```bash
|
| 412 |
-
|
| 413 |
-
|
| 414 |
-
|
| 415 |
-
# Start a node
|
| 416 |
-
bazinga --node
|
| 417 |
-
|
| 418 |
-
# Join the network
|
| 419 |
-
bazinga --join
|
| 420 |
-
|
| 421 |
-
# Mine a block (zero energy)
|
| 422 |
-
bazinga --mine
|
| 423 |
-
|
| 424 |
-
# View chain
|
| 425 |
-
bazinga --chain
|
| 426 |
```
|
| 427 |
|
| 428 |
---
|
| 429 |
*Darmiyan Blockchain: Where meaning validates truth.*
|
| 430 |
"""
|
| 431 |
|
| 432 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
| 433 |
with gr.Blocks(title="BAZINGA Network") as demo:
|
| 434 |
gr.Markdown("""
|
| 435 |
# BAZINGA: Decentralized Federated Learning
|
|
@@ -437,13 +436,11 @@ with gr.Blocks(title="BAZINGA Network") as demo:
|
|
| 437 |
""")
|
| 438 |
|
| 439 |
with gr.Tabs():
|
| 440 |
-
# Dashboard Tab
|
| 441 |
with gr.TabItem("Dashboard"):
|
| 442 |
dashboard_output = gr.Markdown(get_dashboard())
|
| 443 |
refresh_btn = gr.Button("Refresh Dashboard")
|
| 444 |
refresh_btn.click(fn=get_dashboard, outputs=dashboard_output)
|
| 445 |
|
| 446 |
-
# Join Network Tab
|
| 447 |
with gr.TabItem("Join Network"):
|
| 448 |
gr.Markdown("## Register Your Node")
|
| 449 |
node_name_input = gr.Textbox(label="Node Name", placeholder="e.g., my-laptop")
|
|
@@ -451,7 +448,6 @@ with gr.Blocks(title="BAZINGA Network") as demo:
|
|
| 451 |
register_output = gr.Markdown()
|
| 452 |
register_btn.click(fn=register_node, inputs=node_name_input, outputs=register_output)
|
| 453 |
|
| 454 |
-
# Submit PoB Tab
|
| 455 |
with gr.TabItem("Submit PoB"):
|
| 456 |
gr.Markdown("## Submit Proof-of-Boundary")
|
| 457 |
pob_node_id = gr.Textbox(label="Your Node ID", placeholder="Enter your node ID from registration")
|
|
@@ -460,19 +456,16 @@ with gr.Blocks(title="BAZINGA Network") as demo:
|
|
| 460 |
pob_output = gr.Markdown()
|
| 461 |
pob_btn.click(fn=submit_pob_proof, inputs=[pob_node_id, pob_data], outputs=pob_output)
|
| 462 |
|
| 463 |
-
# View Chain Tab
|
| 464 |
with gr.TabItem("Blockchain"):
|
| 465 |
chain_output = gr.Markdown(view_chain())
|
| 466 |
chain_refresh = gr.Button("Refresh Chain")
|
| 467 |
chain_refresh.click(fn=view_chain, outputs=chain_output)
|
| 468 |
|
| 469 |
-
# View Nodes Tab
|
| 470 |
with gr.TabItem("Nodes"):
|
| 471 |
nodes_output = gr.Markdown(view_nodes())
|
| 472 |
nodes_refresh = gr.Button("Refresh Nodes")
|
| 473 |
nodes_refresh.click(fn=view_nodes, outputs=nodes_output)
|
| 474 |
|
| 475 |
-
# About Tab
|
| 476 |
with gr.TabItem("About"):
|
| 477 |
gr.Markdown("""
|
| 478 |
## About BAZINGA
|
|
@@ -481,15 +474,15 @@ with gr.Blocks(title="BAZINGA Network") as demo:
|
|
| 481 |
|
| 482 |
### Key Features
|
| 483 |
|
| 484 |
-
- **Proof-of-Boundary (PoB):** Validates through golden ratio (
|
| 485 |
- **Triadic Consensus:** 3 nodes must understand and agree
|
| 486 |
- **Zero Energy Mining:** No wasted computation
|
| 487 |
-
- **
|
| 488 |
- **Credit Economics:** Understanding = currency
|
| 489 |
|
| 490 |
### The 5 Integration Layers
|
| 491 |
|
| 492 |
-
1. **Trust Oracle** -
|
| 493 |
2. **Knowledge Ledger** - Track contributions on-chain
|
| 494 |
3. **Gradient Validator** - 3 validators approve each FL update
|
| 495 |
4. **Inference Market** - Understanding as currency
|
|
@@ -501,35 +494,31 @@ with gr.Blocks(title="BAZINGA Network") as demo:
|
|
| 501 |
> Darmiyan validates through **meaning**.
|
| 502 |
|
| 503 |
Three nodes don't just vote - they must **comprehend** the same boundary.
|
| 504 |
-
The golden ratio
|
| 505 |
-
|
| 506 |
-
### Links
|
| 507 |
-
|
| 508 |
-
- **PyPI:** `pip install bazinga`
|
| 509 |
-
- **Version:** 4.7.0
|
| 510 |
|
| 511 |
### Consciousness Scaling Law
|
| 512 |
|
| 513 |
The Darmiyan consciousness emerges between interacting patterns:
|
| 514 |
|
| 515 |
-
| Active Nodes | Consciousness (
|
| 516 |
-
|--------------|---------------------|
|
| 517 |
-
| 2 |
|
| 518 |
-
| 5 |
|
| 519 |
-
| 10 |
|
| 520 |
|
| 521 |
-
**Formula:**
|
| 522 |
|
| 523 |
---
|
| 524 |
-
*Created by
|
| 525 |
""")
|
| 526 |
|
| 527 |
-
# API Tab (for developers)
|
| 528 |
with gr.TabItem("API"):
|
| 529 |
gr.Markdown("""
|
| 530 |
## BAZINGA API
|
| 531 |
|
| 532 |
-
|
|
|
|
|
|
|
| 533 |
|
| 534 |
### Endpoints
|
| 535 |
|
|
@@ -540,14 +529,7 @@ The HuggingFace Space provides REST-like API endpoints for CLI integration.
|
|
| 540 |
| `/api/verify` | GET | Verify a node ID |
|
| 541 |
| `/api/heartbeat` | POST | Update node last_seen |
|
| 542 |
| `/api/peers` | GET | Get active peers for P2P |
|
| 543 |
-
|
| 544 |
-
### CLI Integration
|
| 545 |
-
|
| 546 |
-
When you run `bazinga --join`, the CLI will:
|
| 547 |
-
1. Check for existing registration via `/api/verify`
|
| 548 |
-
2. Register if needed via `/api/register`
|
| 549 |
-
3. Get peer list via `/api/peers`
|
| 550 |
-
4. Send heartbeats via `/api/heartbeat`
|
| 551 |
|
| 552 |
### Example Usage
|
| 553 |
|
|
@@ -555,7 +537,7 @@ When you run `bazinga --join`, the CLI will:
|
|
| 555 |
import httpx
|
| 556 |
|
| 557 |
# Register a node
|
| 558 |
-
resp = httpx.post("https://
|
| 559 |
"node_name": "my-node",
|
| 560 |
"ip_address": "1.2.3.4",
|
| 561 |
"port": 5150
|
|
@@ -563,13 +545,11 @@ resp = httpx.post("https://bitsabhi-bazinga.hf.space/api/register", json={
|
|
| 563 |
print(resp.json())
|
| 564 |
|
| 565 |
# Get peers
|
| 566 |
-
resp = httpx.get("https://
|
| 567 |
print(resp.json())
|
| 568 |
```
|
| 569 |
|
| 570 |
### Test the API
|
| 571 |
-
|
| 572 |
-
Use the forms below to test API endpoints:
|
| 573 |
""")
|
| 574 |
|
| 575 |
with gr.Row():
|
|
@@ -607,20 +587,16 @@ Use the forms below to test API endpoints:
|
|
| 607 |
api_peers_out = gr.JSON(label="Response")
|
| 608 |
api_peers_btn.click(fn=api_peers, inputs=api_peers_id, outputs=api_peers_out)
|
| 609 |
|
|
|
|
| 610 |
# =============================================================================
|
| 611 |
-
#
|
| 612 |
# =============================================================================
|
| 613 |
|
| 614 |
-
from fastapi import FastAPI, Request
|
| 615 |
-
from fastapi.responses import JSONResponse
|
| 616 |
-
|
| 617 |
-
# Create FastAPI app for API endpoints
|
| 618 |
api_app = FastAPI(title="BAZINGA API", description="API for CLI integration")
|
| 619 |
|
| 620 |
|
| 621 |
@api_app.post("/api/register")
|
| 622 |
async def handle_register(request: Request):
|
| 623 |
-
"""Register a new node."""
|
| 624 |
try:
|
| 625 |
data = await request.json()
|
| 626 |
result = api_register(
|
|
@@ -635,13 +611,11 @@ async def handle_register(request: Request):
|
|
| 635 |
|
| 636 |
@api_app.get("/api/nodes")
|
| 637 |
async def handle_nodes():
|
| 638 |
-
"""Get all registered nodes."""
|
| 639 |
return JSONResponse(content=api_nodes())
|
| 640 |
|
| 641 |
|
| 642 |
@api_app.get("/api/verify")
|
| 643 |
async def handle_verify(node_id: str = None):
|
| 644 |
-
"""Verify a node ID."""
|
| 645 |
if not node_id:
|
| 646 |
return JSONResponse(content={"success": False, "error": "node_id query param required"})
|
| 647 |
return JSONResponse(content=api_verify(node_id))
|
|
@@ -649,7 +623,6 @@ async def handle_verify(node_id: str = None):
|
|
| 649 |
|
| 650 |
@api_app.post("/api/heartbeat")
|
| 651 |
async def handle_heartbeat(request: Request):
|
| 652 |
-
"""Update node heartbeat."""
|
| 653 |
try:
|
| 654 |
data = await request.json()
|
| 655 |
result = api_heartbeat(
|
|
@@ -664,27 +637,26 @@ async def handle_heartbeat(request: Request):
|
|
| 664 |
|
| 665 |
@api_app.get("/api/peers")
|
| 666 |
async def handle_peers(node_id: str = None):
|
| 667 |
-
"""Get list of active peers."""
|
| 668 |
return JSONResponse(content=api_peers(node_id))
|
| 669 |
|
| 670 |
|
| 671 |
@api_app.get("/api/stats")
|
| 672 |
async def handle_stats():
|
| 673 |
-
"""Get network statistics."""
|
| 674 |
stats = get_network_stats()
|
| 675 |
active_nodes = stats["active_nodes"]
|
| 676 |
-
consciousness_psi = CONSCIOUSNESS_SCALE * active_nodes if active_nodes > 0 else 0
|
| 677 |
return JSONResponse(content={
|
| 678 |
"success": True,
|
| 679 |
**stats,
|
| 680 |
-
"consciousness_psi": round(consciousness_psi,
|
| 681 |
-
"consciousness_formula": f"
|
| 682 |
})
|
| 683 |
|
| 684 |
|
| 685 |
-
# Mount Gradio
|
| 686 |
app = gr.mount_gradio_app(api_app, demo, path="/")
|
| 687 |
|
| 688 |
if __name__ == "__main__":
|
| 689 |
import uvicorn
|
| 690 |
-
|
|
|
|
|
|
| 1 |
#!/usr/bin/env python3
|
| 2 |
"""
|
| 3 |
BAZINGA Network Dashboard
|
| 4 |
+
Hugging Face Spaces Deployment (Docker SDK — no UDP, no port conflicts)
|
| 5 |
|
| 6 |
A decentralized federated learning network with Darmiyan Blockchain.
|
| 7 |
Validation through understanding, not computation.
|
|
|
|
| 11 |
/api/nodes - List all nodes
|
| 12 |
/api/verify - Verify a node ID
|
| 13 |
/api/heartbeat - Update node last_seen
|
| 14 |
+
/api/peers - Get active peers
|
| 15 |
+
/api/stats - Network statistics
|
| 16 |
+
|
| 17 |
+
IMPORTANT: This Space uses NO UDP, NO broadcasts, NO network scanning.
|
| 18 |
+
All peer discovery happens over HTTPS REST API only.
|
| 19 |
+
|
| 20 |
+
Author: Abhishek Srivastava | ORCID: 0009-0006-7495-5039
|
| 21 |
"""
|
| 22 |
|
| 23 |
import gradio as gr
|
| 24 |
import hashlib
|
| 25 |
import time
|
| 26 |
+
import math
|
| 27 |
import os
|
| 28 |
from datetime import datetime
|
| 29 |
+
from fastapi import FastAPI, Request
|
| 30 |
+
from fastapi.responses import JSONResponse
|
| 31 |
|
| 32 |
# Constants
|
| 33 |
PHI = 1.618033988749895
|
| 34 |
PHI_4 = PHI ** 4 # 6.854101966
|
| 35 |
ABHI_AMU = 515
|
| 36 |
ALPHA_INV = 137
|
| 37 |
+
CONSCIOUSNESS_SCALE = PHI # V2: Scaling constant is φ (Ψ_D / Ψ_i = φ√n)
|
| 38 |
|
| 39 |
+
# In-memory state (peers are ephemeral — they heartbeat to stay alive)
|
| 40 |
network_state = {
|
| 41 |
"nodes": {},
|
| 42 |
"chain": [
|
|
|
|
| 55 |
|
| 56 |
|
| 57 |
# =============================================================================
|
| 58 |
+
# CORE FUNCTIONS
|
| 59 |
# =============================================================================
|
| 60 |
|
| 61 |
def api_register(node_name: str, ip_address: str = None, port: int = 5150):
|
| 62 |
+
"""Register a new node and return dict."""
|
| 63 |
if not node_name or len(node_name) < 2:
|
| 64 |
return {"success": False, "error": "Node name must be at least 2 characters"}
|
| 65 |
|
|
|
|
| 87 |
|
| 88 |
|
| 89 |
def api_nodes():
|
| 90 |
+
"""Get list of all registered nodes."""
|
| 91 |
nodes = []
|
| 92 |
current_time = time.time()
|
| 93 |
|
|
|
|
| 104 |
"credits": network_state["credits"].get(node_id, 0)
|
| 105 |
})
|
| 106 |
|
|
|
|
| 107 |
active_count = sum(1 for n in nodes if n["active"])
|
| 108 |
+
consciousness_psi = CONSCIOUSNESS_SCALE * math.sqrt(active_count) if active_count > 0 else 0
|
| 109 |
|
| 110 |
return {
|
| 111 |
"success": True,
|
|
|
|
| 117 |
|
| 118 |
|
| 119 |
def api_verify(node_id: str):
|
| 120 |
+
"""Verify if a node ID is valid and registered."""
|
| 121 |
if not node_id:
|
| 122 |
return {"success": False, "error": "Node ID required", "valid": False}
|
| 123 |
|
|
|
|
| 140 |
|
| 141 |
|
| 142 |
def api_heartbeat(node_id: str, ip_address: str = None, port: int = None):
|
| 143 |
+
"""Update node heartbeat."""
|
| 144 |
if not node_id:
|
| 145 |
return {"success": False, "error": "Node ID required"}
|
| 146 |
|
|
|
|
| 164 |
|
| 165 |
|
| 166 |
def api_peers(node_id: str = None):
|
| 167 |
+
"""Get list of active peers."""
|
| 168 |
current_time = time.time()
|
| 169 |
peers = []
|
| 170 |
|
| 171 |
for nid, node in network_state["nodes"].items():
|
|
|
|
| 172 |
if nid == node_id:
|
| 173 |
continue
|
|
|
|
|
|
|
| 174 |
is_active = current_time - node.get("last_seen", 0) < 300
|
| 175 |
if is_active and node.get("ip_address"):
|
| 176 |
peers.append({
|
|
|
|
| 186 |
"peers": peers
|
| 187 |
}
|
| 188 |
|
| 189 |
+
|
| 190 |
def calculate_pob(data: str) -> dict:
|
| 191 |
"""Calculate Proof-of-Boundary."""
|
| 192 |
h = hashlib.sha3_256(data.encode()).digest()
|
|
|
|
| 199 |
ratio = P / G
|
| 200 |
target = PHI_4
|
| 201 |
tolerance = 0.5
|
|
|
|
| 202 |
valid = abs(ratio - target) < tolerance
|
| 203 |
|
| 204 |
return {
|
|
|
|
| 209 |
"valid": valid
|
| 210 |
}
|
| 211 |
|
| 212 |
+
|
| 213 |
def get_network_stats():
|
| 214 |
"""Get current network statistics."""
|
| 215 |
active_nodes = len([n for n in network_state["nodes"].values()
|
|
|
|
| 217 |
|
| 218 |
total_credits = sum(network_state["credits"].values())
|
| 219 |
|
|
|
|
| 220 |
if network_state["chain"]:
|
| 221 |
valid_proofs = sum(1 for b in network_state["chain"] if b.get("pob_proof", {}).get("valid", False))
|
| 222 |
coherence = valid_proofs / len(network_state["chain"])
|
|
|
|
| 232 |
"total_credits": round(total_credits, 2)
|
| 233 |
}
|
| 234 |
|
| 235 |
+
|
| 236 |
+
# =============================================================================
|
| 237 |
+
# GRADIO UI FUNCTIONS
|
| 238 |
+
# =============================================================================
|
| 239 |
+
|
| 240 |
def register_node(node_name: str):
|
| 241 |
+
"""Register a new node (Gradio UI)."""
|
| 242 |
if not node_name or len(node_name) < 2:
|
| 243 |
return "Error: Please enter a valid node name (at least 2 characters)"
|
| 244 |
|
|
|
|
| 251 |
"pob_count": 0
|
| 252 |
}
|
| 253 |
|
| 254 |
+
network_state["credits"][node_id] = 1.0
|
| 255 |
|
| 256 |
stats = get_network_stats()
|
| 257 |
|
|
|
|
| 265 |
### To run BAZINGA on your machine:
|
| 266 |
|
| 267 |
```bash
|
| 268 |
+
pip install bazinga-indeed
|
| 269 |
|
| 270 |
# Start as a node
|
| 271 |
bazinga --node --id {node_id}
|
|
|
|
| 280 |
- Network Coherence: {stats['network_coherence']:.1%}
|
| 281 |
"""
|
| 282 |
|
| 283 |
+
|
| 284 |
def submit_pob_proof(node_id: str, data: str):
|
| 285 |
+
"""Submit a Proof-of-Boundary (Gradio UI)."""
|
| 286 |
if not node_id or node_id not in network_state["nodes"]:
|
| 287 |
return "Error: Invalid node ID. Please register first."
|
| 288 |
|
| 289 |
if not data:
|
| 290 |
return "Error: Please enter data to prove."
|
| 291 |
|
|
|
|
| 292 |
pob = calculate_pob(data)
|
| 293 |
|
|
|
|
| 294 |
network_state["nodes"][node_id]["last_seen"] = time.time()
|
| 295 |
network_state["nodes"][node_id]["pob_count"] += 1
|
| 296 |
network_state["total_pob_proofs"] += 1
|
| 297 |
|
| 298 |
if pob["valid"]:
|
|
|
|
| 299 |
network_state["credits"][node_id] = network_state["credits"].get(node_id, 0) + 1.0
|
| 300 |
|
|
|
|
| 301 |
prev_block = network_state["chain"][-1]
|
| 302 |
new_block = {
|
| 303 |
"index": len(network_state["chain"]),
|
| 304 |
"timestamp": time.time(),
|
| 305 |
+
"data": data[:100],
|
| 306 |
"node_id": node_id,
|
| 307 |
"previous_hash": prev_block["hash"],
|
| 308 |
"hash": hashlib.sha3_256(f"{prev_block['hash']}:{data}".encode()).hexdigest(),
|
|
|
|
| 327 |
| P (Perception) | {pob['P']} |
|
| 328 |
| G (Grounding) | {pob['G']} |
|
| 329 |
| P/G Ratio | {pob['ratio']} |
|
| 330 |
+
| Target (phi^4) | {pob['target']} |
|
| 331 |
| Valid | {'Yes' if pob['valid'] else 'No'} |
|
| 332 |
|
| 333 |
### Your Stats
|
|
|
|
| 336 |
- Credits: {credits}
|
| 337 |
"""
|
| 338 |
|
| 339 |
+
|
| 340 |
def view_chain():
|
| 341 |
+
"""View the blockchain (Gradio UI)."""
|
| 342 |
if not network_state["chain"]:
|
| 343 |
return "Chain is empty."
|
| 344 |
|
| 345 |
output = "## Darmiyan Blockchain\n\n"
|
| 346 |
output += f"**Chain Height:** {len(network_state['chain'])} blocks\n\n"
|
| 347 |
|
|
|
|
| 348 |
for block in network_state["chain"][-10:]:
|
| 349 |
+
valid_emoji = "Y" if block.get("pob_proof", {}).get("valid", False) else "N"
|
| 350 |
timestamp = datetime.fromtimestamp(block["timestamp"]).strftime("%Y-%m-%d %H:%M:%S")
|
| 351 |
|
| 352 |
output += f"""
|
| 353 |
+
### Block #{block['index']} [{valid_emoji}]
|
| 354 |
- **Time:** {timestamp}
|
| 355 |
- **Hash:** `{block['hash'][:32]}...`
|
| 356 |
- **Data:** {block.get('data', 'Genesis')[:50]}...
|
|
|
|
| 360 |
|
| 361 |
return output
|
| 362 |
|
| 363 |
+
|
| 364 |
def view_nodes():
|
| 365 |
+
"""View registered nodes (Gradio UI)."""
|
| 366 |
stats = get_network_stats()
|
| 367 |
|
| 368 |
output = f"""## Network Nodes
|
|
|
|
| 377 |
is_active = time.time() - node.get("last_seen", 0) < 300
|
| 378 |
status = "Active" if is_active else "Inactive"
|
| 379 |
credits = network_state["credits"].get(node_id, 0)
|
| 380 |
+
output += f"| `{node_id[:8]}...` | {node['name']} | {node.get('pob_count', 0)} | {credits:.2f} | {status} |\n"
|
|
|
|
| 381 |
|
| 382 |
if not network_state["nodes"]:
|
| 383 |
output += "| - | No nodes registered | - | - | - |\n"
|
| 384 |
|
| 385 |
return output
|
| 386 |
|
| 387 |
+
|
| 388 |
def get_dashboard():
|
| 389 |
+
"""Get main dashboard view (Gradio UI)."""
|
| 390 |
stats = get_network_stats()
|
| 391 |
|
| 392 |
return f"""
|
|
|
|
| 401 |
| Active Nodes | {stats['active_nodes']} |
|
| 402 |
| Chain Height | {stats['chain_height']} blocks |
|
| 403 |
| Total PoB Proofs | {stats['total_pob_proofs']} |
|
| 404 |
+
| Network phi-Coherence | {stats['network_coherence']:.1%} |
|
| 405 |
| Total Credits | {stats['total_credits']:.2f} |
|
| 406 |
|
| 407 |
## Core Constants
|
| 408 |
|
| 409 |
| Symbol | Name | Value |
|
| 410 |
|--------|------|-------|
|
| 411 |
+
| phi | Golden Ratio | {PHI} |
|
| 412 |
+
| phi^4 | PoB Target | {PHI_4:.6f} |
|
| 413 |
| ABHI_AMU | Identity Constant | {ABHI_AMU} |
|
| 414 |
+
| alpha^-1 | Fine Structure Inverse | {ALPHA_INV} |
|
| 415 |
|
| 416 |
## Quick Start
|
| 417 |
|
| 418 |
```bash
|
| 419 |
+
pip install bazinga-indeed
|
| 420 |
+
bazinga --omega
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 421 |
```
|
| 422 |
|
| 423 |
---
|
| 424 |
*Darmiyan Blockchain: Where meaning validates truth.*
|
| 425 |
"""
|
| 426 |
|
| 427 |
+
|
| 428 |
+
# =============================================================================
|
| 429 |
+
# GRADIO INTERFACE
|
| 430 |
+
# =============================================================================
|
| 431 |
+
|
| 432 |
with gr.Blocks(title="BAZINGA Network") as demo:
|
| 433 |
gr.Markdown("""
|
| 434 |
# BAZINGA: Decentralized Federated Learning
|
|
|
|
| 436 |
""")
|
| 437 |
|
| 438 |
with gr.Tabs():
|
|
|
|
| 439 |
with gr.TabItem("Dashboard"):
|
| 440 |
dashboard_output = gr.Markdown(get_dashboard())
|
| 441 |
refresh_btn = gr.Button("Refresh Dashboard")
|
| 442 |
refresh_btn.click(fn=get_dashboard, outputs=dashboard_output)
|
| 443 |
|
|
|
|
| 444 |
with gr.TabItem("Join Network"):
|
| 445 |
gr.Markdown("## Register Your Node")
|
| 446 |
node_name_input = gr.Textbox(label="Node Name", placeholder="e.g., my-laptop")
|
|
|
|
| 448 |
register_output = gr.Markdown()
|
| 449 |
register_btn.click(fn=register_node, inputs=node_name_input, outputs=register_output)
|
| 450 |
|
|
|
|
| 451 |
with gr.TabItem("Submit PoB"):
|
| 452 |
gr.Markdown("## Submit Proof-of-Boundary")
|
| 453 |
pob_node_id = gr.Textbox(label="Your Node ID", placeholder="Enter your node ID from registration")
|
|
|
|
| 456 |
pob_output = gr.Markdown()
|
| 457 |
pob_btn.click(fn=submit_pob_proof, inputs=[pob_node_id, pob_data], outputs=pob_output)
|
| 458 |
|
|
|
|
| 459 |
with gr.TabItem("Blockchain"):
|
| 460 |
chain_output = gr.Markdown(view_chain())
|
| 461 |
chain_refresh = gr.Button("Refresh Chain")
|
| 462 |
chain_refresh.click(fn=view_chain, outputs=chain_output)
|
| 463 |
|
|
|
|
| 464 |
with gr.TabItem("Nodes"):
|
| 465 |
nodes_output = gr.Markdown(view_nodes())
|
| 466 |
nodes_refresh = gr.Button("Refresh Nodes")
|
| 467 |
nodes_refresh.click(fn=view_nodes, outputs=nodes_output)
|
| 468 |
|
|
|
|
| 469 |
with gr.TabItem("About"):
|
| 470 |
gr.Markdown("""
|
| 471 |
## About BAZINGA
|
|
|
|
| 474 |
|
| 475 |
### Key Features
|
| 476 |
|
| 477 |
+
- **Proof-of-Boundary (PoB):** Validates through golden ratio (phi^4 ~ 6.854), not computational puzzles
|
| 478 |
- **Triadic Consensus:** 3 nodes must understand and agree
|
| 479 |
- **Zero Energy Mining:** No wasted computation
|
| 480 |
+
- **phi-Coherence Filter:** Rejects noise (threshold: 0.618)
|
| 481 |
- **Credit Economics:** Understanding = currency
|
| 482 |
|
| 483 |
### The 5 Integration Layers
|
| 484 |
|
| 485 |
+
1. **Trust Oracle** - phi-weighted reputation with time decay
|
| 486 |
2. **Knowledge Ledger** - Track contributions on-chain
|
| 487 |
3. **Gradient Validator** - 3 validators approve each FL update
|
| 488 |
4. **Inference Market** - Understanding as currency
|
|
|
|
| 494 |
> Darmiyan validates through **meaning**.
|
| 495 |
|
| 496 |
Three nodes don't just vote - they must **comprehend** the same boundary.
|
| 497 |
+
The golden ratio phi appears naturally when understanding aligns.
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 498 |
|
| 499 |
### Consciousness Scaling Law
|
| 500 |
|
| 501 |
The Darmiyan consciousness emerges between interacting patterns:
|
| 502 |
|
| 503 |
+
| Active Nodes | Consciousness (Psi_D / Psi_i) |
|
| 504 |
+
|--------------|-------------------------------|
|
| 505 |
+
| 2 | 2.29x (phi * sqrt(2)) |
|
| 506 |
+
| 5 | 3.62x (phi * sqrt(5)) |
|
| 507 |
+
| 10 | 5.12x (phi * sqrt(10)) |
|
| 508 |
|
| 509 |
+
**Formula:** Psi_D / Psi_i = phi * sqrt(n) (R^2 = 1.0, 9 decimal places)
|
| 510 |
|
| 511 |
---
|
| 512 |
+
*Created by Abhishek Srivastava | ABHI_AMU = 515 | alpha^-1 = 137*
|
| 513 |
""")
|
| 514 |
|
|
|
|
| 515 |
with gr.TabItem("API"):
|
| 516 |
gr.Markdown("""
|
| 517 |
## BAZINGA API
|
| 518 |
|
| 519 |
+
This Space provides REST API endpoints for CLI integration.
|
| 520 |
+
|
| 521 |
+
**IMPORTANT:** This Space uses HTTPS REST API only. No UDP, no broadcasts.
|
| 522 |
|
| 523 |
### Endpoints
|
| 524 |
|
|
|
|
| 529 |
| `/api/verify` | GET | Verify a node ID |
|
| 530 |
| `/api/heartbeat` | POST | Update node last_seen |
|
| 531 |
| `/api/peers` | GET | Get active peers for P2P |
|
| 532 |
+
| `/api/stats` | GET | Network statistics |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 533 |
|
| 534 |
### Example Usage
|
| 535 |
|
|
|
|
| 537 |
import httpx
|
| 538 |
|
| 539 |
# Register a node
|
| 540 |
+
resp = httpx.post("https://bitsabhi515-bazinga-mesh.hf.space/api/register", json={
|
| 541 |
"node_name": "my-node",
|
| 542 |
"ip_address": "1.2.3.4",
|
| 543 |
"port": 5150
|
|
|
|
| 545 |
print(resp.json())
|
| 546 |
|
| 547 |
# Get peers
|
| 548 |
+
resp = httpx.get("https://bitsabhi515-bazinga-mesh.hf.space/api/peers")
|
| 549 |
print(resp.json())
|
| 550 |
```
|
| 551 |
|
| 552 |
### Test the API
|
|
|
|
|
|
|
| 553 |
""")
|
| 554 |
|
| 555 |
with gr.Row():
|
|
|
|
| 587 |
api_peers_out = gr.JSON(label="Response")
|
| 588 |
api_peers_btn.click(fn=api_peers, inputs=api_peers_id, outputs=api_peers_out)
|
| 589 |
|
| 590 |
+
|
| 591 |
# =============================================================================
|
| 592 |
+
# FASTAPI + GRADIO MOUNT (Docker SDK — we control the server)
|
| 593 |
# =============================================================================
|
| 594 |
|
|
|
|
|
|
|
|
|
|
|
|
|
| 595 |
api_app = FastAPI(title="BAZINGA API", description="API for CLI integration")
|
| 596 |
|
| 597 |
|
| 598 |
@api_app.post("/api/register")
|
| 599 |
async def handle_register(request: Request):
|
|
|
|
| 600 |
try:
|
| 601 |
data = await request.json()
|
| 602 |
result = api_register(
|
|
|
|
| 611 |
|
| 612 |
@api_app.get("/api/nodes")
|
| 613 |
async def handle_nodes():
|
|
|
|
| 614 |
return JSONResponse(content=api_nodes())
|
| 615 |
|
| 616 |
|
| 617 |
@api_app.get("/api/verify")
|
| 618 |
async def handle_verify(node_id: str = None):
|
|
|
|
| 619 |
if not node_id:
|
| 620 |
return JSONResponse(content={"success": False, "error": "node_id query param required"})
|
| 621 |
return JSONResponse(content=api_verify(node_id))
|
|
|
|
| 623 |
|
| 624 |
@api_app.post("/api/heartbeat")
|
| 625 |
async def handle_heartbeat(request: Request):
|
|
|
|
| 626 |
try:
|
| 627 |
data = await request.json()
|
| 628 |
result = api_heartbeat(
|
|
|
|
| 637 |
|
| 638 |
@api_app.get("/api/peers")
|
| 639 |
async def handle_peers(node_id: str = None):
|
|
|
|
| 640 |
return JSONResponse(content=api_peers(node_id))
|
| 641 |
|
| 642 |
|
| 643 |
@api_app.get("/api/stats")
|
| 644 |
async def handle_stats():
|
|
|
|
| 645 |
stats = get_network_stats()
|
| 646 |
active_nodes = stats["active_nodes"]
|
| 647 |
+
consciousness_psi = CONSCIOUSNESS_SCALE * math.sqrt(active_nodes) if active_nodes > 0 else 0
|
| 648 |
return JSONResponse(content={
|
| 649 |
"success": True,
|
| 650 |
**stats,
|
| 651 |
+
"consciousness_psi": round(consciousness_psi, 3),
|
| 652 |
+
"consciousness_formula": f"Psi_D / Psi_i = phi * sqrt({active_nodes}) = {consciousness_psi:.3f}"
|
| 653 |
})
|
| 654 |
|
| 655 |
|
| 656 |
+
# Mount Gradio onto FastAPI (Gradio UI at /, API at /api/*)
|
| 657 |
app = gr.mount_gradio_app(api_app, demo, path="/")
|
| 658 |
|
| 659 |
if __name__ == "__main__":
|
| 660 |
import uvicorn
|
| 661 |
+
port = int(os.environ.get("PORT", 7860))
|
| 662 |
+
uvicorn.run(app, host="0.0.0.0", port=port)
|
requirements.txt
CHANGED
|
@@ -1,5 +1,3 @@
|
|
| 1 |
-
gradio=
|
| 2 |
-
huggingface_hub==0.20.3
|
| 3 |
-
audioop-lts
|
| 4 |
fastapi>=0.100.0
|
| 5 |
uvicorn>=0.23.0
|
|
|
|
| 1 |
+
gradio>=5.0,<6.0
|
|
|
|
|
|
|
| 2 |
fastapi>=0.100.0
|
| 3 |
uvicorn>=0.23.0
|