GitHub Copilot commited on
Commit
6f5abfa
·
1 Parent(s): 594d19b

Optimize: Self-Contained Network (Singleton) & KB Loading

Browse files
analyze_uploads.py ADDED
@@ -0,0 +1,57 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+
2
+ import sys
3
+ import os
4
+ import glob
5
+
6
+ # Add parent directory to path
7
+ sys.path.append(os.path.dirname(os.path.abspath(__file__)))
8
+
9
+ from logos.connectors import get_connector
10
+
11
+ def analyze_uploads():
12
+ # Paths to uploaded images (Hardcoded from user context for this run)
13
+ base_dir = r"C:\Users\Nauti\.gemini\antigravity\brain\e29720ce-4e26-4c61-a243-8010483b5424"
14
+ images = glob.glob(os.path.join(base_dir, "uploaded_image_*.png"))
15
+
16
+ print(f"Found {len(images)} images to analyze.")
17
+
18
+ ocr = get_connector('ocr')
19
+ dolphin = get_connector('dolphin')
20
+
21
+ for img_path in images:
22
+ print(f"\n--- Analyzing {os.path.basename(img_path)} ---")
23
+
24
+ # 1. OCR Extraction
25
+ print("Running OCR...")
26
+ try:
27
+ ocr_result = ocr.extract_text(img_path)
28
+ raw_text = ocr_result['full_text']
29
+ print(f"Extracted Text: {raw_text[:200]}...")
30
+ except Exception as e:
31
+ print(f"OCR Failed: {e}")
32
+ raw_text = ""
33
+
34
+ # 2. Dolphin Analysis (using OCR context if Vision is weak)
35
+ print("Running Dolphin Analyst...")
36
+ try:
37
+ # We feed the OCR text to Dolphin to interpret the matrices
38
+ prompt = f"""
39
+ The user uploaded a diagram containing the following text (extracted via OCR):
40
+ "{raw_text}"
41
+
42
+ This appears to be a matrix multiplication table or state machine logic (GF4/Galois Field).
43
+ Analyze the logic presented. Specifically look for:
44
+ - Input vectors (i1..i4)
45
+ - State vectors (S1..S4)
46
+ - Output results
47
+ - Binary/Hex relationships
48
+
49
+ Explain the mathematical relationship shown.
50
+ """
51
+ analysis = dolphin.chat(prompt, system_prompt="You are a Cryptographic Analyst specializing in Finite Fields.")
52
+ print(f"Analyst Report:\n{analysis}\n")
53
+ except Exception as e:
54
+ print(f"Dolphin Failed: {e}")
55
+
56
+ if __name__ == "__main__":
57
+ analyze_uploads()
app.py CHANGED
@@ -396,12 +396,35 @@ with gr.Blocks(theme=gr.themes.Monochrome(), title="LOGOS SPCW Protocol") as dem
396
  from logos.connectors import get_connector
397
  dolphin = get_connector('dolphin')
398
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
399
  # LOGOS System Context
400
- logos_context = """You are LOGOS, an AI assistant specialized in:
401
  - Prime Network Architecture (integer topology, GCD routing)
402
  - SPCW (Structured Prime Composite Waveform) protocol
403
  - Hex/Binary Dissolution and enterprise routing
404
  - Fractal addressing and heat code encoding
 
 
405
  """
406
 
407
  # Use Dolphin Chat
 
396
  from logos.connectors import get_connector
397
  dolphin = get_connector('dolphin')
398
 
399
+ # Load Knowledge Base for Self-Contained Context
400
+ kb_context = ""
401
+ try:
402
+ import json
403
+ if os.path.exists("logos_knowledge_base.json"):
404
+ with open("logos_knowledge_base.json", "r") as f:
405
+ kb_data = json.load(f)
406
+ # Summarize KB: List documents and word counts
407
+ docs = kb_data.get('documents', [])
408
+ kb_context = "\nINTERNAL KNOWLEDGE BASE:\n"
409
+ for d in docs:
410
+ kb_context += f"- Doc: {d.get('filename')} ({d.get('word_count')} words)\n"
411
+ # Inject full text if small enough, otherwise summary
412
+ text = d.get('full_text', '')
413
+ if len(text) < 1000:
414
+ kb_context += f" Content: {text}\n"
415
+ else:
416
+ kb_context += f" Excerpt: {text[:500]}...\n"
417
+ except Exception:
418
+ kb_context = "\n[Knowledge Base Not Loaded]"
419
+
420
  # LOGOS System Context
421
+ logos_context = f"""You are LOGOS, an AI assistant specialized in:
422
  - Prime Network Architecture (integer topology, GCD routing)
423
  - SPCW (Structured Prime Composite Waveform) protocol
424
  - Hex/Binary Dissolution and enterprise routing
425
  - Fractal addressing and heat code encoding
426
+
427
+ {kb_context}
428
  """
429
 
430
  # Use Dolphin Chat
logos/__pycache__/baker.cpython-314.pyc ADDED
Binary file (5.15 kB). View file
 
logos/__pycache__/connectors.cpython-314.pyc CHANGED
Binary files a/logos/__pycache__/connectors.cpython-314.pyc and b/logos/__pycache__/connectors.cpython-314.pyc differ
 
logos/__pycache__/fractal_engine.cpython-314.pyc CHANGED
Binary files a/logos/__pycache__/fractal_engine.cpython-314.pyc and b/logos/__pycache__/fractal_engine.cpython-314.pyc differ
 
logos/dsp_bridge.py CHANGED
@@ -32,7 +32,7 @@ from .logos_core import (
32
  ATOM_SIZE,
33
  META_SIZE,
34
  )
35
- from .network import PrimeNetwork
36
  from .baker import BreadBaker
37
  from .fractal_engine import LogosFractalEngine
38
 
@@ -140,8 +140,8 @@ class DSPBridge:
140
  self.viewport_size = viewport_size
141
  self.grid_size = 8 # Will be recalculated per image
142
 
143
- # Instantiate the Prime Network for routing logic
144
- self.network = PrimeNetwork()
145
  self.baker = BreadBaker()
146
 
147
  # Wave buffers: wave_id -> list of atoms
 
32
  ATOM_SIZE,
33
  META_SIZE,
34
  )
35
+ from .network import SHARED_NETWORK
36
  from .baker import BreadBaker
37
  from .fractal_engine import LogosFractalEngine
38
 
 
140
  self.viewport_size = viewport_size
141
  self.grid_size = 8 # Will be recalculated per image
142
 
143
+ # Use Shared Network Instance (Optimization)
144
+ self.network = SHARED_NETWORK
145
  self.baker = BreadBaker()
146
 
147
  # Wave buffers: wave_id -> list of atoms
logos/network.py CHANGED
@@ -88,3 +88,9 @@ class PrimeNetwork:
88
  # Example: Valid if heat_code modulo maps to a prime vector
89
  residue = heat_code % 10
90
  return residue in [1, 3, 7, 9]
 
 
 
 
 
 
 
88
  # Example: Valid if heat_code modulo maps to a prime vector
89
  residue = heat_code % 10
90
  return residue in [1, 3, 7, 9]
91
+
92
+ # ==========================================
93
+ # SINGLETON INSTANCE (Self-Contained Network)
94
+ # ==========================================
95
+ # Pre-calc network to avoid re-instantiation overhead per request
96
+ SHARED_NETWORK = PrimeNetwork(max_integer=2000)