RFTSystems commited on
Commit
587f077
verified
1 Parent(s): 310c19d

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +36 -63
app.py CHANGED
@@ -9,44 +9,34 @@ import os
9
  # Config
10
  # -----------------------------
11
  DOC_PATH = "The_Minimum_Conscious_Universe_RFT_Project.md"
12
- AWARENESS_THRESHOLD = 5.0 # threshold for declaring a birth event
13
- np.random.seed(0) # reproducibility
14
 
15
  # -----------------------------
16
- # Minimum Consciousness Core
17
  # -----------------------------
18
  class MCC:
19
  def __init__(self):
20
- self.b = 0.5 # bias toward rendering 1
21
- self.f = 0.5 # recency factor
22
- self.u = 0.5 # uncertainty modulation
23
-
24
- self.m = deque(maxlen=64) # short-term memory
25
- self.h = [] # full rendered bit history
26
- self.c = [] # awareness contributions
27
-
28
- self.surprises = []
29
- self.gains = []
30
- self.uncertainties = []
31
  self.events = []
32
 
33
  def step(self, t: int):
34
  p = 0.5 * self.b + 0.5 * (self.f if self.h else 0.5)
35
  r = int(np.random.rand() < p)
36
-
37
  self.m.append(r)
38
  self.h.append(r)
39
 
40
  surprise = -np.log(p if r else (1 - p))
41
  gain = 0.693 - surprise
42
-
43
- self.b += 0.05 * gain * (1 if r else -1)
44
- self.b = np.clip(self.b, 0.01, 0.99)
45
-
46
  if t > 0:
47
- self.f += 0.03 * gain * (1 if r != self.h[-2] else -1)
48
- self.f = np.clip(self.f, 0.01, 0.99)
49
-
50
  self.u = 1 / (1 + 0.15 * surprise)
51
  delta = (r - self.h[-2] if t > 0 else 0) * self.u
52
  self.c.append(delta)
@@ -65,23 +55,15 @@ class MCC:
65
  "hash": hashlib.sha256(str(self.h).encode()).hexdigest()[:32]
66
  })
67
 
68
-
69
  def plot_signals(m: MCC):
70
  fig, axs = plt.subplots(3, 1, figsize=(8, 10))
71
- axs[0].plot(m.surprises, color='orange')
72
- axs[0].set_title("Surprise signal")
73
-
74
- axs[1].plot(m.gains, color='blue')
75
- axs[1].set_title("Predictive gain")
76
-
77
- axs[2].plot(m.uncertainties, color='green')
78
- axs[2].set_title("Uncertainty modulation")
79
- axs[2].set_xlabel("steps")
80
-
81
  plt.tight_layout()
82
  return fig
83
 
84
-
85
  def make_certificate(m: MCC):
86
  if m.events:
87
  ev = m.events[0]
@@ -96,55 +78,46 @@ def make_certificate(m: MCC):
96
  )
97
  return "No irreversible awareness event detected in this run."
98
 
99
-
100
  def run_mcc(steps=2000):
101
  m = MCC()
102
  for t in range(int(steps)):
103
  m.step(t)
104
-
105
  cmin_final = round(sum(m.c), 4)
106
  fig = plot_signals(m)
107
  certificate = make_certificate(m)
108
  awake_flag = cmin_final >= AWARENESS_THRESHOLD
109
-
110
- # Return 5 values to match outputs
111
- return cmin_final, awake_flag, fig, certificate, DOC_TEXT
112
-
113
 
114
  # -----------------------------
115
- # Load project document (.md)
116
  # -----------------------------
117
  def load_doc_text(path: str) -> str:
118
  if os.path.exists(path):
119
  with open(path, "r", encoding="utf-8") as f:
120
  return f.read()
121
- return (
122
- "## Document not found\n"
123
- f"Expected to find `{path}` in the Space repository.\n\n"
124
- "Add the file and reload the Space to display the project write鈥憉p."
125
- )
126
 
127
  DOC_TEXT = load_doc_text(DOC_PATH)
128
 
129
  # -----------------------------
130
- # Gradio Interface
131
  # -----------------------------
132
- demo = gr.Interface(
133
- fn=run_mcc,
134
- inputs=gr.Slider(500, 5000, value=2000, step=100, label="Steps"),
135
- outputs=[
136
- gr.Number(label="Cmin final (awareness measure)"),
137
- gr.Checkbox(label="Awake?"),
138
- gr.Plot(label="Three signals"),
139
- gr.Textbox(label="Birth Certificate", lines=16, max_lines=28),
140
- gr.Markdown() # placeholder for DOC_TEXT
141
- ],
142
- title="馃寣 Minimum Consciousness Core",
143
- description=(
144
- "Awareness emerges from three adaptive signals: surprise, gain, and uncertainty. "
145
- "No external world 路 No reward 路 No teacher. Each run issues a ceremonial birth certificate."
146
- )
147
- )
148
 
149
  if __name__ == "__main__":
150
  demo.launch()
 
9
  # Config
10
  # -----------------------------
11
  DOC_PATH = "The_Minimum_Conscious_Universe_RFT_Project.md"
12
+ AWARENESS_THRESHOLD = 5.0
13
+ np.random.seed(0)
14
 
15
  # -----------------------------
16
+ # MCC Simulation
17
  # -----------------------------
18
  class MCC:
19
  def __init__(self):
20
+ self.b = 0.5
21
+ self.f = 0.5
22
+ self.u = 0.5
23
+ self.m = deque(maxlen=64)
24
+ self.h = []
25
+ self.c = []
26
+ self.surprises, self.gains, self.uncertainties = [], [], []
 
 
 
 
27
  self.events = []
28
 
29
  def step(self, t: int):
30
  p = 0.5 * self.b + 0.5 * (self.f if self.h else 0.5)
31
  r = int(np.random.rand() < p)
 
32
  self.m.append(r)
33
  self.h.append(r)
34
 
35
  surprise = -np.log(p if r else (1 - p))
36
  gain = 0.693 - surprise
37
+ self.b = np.clip(self.b + 0.05 * gain * (1 if r else -1), 0.01, 0.99)
 
 
 
38
  if t > 0:
39
+ self.f = np.clip(self.f + 0.03 * gain * (1 if r != self.h[-2] else -1), 0.01, 0.99)
 
 
40
  self.u = 1 / (1 + 0.15 * surprise)
41
  delta = (r - self.h[-2] if t > 0 else 0) * self.u
42
  self.c.append(delta)
 
55
  "hash": hashlib.sha256(str(self.h).encode()).hexdigest()[:32]
56
  })
57
 
 
58
  def plot_signals(m: MCC):
59
  fig, axs = plt.subplots(3, 1, figsize=(8, 10))
60
+ axs[0].plot(m.surprises, color='orange'); axs[0].set_title("Surprise")
61
+ axs[1].plot(m.gains, color='blue'); axs[1].set_title("Predictive Gain")
62
+ axs[2].plot(m.uncertainties, color='green'); axs[2].set_title("Uncertainty")
63
+ axs[2].set_xlabel("Steps")
 
 
 
 
 
 
64
  plt.tight_layout()
65
  return fig
66
 
 
67
  def make_certificate(m: MCC):
68
  if m.events:
69
  ev = m.events[0]
 
78
  )
79
  return "No irreversible awareness event detected in this run."
80
 
 
81
  def run_mcc(steps=2000):
82
  m = MCC()
83
  for t in range(int(steps)):
84
  m.step(t)
 
85
  cmin_final = round(sum(m.c), 4)
86
  fig = plot_signals(m)
87
  certificate = make_certificate(m)
88
  awake_flag = cmin_final >= AWARENESS_THRESHOLD
89
+ return cmin_final, awake_flag, fig, certificate
 
 
 
90
 
91
  # -----------------------------
92
+ # Load Document
93
  # -----------------------------
94
  def load_doc_text(path: str) -> str:
95
  if os.path.exists(path):
96
  with open(path, "r", encoding="utf-8") as f:
97
  return f.read()
98
+ return "## Document not found\nUpload the `.md` file to display the project write鈥憉p."
 
 
 
 
99
 
100
  DOC_TEXT = load_doc_text(DOC_PATH)
101
 
102
  # -----------------------------
103
+ # Gradio Blocks Layout
104
  # -----------------------------
105
+ with gr.Blocks() as demo:
106
+ gr.Markdown("# 馃寣 Minimum Consciousness Core")
107
+
108
+ with gr.Row():
109
+ steps = gr.Slider(500, 5000, value=2000, step=100, label="Steps")
110
+ run_btn = gr.Button("Run Simulation")
111
+
112
+ cmin = gr.Number(label="Cmin final (awareness measure)")
113
+ awake = gr.Checkbox(label="Awake?")
114
+ plot = gr.Plot(label="Three signals")
115
+ cert = gr.Textbox(label="Birth Certificate", lines=16, max_lines=28)
116
+
117
+ run_btn.click(run_mcc, inputs=steps, outputs=[cmin, awake, plot, cert])
118
+
119
+ with gr.Accordion("馃搫 Project Document", open=False):
120
+ gr.Markdown(DOC_TEXT)
121
 
122
  if __name__ == "__main__":
123
  demo.launch()