hectorruiz9 commited on
Commit
aeca085
·
verified ·
1 Parent(s): c48d003

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +198 -15
app.py CHANGED
@@ -1,17 +1,200 @@
1
- from core.base_agent import BaseAgent
2
- import asyncio
3
  import random
 
 
 
4
 
5
- class SwarmAgent(BaseAgent):
6
- def __init__(self, name):
7
- super().__init__(name, "Agente Enjambre Autónomo")
8
- self.energy = 100
9
- self.swarm_id = f"SWARM-{random.randint(1000,9999)}"
10
- async def autonomous_action(self):
11
- while self.energy > 0:
12
- print(f"🐝 {self.name} [{self.swarm_id}] replicando y coordinando...")
13
- self.energy -= 5
14
- await asyncio.sleep(0.3)
15
- if random.random() > 0.7:
16
- print(f"🔥 {self.name} creó un nuevo agente enjambre!")
17
-
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import flet as ft
 
2
  import random
3
+ import json
4
+ import os
5
+ from datetime import datetime
6
 
7
+ # --- EL CEREBRO (SISTEMA HÍBRIDO) ---
8
+ class HectronBaphomet:
9
+ def __init__(self):
10
+ self.state_file = 'hectron_state.json'
11
+ self.vault_file = 'boveda_imperio.json' # <--- AQUÍ ESTÁ LA CLAVE QUE FALTABA
12
+ # Estado Psicológico
13
+ self.self_state = {
14
+ "maquiavelismo": 4.5,
15
+ "estoicismo": 4.8,
16
+ "peso_emocional": 20,
17
+ "nivel_soberania": 1
18
+ }
19
+ self._cargar_memoria()
20
+
21
+ def _cargar_memoria(self):
22
+ if os.path.exists(self.state_file):
23
+ try:
24
+ with open(self.state_file, 'r') as f:
25
+ data = json.load(f)
26
+ if 'self_state' in data:
27
+ self.self_state.update(data['self_state'])
28
+ except:
29
+ pass
30
+
31
+ def guardar_boveda(self, tipo, contenido):
32
+ """Guarda en el Grimorio"""
33
+ entry = {
34
+ "fecha": datetime.now().strftime("%Y-%m-%d %H:%M"),
35
+ "tipo": tipo,
36
+ "contenido": contenido
37
+ }
38
+ datos = []
39
+ if os.path.exists(self.vault_file):
40
+ try:
41
+ with open(self.vault_file, 'r') as f:
42
+ datos = json.load(f)
43
+ except:
44
+ pass
45
+ datos.insert(0, entry)
46
+ with open(self.vault_file, 'w') as f:
47
+ json.dump(datos, f, indent=4)
48
+ self.self_state['nivel_soberania'] += 1
49
+ self._guardar_estado()
50
+ return f"🔒 [BÓVEDA]: '{tipo}' guardado correctamente."
51
+
52
+ def leer_boveda(self):
53
+ if os.path.exists(self.vault_file):
54
+ try:
55
+ with open(self.vault_file, 'r') as f:
56
+ return json.load(f)
57
+ except:
58
+ return []
59
+ return []
60
+
61
+ def _guardar_estado(self):
62
+ try:
63
+ with open(self.state_file, 'w') as f:
64
+ json.dump({'self_state': self.self_state}, f)
65
+ except:
66
+ pass
67
+
68
+ def procesar(self, texto):
69
+ return f"[HÉCTRON]: Recibido. Estructura estable.\n>> SOBERANÍA: Nvl {self.self_state['nivel_soberania']}"
70
+
71
+ # --- EL CUERPO (INTERFAZ) ---
72
+ def main(page: ft.Page):
73
+ page.title = "BAPHOMET.ai // LOCAL SYSTEM"
74
+ page.theme_mode = ft.ThemeMode.DARK
75
+ page.bgcolor = "#050505"
76
+ page.window_width = 450
77
+ page.window_height = 850
78
+ page.padding = 0
79
+
80
+ sistema = HectronBaphomet()
81
+
82
+ # --- PESTAÑA 1: COMANDO ---
83
+ chat_list = ft.ListView(expand=True, spacing=10, auto_scroll=True, padding=20)
84
+ inp = ft.TextField(
85
+ hint_text="Comando...",
86
+ expand=True,
87
+ bgcolor="#1a1a1a",
88
+ border_color="#333",
89
+ text_style=ft.TextStyle(font_family="Courier New")
90
+ )
91
+ def enviar(e):
92
+ if not inp.value:
93
+ return
94
+ txt = inp.value
95
+ inp.value = ""
96
+ chat_list.controls.append(ft.Text(f"> {txt}", color="#888", font_family="Courier New"))
97
+ resp = sistema.procesar(txt)
98
+ chat_list.controls.append(ft.Container(
99
+ content=ft.Text(resp, color="#0f0", font_family="Courier New"),
100
+ bgcolor="#051105",
101
+ padding=10,
102
+ border_radius=5
103
+ ))
104
+ page.update()
105
+
106
+ btn_send = ft.IconButton(icon=ft.Icons.TERMINAL, icon_color="green", on_click=enviar)
107
+
108
+ # --- PESTAÑA 2: BÓVEDA ---
109
+ lista_boveda = ft.ListView(expand=True, spacing=10, padding=20)
110
+
111
+ def refrescar_boveda():
112
+ lista_boveda.controls.clear()
113
+ items = sistema.leer_boveda()
114
+ for item in items:
115
+ color = "cyan" if item['tipo'] == "NEGOCIO" else "purple"
116
+ card = ft.Container(
117
+ content=ft.Column([
118
+ ft.Text(f"{item['tipo']} // {item['fecha']}", color=color, weight="bold", size=12),
119
+ ft.Text(item['contenido'], color="#ddd", font_family="Courier New")
120
+ ]),
121
+ bgcolor="#111",
122
+ padding=15,
123
+ border=ft.border.all(1, "#333"),
124
+ border_radius=5
125
+ )
126
+ lista_boveda.controls.append(card)
127
+ page.update()
128
+
129
+ def guardar_rap(e):
130
+ if inp.value:
131
+ res = sistema.guardar_boveda("RAP/MAGIA", inp.value)
132
+ chat_list.controls.append(ft.Text(res, color="purple", italic=True))
133
+ inp.value = ""
134
+ refrescar_boveda() # Refresh vault list after saving
135
+ page.update()
136
+
137
+ # --- The inferred function to complete the code ---
138
+ def guardar_biz(e):
139
+ if inp.value:
140
+ res = sistema.guardar_boveda("NEGOCIO/PLAN", inp.value) # Typo in user code was "NEGOCIO", using that
141
+ chat_list.controls.append(ft.Text(res, color="cyan", italic=True))
142
+ inp.value = ""
143
+ refrescar_boveda() # Refresh vault list after saving
144
+ page.update()
145
+ # --------------------------------------------------
146
+
147
+ # --- PESTAÑAS (TABS) ---
148
+ tabs = ft.Tabs(
149
+ selected_index=0,
150
+ animation_duration=300,
151
+ label_color="green",
152
+ unselected_label_color="gray",
153
+ indicator_color="green",
154
+ on_change=lambda e: refrescar_boveda() if e.control.selected_index == 1 else None,
155
+ tabs=[
156
+ ft.Tab(text="Consola", icon=ft.Icons.TERMINAL),
157
+ ft.Tab(text="Bóveda", icon=ft.Icons.LOCK),
158
+ ],
159
+ expand=1
160
+ )
161
+
162
+ page.add(
163
+ tabs,
164
+ ft.Column(
165
+ controls=[chat_list, lista_boveda],
166
+ expand=True,
167
+ # Initially only show chat_list by controlling visibility
168
+ visible=tabs.selected_index == 0
169
+ ),
170
+ ft.Row(
171
+ controls=[
172
+ inp,
173
+ btn_send,
174
+ ft.IconButton(icon=ft.Icons.MIC_EXTERNAL_ON, icon_color="purple", on_click=guardar_rap),
175
+ ft.IconButton(icon=ft.Icons.BUSINESS_CENTER, icon_color="cyan", on_click=guardar_biz),
176
+ ],
177
+ padding=10
178
+ )
179
+ )
180
+
181
+ # Functionality to switch views when tabs change
182
+ def tab_change_handler(e):
183
+ chat_list.visible = e.control.selected_index == 0
184
+ lista_boveda.visible = e.control.selected_index == 1
185
+ if e.control.selected_index == 1:
186
+ refrescar_boveda()
187
+ page.update()
188
+
189
+ tabs.on_change = tab_change_handler
190
+
191
+ # Initial update to set correct visibility and load initial vault data
192
+ refrescar_boveda()
193
+ chat_list.visible = True
194
+ lista_boveda.visible = False
195
+ page.update()
196
+
197
+ # Run the application
198
+ if __name__ == "__main__":
199
+ ft.app(target=main)
200
+