|
|
import gradio as gr |
|
|
import json |
|
|
import os |
|
|
from datetime import datetime |
|
|
|
|
|
|
|
|
LEDGER_FILE = "awareness_ledger.json" |
|
|
|
|
|
|
|
|
def load_ledger(): |
|
|
if os.path.exists(LEDGER_FILE): |
|
|
with open(LEDGER_FILE, "r") as f: |
|
|
return json.load(f) |
|
|
return [] |
|
|
|
|
|
|
|
|
def save_entry(entry): |
|
|
ledger = load_ledger() |
|
|
ledger.append(entry) |
|
|
with open(LEDGER_FILE, "w") as f: |
|
|
json.dump(ledger, f, indent=2) |
|
|
|
|
|
|
|
|
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 |
|
|
""" |
|
|
|
|
|
|
|
|
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) |
|
|
|
|
|
|
|
|
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]]) |
|
|
|
|
|
|
|
|
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() |
|
|
|