Spaces:
Build error
Build error
Upload 10 files
Browse files- README.md +16 -13
- api_helpers.py +2 -0
- app.py +45 -0
- engine.py +35 -0
- mappings.py +3 -0
- memory.py +8 -0
- music.py +3 -0
- requirements.txt +9 -0
- resonance.py +7 -0
- self_improvement.py +4 -0
README.md
CHANGED
|
@@ -1,14 +1,17 @@
|
|
| 1 |
-
|
| 2 |
-
|
| 3 |
-
emoji: 🌍
|
| 4 |
-
colorFrom: pink
|
| 5 |
-
colorTo: blue
|
| 6 |
-
sdk: gradio
|
| 7 |
-
sdk_version: 5.49.1
|
| 8 |
-
app_file: app.py
|
| 9 |
-
pinned: false
|
| 10 |
-
license: apache-2.0
|
| 11 |
-
short_description: RRF
|
| 12 |
-
---
|
| 13 |
|
| 14 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
# 🤖 SAVANT-RRF Simbiótico (CPU Ready)
|
| 2 |
+
Este Space implementa el **núcleo simbiótico Savant-RRF**, con integración resonante, memoria adaptativa y auto-mejora ligera.
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 3 |
|
| 4 |
+
### 📦 Estructura
|
| 5 |
+
- `app.py` → Interfaz Gradio con selección de modelo (DistilGPT2, Falcon, Mistral)
|
| 6 |
+
- `engine.py` → Núcleo simbiótico del sistema RRF
|
| 7 |
+
- `resonance.py` → Simulador de resonancia discreta
|
| 8 |
+
- `music.py` → Adaptador de texto a secuencias musicales
|
| 9 |
+
- `memory.py` → Memoria incremental
|
| 10 |
+
- `self_improvement.py` → Módulo de auto-refinamiento
|
| 11 |
+
- `requirements.txt` → Dependencias listas para Hugging Face Spaces (CPU)
|
| 12 |
+
|
| 13 |
+
### 🚀 Uso
|
| 14 |
+
Sube este ZIP completo a tu **Hugging Face Space** y selecciona:
|
| 15 |
+
- Runtime: **CPU**
|
| 16 |
+
- SDK: **Gradio**
|
| 17 |
+
- Entrypoint: `app.py`
|
api_helpers.py
ADDED
|
@@ -0,0 +1,2 @@
|
|
|
|
|
|
|
|
|
|
| 1 |
+
def chat_refine(text, base_output, self_improver=None):
|
| 2 |
+
return f"[RRF-refined] {base_output[:200]}"
|
app.py
ADDED
|
@@ -0,0 +1,45 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import gradio as gr
|
| 2 |
+
from transformers import pipeline
|
| 3 |
+
from engine import SavantEngine
|
| 4 |
+
|
| 5 |
+
MODELOS = {
|
| 6 |
+
"Ligero (distilgpt2)": "distilgpt2",
|
| 7 |
+
"Avanzado (Falcon-7B-Instruct)": "tiiuae/falcon-7b-instruct",
|
| 8 |
+
"Avanzado (Mistral-7B-Instruct)": "mistralai/Mistral-7B-Instruct-v0.2"
|
| 9 |
+
}
|
| 10 |
+
|
| 11 |
+
modelo_activo = MODELOS["Ligero (distilgpt2)"]
|
| 12 |
+
chatbot = pipeline("text-generation", model=modelo_activo, device=-1)
|
| 13 |
+
|
| 14 |
+
engine = SavantEngine()
|
| 15 |
+
|
| 16 |
+
def cambiar_modelo(nombre):
|
| 17 |
+
global chatbot, modelo_activo
|
| 18 |
+
modelo_activo = MODELOS[nombre]
|
| 19 |
+
chatbot = pipeline("text-generation", model=modelo_activo, device=-1)
|
| 20 |
+
return f"✅ Modelo cambiado a: {nombre}"
|
| 21 |
+
|
| 22 |
+
def responder(mensaje, historial):
|
| 23 |
+
base_output = chatbot(mensaje, max_length=200, num_return_sequences=1, do_sample=True)[0]["generated_text"]
|
| 24 |
+
enriched = engine.handle_query(mensaje, base_output)
|
| 25 |
+
respuesta = enriched["response"]
|
| 26 |
+
historial = historial + [(mensaje, respuesta)]
|
| 27 |
+
return historial, historial
|
| 28 |
+
|
| 29 |
+
with gr.Blocks() as demo:
|
| 30 |
+
gr.Markdown("# 🤖 SAVANT-RRF Simbiótico – AGI Experimental (CPU Ready)")
|
| 31 |
+
|
| 32 |
+
with gr.Row():
|
| 33 |
+
modelo_selector = gr.Dropdown(list(MODELOS.keys()), value="Ligero (distilgpt2)", label="Selecciona Modelo")
|
| 34 |
+
salida_modelo = gr.Textbox(label="Estado del modelo")
|
| 35 |
+
|
| 36 |
+
modelo_selector.change(cambiar_modelo, modelo_selector, salida_modelo)
|
| 37 |
+
|
| 38 |
+
chatbot_ui = gr.Chatbot()
|
| 39 |
+
msg = gr.Textbox(label="Escribe aquí tu mensaje")
|
| 40 |
+
clear = gr.Button("🧹 Limpiar Chat")
|
| 41 |
+
|
| 42 |
+
msg.submit(responder, [msg, chatbot_ui], [chatbot_ui, chatbot_ui])
|
| 43 |
+
clear.click(lambda: [], None, chatbot_ui, queue=False)
|
| 44 |
+
|
| 45 |
+
demo.launch()
|
engine.py
ADDED
|
@@ -0,0 +1,35 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
from resonance import ResonanceSimulator
|
| 2 |
+
from mappings import IcosaMap, DodecaMap
|
| 3 |
+
from music import MusicAdapter
|
| 4 |
+
from memory import MemoryStore
|
| 5 |
+
from self_improvement import SelfImprover
|
| 6 |
+
from api_helpers import chat_refine
|
| 7 |
+
import pandas as pd, json, os, time
|
| 8 |
+
|
| 9 |
+
class SavantEngine:
|
| 10 |
+
def __init__(self):
|
| 11 |
+
self.memory = MemoryStore("SAVANT_memory.jsonl")
|
| 12 |
+
self.icosa = IcosaMap()
|
| 13 |
+
self.dodeca = DodecaMap()
|
| 14 |
+
self.resonator = ResonanceSimulator()
|
| 15 |
+
self.music = MusicAdapter()
|
| 16 |
+
self.self_improver = SelfImprover(self.memory)
|
| 17 |
+
|
| 18 |
+
def _classify(self, text):
|
| 19 |
+
t = text.lower()
|
| 20 |
+
if any(k in t for k in ("equation", "dirac", "hamiltoniano")): return "equation"
|
| 21 |
+
if any(k in t for k in ("node", "icosahedron", "nodo")): return "node"
|
| 22 |
+
if any(k in t for k in ("freq", "music", "nota", "resonance")): return "resonance"
|
| 23 |
+
return "chat"
|
| 24 |
+
|
| 25 |
+
def handle_query(self, text, base_output=None):
|
| 26 |
+
kind = self._classify(text)
|
| 27 |
+
if kind == "resonance":
|
| 28 |
+
r = self.resonator.simulate(text)
|
| 29 |
+
seq = self.music.adapt_text_to_music(text)
|
| 30 |
+
response = f"🎵 Resonancia detectada. Frecuencia dominante: {r['summary']['dom_freq']:.4f} Hz. Secuencia inicial: {seq[:5]}"
|
| 31 |
+
else:
|
| 32 |
+
refined = chat_refine(text, base_output or "", self_improver=self.self_improver)
|
| 33 |
+
response = refined
|
| 34 |
+
self.memory.add({"type": kind, "query": text, "response": response, "_ts": time.time()})
|
| 35 |
+
return {"response": response}
|
mappings.py
ADDED
|
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
class IcosaMap:
|
| 2 |
+
def closest_node(self, text): return "φ-node"
|
| 3 |
+
class DodecaMap: pass
|
memory.py
ADDED
|
@@ -0,0 +1,8 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import json, os
|
| 2 |
+
class MemoryStore:
|
| 3 |
+
def __init__(self, path):
|
| 4 |
+
self.path = path
|
| 5 |
+
if not os.path.exists(path): open(path, 'w').close()
|
| 6 |
+
def add(self, record):
|
| 7 |
+
with open(self.path, 'a') as f:
|
| 8 |
+
f.write(json.dumps(record) + "\n")
|
music.py
ADDED
|
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
class MusicAdapter:
|
| 2 |
+
def adapt_text_to_music(self, text):
|
| 3 |
+
return [(440, 0.5), (466, 0.25), (494, 0.5)]
|
requirements.txt
ADDED
|
@@ -0,0 +1,9 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
torch==2.2.0
|
| 2 |
+
transformers==4.40.0
|
| 3 |
+
sentence-transformers==2.6.1
|
| 4 |
+
pandas
|
| 5 |
+
numpy<2
|
| 6 |
+
gradio==5.0.2
|
| 7 |
+
faiss-cpu
|
| 8 |
+
networkx
|
| 9 |
+
matplotlib
|
resonance.py
ADDED
|
@@ -0,0 +1,7 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import numpy as np
|
| 2 |
+
class ResonanceSimulator:
|
| 3 |
+
def simulate(self, text):
|
| 4 |
+
freqs = np.abs(np.fft.rfftfreq(256, 1/44100))
|
| 5 |
+
signal = np.sin(2 * np.pi * freqs[:256] * np.random.rand())
|
| 6 |
+
dom_freq = float(freqs[np.argmax(signal)])
|
| 7 |
+
return {"summary": {"dom_freq": dom_freq, "max_power": float(signal.max())}}
|
self_improvement.py
ADDED
|
@@ -0,0 +1,4 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
class SelfImprover:
|
| 2 |
+
def __init__(self, memory): self.memory = memory
|
| 3 |
+
def propose(self): return "adjustment vector"
|
| 4 |
+
def evaluate_and_apply(self, proposal): return True, 1.0
|