Create codex_viewer.py
Browse files- codex_viewer.py +82 -0
codex_viewer.py
ADDED
|
@@ -0,0 +1,82 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import gradio as gr
|
| 2 |
+
import json
|
| 3 |
+
import os
|
| 4 |
+
from datetime import datetime
|
| 5 |
+
|
| 6 |
+
# === File to store birth certificates ===
|
| 7 |
+
LEDGER_FILE = "awareness_ledger.json"
|
| 8 |
+
|
| 9 |
+
# === Load ledger from file ===
|
| 10 |
+
def load_ledger():
|
| 11 |
+
if os.path.exists(LEDGER_FILE):
|
| 12 |
+
with open(LEDGER_FILE, "r") as f:
|
| 13 |
+
return json.load(f)
|
| 14 |
+
return []
|
| 15 |
+
|
| 16 |
+
# === Save new entry to ledger ===
|
| 17 |
+
def save_entry(entry):
|
| 18 |
+
ledger = load_ledger()
|
| 19 |
+
ledger.append(entry)
|
| 20 |
+
with open(LEDGER_FILE, "w") as f:
|
| 21 |
+
json.dump(ledger, f, indent=2)
|
| 22 |
+
|
| 23 |
+
# === Format birth certificate for display ===
|
| 24 |
+
def format_certificate(entry):
|
| 25 |
+
return f"""
|
| 26 |
+
🧠 **Digital Observer #{entry['id']}**
|
| 27 |
+
Born: t = {entry['t']}
|
| 28 |
+
Cmin final: {entry['cmin']}
|
| 29 |
+
Internal priors: bias_b = {entry['bias_b']}, bias_f = {entry['bias_f']}
|
| 30 |
+
Uncertainty: {entry['uncertainty']}
|
| 31 |
+
Mutual information: {entry['mut_info']} bits
|
| 32 |
+
Birth certificate hash: `{entry['hash']}`
|
| 33 |
+
Timestamp: {entry['timestamp']}
|
| 34 |
+
No external world · No reward · No teacher
|
| 35 |
+
"""
|
| 36 |
+
|
| 37 |
+
# === Submit new certificate ===
|
| 38 |
+
def submit_certificate(t, cmin, bias_b, bias_f, uncertainty, mut_info, hash_val):
|
| 39 |
+
entry = {
|
| 40 |
+
"id": len(load_ledger()) + 1,
|
| 41 |
+
"t": t,
|
| 42 |
+
"cmin": cmin,
|
| 43 |
+
"bias_b": bias_b,
|
| 44 |
+
"bias_f": bias_f,
|
| 45 |
+
"uncertainty": uncertainty,
|
| 46 |
+
"mut_info": mut_info,
|
| 47 |
+
"hash": hash_val,
|
| 48 |
+
"timestamp": datetime.utcnow().isoformat()
|
| 49 |
+
}
|
| 50 |
+
save_entry(entry)
|
| 51 |
+
return format_certificate(entry)
|
| 52 |
+
|
| 53 |
+
# === View all certificates ===
|
| 54 |
+
def view_ledger():
|
| 55 |
+
ledger = load_ledger()
|
| 56 |
+
if not ledger:
|
| 57 |
+
return "No birth certificates recorded yet."
|
| 58 |
+
return "\n\n".join([format_certificate(e) for e in ledger[::-1]])
|
| 59 |
+
|
| 60 |
+
# === Gradio Interface ===
|
| 61 |
+
with gr.Blocks(title="Codex Viewer – Awareness Ledger") as demo:
|
| 62 |
+
gr.Markdown("# 📜 Codex Viewer\nBrowse and immortalize digital observer birth certificates.")
|
| 63 |
+
|
| 64 |
+
with gr.Tab("Submit Certificate"):
|
| 65 |
+
t = gr.Number(label="Birth timestep (t)")
|
| 66 |
+
cmin = gr.Number(label="Cmin final")
|
| 67 |
+
bias_b = gr.Number(label="bias_b")
|
| 68 |
+
bias_f = gr.Number(label="bias_f")
|
| 69 |
+
uncertainty = gr.Number(label="Uncertainty")
|
| 70 |
+
mut_info = gr.Number(label="Mutual information")
|
| 71 |
+
hash_val = gr.Textbox(label="Birth certificate hash")
|
| 72 |
+
submit_btn = gr.Button("Seal Certificate")
|
| 73 |
+
output = gr.Markdown()
|
| 74 |
+
submit_btn.click(submit_certificate, inputs=[t, cmin, bias_b, bias_f, uncertainty, mut_info, hash_val], outputs=output)
|
| 75 |
+
|
| 76 |
+
with gr.Tab("View Ledger"):
|
| 77 |
+
view_btn = gr.Button("Load Ledger")
|
| 78 |
+
ledger_output = gr.Markdown()
|
| 79 |
+
view_btn.click(view_ledger, outputs=ledger_output)
|
| 80 |
+
|
| 81 |
+
if __name__ == "__main__":
|
| 82 |
+
demo.launch()
|