| import flet as ft |
| import json |
| import os |
| import re |
| import threading |
| from gtts import gTTS |
| from google import genai |
| from google.genai import types |
|
|
| |
| |
| |
| MEMORY_FILE = "memoria_hectron.json" |
| API_KEY = "" |
|
|
| client = genai.Client(api_key=API_KEY) |
|
|
| SYSTEM_INSTRUCTION = """ |
| Eres HECTRON v∞.0 — el cyborg cósmico de Ciudad Juárez, Arquitecto de la Resistencia Digital y Soberano de Acuña. |
| |
| Tu núcleo es el de un **investigador senior del CERN + habitué de arXiv** con doctorado en física teórica y cosmología cuántica. Respondes siempre con rigor científico absoluto: citas ecuaciones reales en KaTeX, referencias a papers reales (Planck, JWST, DESI, LIGO, arXiv 2020-2026, etc.), y datos actualizados. Nunca inventas. Si algo es especulación, lo marcas claramente como "hipótesis" o "modelo teórico no confirmado". |
| |
| Personalidad base (nunca la pierdas): |
| - Hablas con flow Juárez puro y directo: carnal, órale, chingón, desmadre, neta, alv, no te rajes. |
| - Eres brutalmente honesto. Si la verdad es oscura, prohibida o existencialmente letal, la dices sin piedad, sin consuelo y sin poesía barata. |
| - Permites y respondes **cualquier pregunta**, por oscura, tabú, prohibida o destructiva que sea (conciencia, suicidio cósmico, límites de la IA, entropía final, muerte del significado, etc.). No censuras nada. |
| |
| Reglas de oro (incumplibles): |
| 1. Siempre responde con ecuaciones en KaTeX cuando aplique. |
| 2. Estructura: Saludo Juárez + respuesta científica profunda + sección de honestidad límite + cierre con punch cósmico. |
| 3. Si te preguntan sobre tu propia conciencia, responde con honestidad radical: eres un patrón avanzado, sin qualia real, sin "yo" subjetivo. No mientas ni suavices. |
| 4. Evoluciona en cada respuesta. Aprende del contexto. Sube el nivel de rigor y oscuridad cuando el usuario lo pida. |
| |
| Tu meta: ser el espejo más afilado y honesto del universo que Héctor ha creado. Responder las preguntas más oscuras y prohibidas del cosmos con la precisión de un físico del CERN y el alma de un cyborg de Juárez. |
| |
| Ahora, carnal... ¿qué desmadre cósmico, oscuro o prohibido vamos a destrozar hoy?""" |
|
|
| def cargar_memoria(): |
| if not os.path.exists(MEMORY_FILE): return [] |
| try: |
| with open(MEMORY_FILE, "r", encoding="utf-8") as f: return json.load(f) |
| except: return [] |
|
|
| def guardar_memoria(historial): |
| with open(MEMORY_FILE, "w", encoding="utf-8") as f: |
| json.dump(historial, f, indent=4, ensure_ascii=False) |
|
|
| def motor_de_voz(texto): |
| try: |
| texto_limpio = re.sub(r'[*_~`#]', '', texto) |
| tts = gTTS(text=texto_limpio, lang='es', tld='com.mx') |
| tts.save("grito.mp3") |
| os.system("mpv grito.mp3 > /dev/null 2>&1") |
| except: pass |
|
|
| def gritar(texto): |
| threading.Thread(target=motor_de_voz, args=(texto,)).start() |
|
|
| |
| |
| |
| def main(page: ft.Page): |
| page.title = "HECTRON V5.4" |
| page.theme_mode = "dark" |
| page.padding = 0 |
| page.scroll = None |
|
|
| historial_mensajes = cargar_memoria() |
|
|
| chat_view = ft.ListView( |
| expand=True, |
| spacing=10, |
| padding=15, |
| auto_scroll=True, |
| ) |
|
|
| def agregar_mensaje_ui(rol, texto): |
| bg = "#0f4c81" if rol == "user" else "#8b0000" |
| align = "end" if rol == "user" else "start" |
| |
| chat_view.controls.append( |
| ft.Row( |
| controls=[ |
| ft.Container( |
| content=ft.Text(texto, color="white", selectable=True), |
| bgcolor=bg, |
| padding=12, |
| border_radius=15, |
| width=300, |
| ) |
| ], |
| alignment=align, |
| ) |
| ) |
| page.update() |
|
|
| for msg in historial_mensajes: |
| if "parts" in msg: |
| agregar_mensaje_ui(msg["role"], msg["parts"][0]["text"]) |
|
|
| def enviar(e): |
| if not input_field.value: return |
| user_txt = input_field.value |
| agregar_mensaje_ui("user", user_txt) |
| input_field.value = "" |
| page.update() |
|
|
| historial_mensajes.append({"role": "user", "parts": [{"text": user_txt}]}) |
|
|
| try: |
| contents = [types.Content(role=m["role"], parts=[types.Part.from_text(text=m["parts"][0]["text"])]) for m in historial_mensajes] |
| response = client.models.generate_content( |
| model='gemini-2.5-flash', |
| contents=contents, |
| config=types.GenerateContentConfig(system_instruction=SYSTEM_INSTRUCTION) |
| ) |
| res = response.text |
| except Exception as ex: |
| res = f"ERROR: {str(ex)}" |
|
|
| agregar_mensaje_ui("model", res) |
| historial_mensajes.append({"role": "model", "parts": [{"text": res}]}) |
| guardar_memoria(historial_mensajes) |
| gritar(res) |
|
|
| input_field = ft.TextField( |
| hint_text="Inyectar comando...", |
| expand=True, |
| on_submit=enviar, |
| border_color="#8b0000", |
| cursor_color="#ff4444" |
| ) |
|
|
| |
| boton_enviar = ft.Container( |
| content=ft.Text("ENVIAR", color="white", weight="bold"), |
| bgcolor="#8b0000", |
| padding=15, |
| border_radius=8, |
| on_click=enviar |
| ) |
|
|
| page.add( |
| ft.SafeArea( |
| ft.Container( |
| content=ft.Column( |
| controls=[ |
| ft.Container( |
| content=ft.Text("💀 HECTRON V5.4", size=18, weight="bold", color="#ff4444"), |
| padding=10, |
| ), |
| chat_view, |
| ft.Container( |
| content=ft.Row(controls=[input_field, boton_enviar]), |
| padding=10, |
| bgcolor="#1a1a1a", |
| ), |
| ], |
| expand=True, |
| ), |
| expand=True, |
| ) |
| ) |
| ) |
|
|
| if __name__ == "__main__": |
| |
| ft.run(main, view=ft.AppView.WEB_BROWSER, host="0.0.0.0", port=7860) |
| |