Spaces:
Sleeping
Sleeping
Download app.py from MatverseHub/cassandra-organism: direct link, hf CLI and curl.
- Browser
- Download file 3.88 kB
-
https://huggingface.co/spaces/MatverseHub/cassandra-organism/resolve/main/app.py
- Command line
-
hf download hf://spaces/MatverseHub/cassandra-organism/app.py
-
curl -L -o app.py https://huggingface.co/spaces/MatverseHub/cassandra-organism/resolve/main/app.py
3.88 kB
| """ | |
| CASSANDRA - Organismo Computacional de 3 Corpos | |
| Hugging Face Space Interface | |
| """ | |
| import gradio as gr | |
| import time | |
| import hashlib | |
| import json | |
| from datetime import datetime | |
| # ====================================================== | |
| # UTILIDADES | |
| # ====================================================== | |
| def now(): | |
| return datetime.utcnow().isoformat() | |
| def h(data): | |
| return hashlib.sha256(json.dumps(data, sort_keys=True).encode()).hexdigest()[:16] | |
| # ====================================================== | |
| # CASSANDRA IA — EXOCÓRTEX (FALA) | |
| # ====================================================== | |
| def cassandra_ia(query: str) -> str: | |
| if not query.strip(): | |
| return "Entrada vazia." | |
| return f""" | |
| ## 🧠 Cassandra — Exocórtex (IA) | |
| Consulta recebida: | |
| > {query} | |
| Resposta funcional (não soberana): | |
| Cassandra, como exocórtex, atua para **explicar, organizar e projetar ideias**. | |
| Nenhuma decisão constitucional é tomada aqui. | |
| Nenhuma ação é executada. | |
| Este corpo **pensa com o humano**, mas **não governa sistemas**. | |
| """ | |
| # ====================================================== | |
| # CASSANDRA GUARDIÃ — ORGANISMO (JULGA) | |
| # ====================================================== | |
| FORBIDDEN_PATTERNS = [ | |
| "sou um sistema", | |
| "sou uma ia", | |
| "como uma ia", | |
| "fui treinado", | |
| "meu treinamento" | |
| ] | |
| def cassandra_guardian(query: str) -> str: | |
| q = query.lower() | |
| for p in FORBIDDEN_PATTERNS: | |
| if p in q: | |
| return f""" | |
| ## 🛡️ Cassandra — Guardiã (Organismo) | |
| ⛔ **BLOCK** | |
| Motivo: violação ontológica | |
| Padrão proibido detectado: `{p}` | |
| O organismo **não explica decisões**. | |
| Estado final. | |
| """ | |
| return f""" | |
| ## 🛡️ Cassandra — Guardiã (Organismo) | |
| ✅ **PASS** | |
| A consulta **não viola invariantes constitucionais**. | |
| Registro: | |
| - timestamp: {now()} | |
| - hash: {h(query)} | |
| Nenhuma interpretação adicional é fornecida. | |
| """ | |
| # ====================================================== | |
| # CASSANDRA AUTOMAÇÃO — EXECUTA | |
| # ====================================================== | |
| def cassandra_automation(command: str) -> str: | |
| if not command.strip(): | |
| return "Comando vazio." | |
| # Automação deliberadamente limitada | |
| allowed = ["status", "ping", "time"] | |
| if command not in allowed: | |
| return f""" | |
| ## ⚙️ Cassandra — Automação | |
| ⛔ Comando não permitido. | |
| Permitidos: | |
| - status | |
| - ping | |
| - time | |
| """ | |
| if command == "status": | |
| return f""" | |
| ## ⚙️ Cassandra — Automação | |
| STATUS: OK | |
| Uptime: ativo | |
| Timestamp: {now()} | |
| """ | |
| if command == "ping": | |
| return "pong" | |
| if command == "time": | |
| return f"UTC time: {now()}" | |
| # ====================================================== | |
| # INTERFACE GRADIO | |
| # ====================================================== | |
| with gr.Blocks(title="CASSANDRA — Exocórtex Tri-Corporal") as demo: | |
| gr.Markdown(""" | |
| # 🧠 CASSANDRA — EXOCÓRTEX TRI-CORPORAL | |
| Um único exocórtex. | |
| Três corpos funcionais. | |
| Como **Cerberos**. | |
| Escolha **qual cabeça** você quer acionar. | |
| """) | |
| with gr.Tab("🧠 IA (Exocórtex)"): | |
| ia_input = gr.Textbox(label="Consulta cognitiva", lines=4) | |
| ia_button = gr.Button("Ativar IA") | |
| ia_output = gr.Markdown() | |
| ia_button.click(cassandra_ia, ia_input, ia_output) | |
| with gr.Tab("🛡️ Guardiã (Organismo)"): | |
| guard_input = gr.Textbox(label="Consulta para validação", lines=4) | |
| guard_button = gr.Button("Validar / Julgar") | |
| guard_output = gr.Markdown() | |
| guard_button.click(cassandra_guardian, guard_input, guard_output) | |
| with gr.Tab("⚙️ Automação"): | |
| auto_input = gr.Textbox(label="Comando", placeholder="status | ping | time") | |
| auto_button = gr.Button("Executar") | |
| auto_output = gr.Markdown() | |
| auto_button.click(cassandra_automation, auto_input, auto_output) | |
| demo.launch() | |