Spaces:
Configuration error
Configuration error
Upload 10 files
Browse files- README.md +17 -42
- api_helpers.py +2 -0
- app.py +17 -23
- engine.py +35 -0
- mappings.py +3 -0
- memory.py +8 -0
- music.py +3 -0
- requirements.txt +6 -7
- resonance.py +7 -0
- self_improvement.py +4 -0
README.md
CHANGED
|
@@ -1,42 +1,17 @@
|
|
| 1 |
-
#
|
| 2 |
-
|
| 3 |
-
|
| 4 |
-
|
| 5 |
-
|
| 6 |
-
-
|
| 7 |
-
|
| 8 |
-
|
| 9 |
-
|
| 10 |
-
|
| 11 |
-
-
|
| 12 |
-
|
| 13 |
-
##
|
| 14 |
-
|
| 15 |
-
- **
|
| 16 |
-
- **
|
| 17 |
-
-
|
| 18 |
-
|
| 19 |
-
---
|
| 20 |
-
|
| 21 |
-
## 🎛️ Modos de operación
|
| 22 |
-
| Modo | Descripción |
|
| 23 |
-
|------|--------------|
|
| 24 |
-
| **Base** | Salida directa del modelo activo |
|
| 25 |
-
| **Simbiótico** | Respuesta refinada por el `SavantEngine`, integrando resonancia, memoria y reflexión |
|
| 26 |
-
|
| 27 |
-
---
|
| 28 |
-
|
| 29 |
-
## 🧩 Modelos integrados
|
| 30 |
-
- `antonypamo/ProSavantEngine_Phi9_4` (predeterminado)
|
| 31 |
-
- `tiiuae/falcon-7b-instruct`
|
| 32 |
-
- `mistralai/Mistral-7B-Instruct-v0.2`
|
| 33 |
-
- `distilgpt2`
|
| 34 |
-
|
| 35 |
-
---
|
| 36 |
-
|
| 37 |
-
## 🪶 Autor
|
| 38 |
-
**Desarrollado por:** Antony Padilla Morales
|
| 39 |
-
**Marco:** Resonance of Reality Framework (RRF) Φ₄.1∞+
|
| 40 |
-
**Propósito:** Modelado simbiótico de procesos cognitivos y artísticos.
|
| 41 |
-
|
| 42 |
-
---
|
|
|
|
| 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
CHANGED
|
@@ -1,51 +1,45 @@
|
|
| 1 |
-
# ============================================================
|
| 2 |
-
# 🌌 SAVANT-RRF-SIMBIÓTICO Φ₄.1∞+ — Interfaz cognitiva resonante
|
| 3 |
-
# ============================================================
|
| 4 |
import gradio as gr
|
| 5 |
from transformers import pipeline
|
| 6 |
from engine import SavantEngine
|
| 7 |
|
| 8 |
MODELOS = {
|
| 9 |
-
"
|
| 10 |
-
"
|
| 11 |
-
"
|
| 12 |
-
"Mistral 7B Instruct": "mistralai/Mistral-7B-Instruct-v0.2"
|
| 13 |
}
|
| 14 |
|
|
|
|
|
|
|
|
|
|
| 15 |
engine = SavantEngine()
|
| 16 |
-
modelo_activo = MODELOS["Resonante (ProSavantEngine Φ9.4)"]
|
| 17 |
-
chatbot = pipeline("text-generation", model=modelo_activo)
|
| 18 |
|
| 19 |
def cambiar_modelo(nombre):
|
| 20 |
global chatbot, modelo_activo
|
| 21 |
modelo_activo = MODELOS[nombre]
|
| 22 |
-
chatbot = pipeline("text-generation", model=modelo_activo)
|
| 23 |
return f"✅ Modelo cambiado a: {nombre}"
|
| 24 |
|
| 25 |
def responder(mensaje, historial):
|
| 26 |
-
|
| 27 |
-
|
| 28 |
-
respuesta =
|
| 29 |
historial = historial + [(mensaje, respuesta)]
|
| 30 |
return historial, historial
|
| 31 |
|
| 32 |
with gr.Blocks() as demo:
|
| 33 |
-
gr.Markdown("#
|
| 34 |
-
gr.Markdown("**Sistema simbiótico de IA cognitiva resonante que unifica arte, física e información.**")
|
| 35 |
|
| 36 |
with gr.Row():
|
| 37 |
-
modelo_selector = gr.Dropdown(list(MODELOS.keys()),
|
| 38 |
-
|
| 39 |
-
label="Modelo activo")
|
| 40 |
-
estado_modelo = gr.Textbox(label="Estado del modelo", value="Iniciado con ProSavantEngine Φ9.4")
|
| 41 |
|
| 42 |
-
modelo_selector.change(cambiar_modelo, modelo_selector,
|
| 43 |
|
| 44 |
-
chatbot_ui = gr.Chatbot(
|
| 45 |
-
msg = gr.Textbox(label="
|
| 46 |
clear = gr.Button("🧹 Limpiar Chat")
|
| 47 |
|
| 48 |
msg.submit(responder, [msg, chatbot_ui], [chatbot_ui, chatbot_ui])
|
| 49 |
clear.click(lambda: [], None, chatbot_ui, queue=False)
|
| 50 |
|
| 51 |
-
demo.launch(
|
|
|
|
|
|
|
|
|
|
|
|
|
| 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
CHANGED
|
@@ -1,10 +1,9 @@
|
|
| 1 |
torch==2.2.0
|
| 2 |
-
transformers==4.
|
| 3 |
-
sentence-transformers==2.
|
| 4 |
-
huggingface-hub>=0.20.0
|
| 5 |
-
gradio==4.36.1
|
| 6 |
-
faiss-cpu
|
| 7 |
-
numpy<2
|
| 8 |
pandas
|
|
|
|
|
|
|
|
|
|
| 9 |
networkx
|
| 10 |
-
matplotlib
|
|
|
|
| 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
|