""" SnapKitty Sovereign Chat Harness Zero-Hallucination Chat — if it can't prove it, it won't say it. Pipeline: prompt → ERE P1-P5 gates → LLM → WORM seal → response """ import asyncio import json import gradio as gr from harness.pipeline import run from harness.gates import verify, prove # ── Helpers ────────────────────────────────────────────────────────────────── def _gate_table(verdict) -> str: rows = [] for g in verdict.gates: status = "✅" if g.passed else "❌" rows.append(f"| {g.gate} | {g.label} | {status} | {g.detail[:60]} |") table = ( "| Gate | Label | Status | Detail |\n" "|------|-------|--------|--------|\n" + "\n".join(rows) ) return table def _proof_panel(verdict) -> str: seal_short = (verdict.worm_seal or "")[:32] overall = "PROVED ✅" if verdict.proof else "BLOCKED ❌" dreams = verdict.dream_cycles panel = f"""## Sovereign Gate Verdict: {overall} {_gate_table(verdict)} **WORM Seal:** `{seal_short}...` **Dream Cycles:** {dreams} **Timestamp:** {verdict.timestamp:.0f} """ return panel # ── Chat function ───────────────────────────────────────────────────────────── def chat(user_message: str, history: list, max_tokens: int, temperature: float): if not user_message.strip(): yield history, "", "No message." return hf_history = [{"role": msg["role"], "content": msg["content"]} for msg in history] response_text = "" verdict = None try: loop = asyncio.new_event_loop() response_text, verdict = loop.run_until_complete( run(user_message, hf_history, max_tokens=max_tokens, temperature=temperature) ) loop.close() except Exception as e: response_text = f"[Pipeline error: {e}]" verdict = None history = history + [ {"role": "user", "content": user_message}, {"role": "assistant", "content": response_text}, ] proof_md = _proof_panel(verdict) if verdict else "Gate run failed." yield history, "", proof_md # ── Gradio UI ───────────────────────────────────────────────────────────────── CSS = """ body { background: #0a0a0f; } .gradio-container { max-width: 1200px; font-family: 'JetBrains Mono', monospace; } #chat-col { border-right: 1px solid #1a1a2e; } .proof-panel { background: #0f0f1a; border: 1px solid #00ff88; border-radius: 8px; padding: 16px; font-size: 12px; } h1, h2, h3 { color: #00ff88; } .message.user { background: #1a1a2e !important; } .message.bot { background: #0f1a0f !important; } footer { display: none !important; } """ with gr.Blocks(css=CSS, title="SnapKitty Sovereign Chat") as demo: gr.Markdown( """# SnapKitty Sovereign Chat Harness **Zero-Hallucination Chat — If it can't prove it, it won't say it.** Every response passes ERE P1-P5 gates before reaching you. Responses that fail formal verification are **blocked and explained**, not silently returned. | Your term | What it does | |-----------|-------------| | `verify` | Prompt + response MetaSum coherence check (P1-P2) | | `curate` | Dream Cycle recovery gate (P3) | | `prove` | Joint entropy invariant (P4) | | `seal` | WORM SHA-256 receipt (P5) | """ ) with gr.Row(): with gr.Column(scale=2, elem_id="chat-col"): chatbot = gr.Chatbot( label="Sovereign Chat", height=500, type="messages", show_copy_button=True, bubble_full_width=False, ) with gr.Row(): msg_box = gr.Textbox( placeholder="Ask anything — responses are formally verified before you see them", show_label=False, scale=4, lines=2, ) send_btn = gr.Button("Send →", variant="primary", scale=1) with gr.Accordion("Parameters", open=False): max_tokens = gr.Slider(64, 1024, value=512, step=64, label="Max tokens") temperature = gr.Slider(0.0, 1.0, value=0.7, step=0.05, label="Temperature") with gr.Column(scale=1): proof_display = gr.Markdown( value="## Proof Panel\nSend a message to see gate verdicts.", label="ERE Gate Verdicts", elem_classes=["proof-panel"], ) gr.Markdown( """### Gate Legend - **P1** verify — prompt coherence - **P2** verify — response MetaSum - **P3** curate — dream cycle recovery - **P4** prove — entropy invariant ≤ 0.20 - **P5** seal — WORM receipt ✅ = gate passed ❌ = gate blocked **θ = 89/φ** phase coherence constraint maintained across all 1024 active agents.""" ) history_state = gr.State([]) def submit(msg, hist, mt, temp): for hist_out, msg_out, proof_out in chat(msg, hist, mt, temp): yield hist_out, msg_out, proof_out, hist_out send_btn.click( fn=submit, inputs=[msg_box, history_state, max_tokens, temperature], outputs=[chatbot, msg_box, proof_display, history_state], ) msg_box.submit( fn=submit, inputs=[msg_box, history_state, max_tokens, temperature], outputs=[chatbot, msg_box, proof_display, history_state], ) gr.Markdown( """--- *Built with [SnapKitty Sovereign Stack](https://huggingface.co/Snapkitty)* · ERE gates derived from quantumap formal verification · WORM receipts: SHA-256 append-only audit chain · [GitHub](https://github.com/SNAPKITTYWEST) · BSL-1.1 / AGPL-3.0 / MPL-2.0""" ) if __name__ == "__main__": demo.launch(server_name="0.0.0.0", server_port=7860, share=False)