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