Spaces:
Runtime error
Runtime error
FerrellSyntheticIntelligence commited on
Commit ·
2d63935
1
Parent(s): 239d4ec
AOT: Finalize RAG-integrated Space deployment
Browse files- app.py +15 -44
- requirements.txt +3 -5
- src/core/memory_engine.py +25 -0
app.py
CHANGED
|
@@ -1,49 +1,20 @@
|
|
| 1 |
-
|
| 2 |
-
import
|
| 3 |
-
import sys
|
| 4 |
-
from pathlib import Path
|
| 5 |
|
| 6 |
-
|
| 7 |
-
|
| 8 |
-
|
| 9 |
|
| 10 |
-
|
| 11 |
-
from
|
| 12 |
-
|
| 13 |
-
|
| 14 |
|
| 15 |
-
|
| 16 |
-
|
| 17 |
-
|
| 18 |
-
|
| 19 |
-
|
| 20 |
-
|
| 21 |
-
dreamer = Dreamer(brain, interval_sec=600)
|
| 22 |
-
dreamer.start()
|
| 23 |
-
|
| 24 |
-
print("[+] Engine operational. Free-Energy optimization loops tracking live telemetry.")
|
| 25 |
-
print("Telemetry In > ", end="")
|
| 26 |
-
|
| 27 |
-
while True:
|
| 28 |
-
try:
|
| 29 |
-
user_input = input().strip()
|
| 30 |
-
if not user_input:
|
| 31 |
-
print("Telemetry In > ", end="")
|
| 32 |
-
continue
|
| 33 |
-
if user_input.lower() in ["exit", "quit"]:
|
| 34 |
-
dreamer.stop()
|
| 35 |
-
break
|
| 36 |
-
|
| 37 |
-
tokens = brain._tokenize(user_input)
|
| 38 |
-
logprob = brain.calculate_last_logprob(tokens)
|
| 39 |
-
fe_engine.ingest_observation(logprob)
|
| 40 |
-
brain.current_temperature = fe_engine.temperature_factor(base_temp=0.8)
|
| 41 |
-
temp_scheduler.tick()
|
| 42 |
-
response = brain.process(user_input)
|
| 43 |
-
print(f"Metrics Out > {response} [FE: {fe_engine.free_energy:.4f} | Temp: {brain.current_temperature:.4f}]\nTelemetry In > ", end="")
|
| 44 |
-
except (KeyboardInterrupt, EOFError):
|
| 45 |
-
dreamer.stop()
|
| 46 |
-
break
|
| 47 |
|
| 48 |
if __name__ == "__main__":
|
| 49 |
-
|
|
|
|
| 1 |
+
import gradio as gr
|
| 2 |
+
from src.core.memory_engine import MemoryEngine
|
|
|
|
|
|
|
| 3 |
|
| 4 |
+
# Initialize the Sovereign Brain
|
| 5 |
+
brain = MemoryEngine()
|
| 6 |
+
brain.ingest_knowledge('storage/knowledge')
|
| 7 |
|
| 8 |
+
def vitalis_chat(user_message, history):
|
| 9 |
+
# Retrieve relevant protocol from local vector store
|
| 10 |
+
response = brain.query(user_message)
|
| 11 |
+
return f"[VITALIS_CORE_UI]: {response}"
|
| 12 |
|
| 13 |
+
demo = gr.ChatInterface(
|
| 14 |
+
fn=vitalis_chat,
|
| 15 |
+
title="Vitalis Synthetic Intelligence | Sovereign Core",
|
| 16 |
+
theme="soft"
|
| 17 |
+
)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 18 |
|
| 19 |
if __name__ == "__main__":
|
| 20 |
+
demo.launch()
|
requirements.txt
CHANGED
|
@@ -1,6 +1,4 @@
|
|
| 1 |
-
|
| 2 |
-
pyyaml
|
| 3 |
-
click
|
| 4 |
-
faiss-cpu
|
| 5 |
sentence-transformers
|
| 6 |
-
|
|
|
|
|
|
| 1 |
+
gradio==4.26.0
|
|
|
|
|
|
|
|
|
|
| 2 |
sentence-transformers
|
| 3 |
+
faiss-cpu
|
| 4 |
+
numpy
|
src/core/memory_engine.py
ADDED
|
@@ -0,0 +1,25 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
from sentence_transformers import SentenceTransformer
|
| 2 |
+
import faiss
|
| 3 |
+
import numpy as np
|
| 4 |
+
import os
|
| 5 |
+
|
| 6 |
+
class MemoryEngine:
|
| 7 |
+
def __init__(self):
|
| 8 |
+
self.model = SentenceTransformer('all-MiniLM-L6-v2')
|
| 9 |
+
self.index = None
|
| 10 |
+
self.documents = []
|
| 11 |
+
|
| 12 |
+
def ingest_knowledge(self, directory):
|
| 13 |
+
for filename in os.listdir(directory):
|
| 14 |
+
with open(os.path.join(directory, filename), 'r') as f:
|
| 15 |
+
content = f.read()
|
| 16 |
+
self.documents.append(content)
|
| 17 |
+
embeddings = self.model.encode(self.documents)
|
| 18 |
+
dimension = embeddings.shape[1]
|
| 19 |
+
self.index = faiss.IndexFlatL2(dimension)
|
| 20 |
+
self.index.add(np.array(embeddings).astype('float32'))
|
| 21 |
+
|
| 22 |
+
def query(self, user_input):
|
| 23 |
+
query_vector = self.model.encode([user_input])
|
| 24 |
+
D, I = self.index.search(np.array(query_vector).astype('float32'), k=1)
|
| 25 |
+
return self.documents[I[0][0]]
|