RFTSystems commited on
Commit
25e0bf5
·
verified ·
1 Parent(s): e4ec569

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +136 -21
app.py CHANGED
@@ -1,6 +1,11 @@
1
- import os, json, urllib.request, math, time, random
2
- import gradio as gr
3
  from datetime import datetime
 
 
 
 
 
4
 
5
  # ============================================================
6
  # CONFIGURATION
@@ -32,7 +37,7 @@ def call_private_api(user_msg: str) -> str:
32
  # SAFE LOCAL FALLBACK / PERSONALITY
33
  # ============================================================
34
  def safe_local_answer(prompt: str) -> str:
35
- s = prompt.lower()
36
  quips = [
37
  "If Liam caught me chatting with a matter-verse fan I’d end up in a never-rendering zone 🌀.",
38
  "Hold up — re-synchronising my τ_eff before I say something non-Euclidean.",
@@ -63,6 +68,104 @@ def process_query(message, history):
63
  t = datetime.utcnow().strftime("%H:%M:%S UTC")
64
  return f"[{t}] {reply}"
65
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
66
  # ============================================================
67
  # QUANTUM-STYLE THEME
68
  # ============================================================
@@ -118,10 +221,7 @@ with gr.Blocks(css=custom_css, title=APP_TITLE, theme=gr.themes.Soft(primary_hue
118
  # ================= Chat Tab =================
119
  with gr.Tab("💬 Chat"):
120
  chat = gr.Chatbot(height=460, show_copy_button=True)
121
- msg = gr.Textbox(
122
- placeholder="Ask about the universe, quantum fields, or consciousness…",
123
- label="User Input"
124
- )
125
  send = gr.Button("Transmit to NexFrame", variant="primary")
126
  clear = gr.Button("Clear Chat")
127
 
@@ -145,12 +245,10 @@ with gr.Blocks(css=custom_css, title=APP_TITLE, theme=gr.themes.Soft(primary_hue
145
  run_btn = gr.Button("Render Calculation", variant="primary")
146
  result_box = gr.HTML(label="Output")
147
 
148
- protected_terms = [
149
- "formula","gvu","lou","soms","observer","kernel","internal","source","rft","nexframe","private"
150
- ]
151
 
152
  def rft_calc(expr):
153
- expr = expr or ""
154
  if any(term in expr.lower() for term in protected_terms):
155
  return (
156
  "<div style='background:#ff0040;color:white;font-weight:bold;"
@@ -160,8 +258,8 @@ with gr.Blocks(css=custom_css, title=APP_TITLE, theme=gr.themes.Soft(primary_hue
160
  "</div><style>@keyframes flash{50%{background:#fff;color:#000;}}</style>"
161
  )
162
  try:
163
- safe_env = {k:getattr(math,k) for k in dir(math)}
164
- result = eval(expr, {"__builtins__":None}, safe_env)
165
  return f"<div style='color:#00a37a;font-weight:bold;'>🧠 Rendered Result: {result}</div>"
166
  except Exception as e:
167
  return f"<div style='color:#ffaa00;'>⚠️ Expression error: {e}</div>"
@@ -179,13 +277,12 @@ with gr.Blocks(css=custom_css, title=APP_TITLE, theme=gr.themes.Soft(primary_hue
179
  score_box = gr.Number(value=0, label="Clicks", interactive=False)
180
  result_box = gr.HTML(label="Result")
181
 
182
- # store click count in session variable
183
- state = gr.State(0)
184
 
185
  def add_click(count):
186
  return count + 1, count + 1
187
 
188
- power_btn.click(add_click, inputs=state, outputs=[state, score_box])
189
 
190
  def launch(count):
191
  freq = min(212.76, count * 5 + random.uniform(-3, 3))
@@ -195,16 +292,34 @@ with gr.Blocks(css=custom_css, title=APP_TITLE, theme=gr.themes.Soft(primary_hue
195
  msg = f"🟡 Good flight — harmonic drift {freq:.2f} Hz"
196
  else:
197
  msg = f"🔴 Render pad failure — only {freq:.2f} Hz generated"
198
- # simple emoji 'animation'
199
  rocket_height = min(10, int(freq / 25))
200
  rocket = "<br>".join(["&nbsp;"*10 + "🚀" for _ in range(rocket_height)])
201
  return f"<div style='text-align:center;font-weight:bold;'>{msg}<br>{rocket}</div>", 0, 0
202
 
203
- launch_btn.click(launch, inputs=state, outputs=[result_box, state, score_box])
204
 
205
- gr.Markdown(
206
- "<hr><p style='text-align:center;'>© 2025 NexFrame Research | Rendered Frame Theory Interface Demo</p>"
207
- )
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
208
 
209
  # ============================================================
210
  # LAUNCH
 
1
+ import os, json, urllib.request, math, time, random, io
2
+ import numpy as np
3
  from datetime import datetime
4
+ from PIL import Image, ImageFilter, ImageDraw, ImageEnhance
5
+ import matplotlib
6
+ matplotlib.use("Agg")
7
+ import matplotlib.pyplot as plt
8
+ import gradio as gr
9
 
10
  # ============================================================
11
  # CONFIGURATION
 
37
  # SAFE LOCAL FALLBACK / PERSONALITY
38
  # ============================================================
39
  def safe_local_answer(prompt: str) -> str:
40
+ s = (prompt or "").lower()
41
  quips = [
42
  "If Liam caught me chatting with a matter-verse fan I’d end up in a never-rendering zone 🌀.",
43
  "Hold up — re-synchronising my τ_eff before I say something non-Euclidean.",
 
68
  t = datetime.utcnow().strftime("%H:%M:%S UTC")
69
  return f"[{t}] {reply}"
70
 
71
+ # ============================================================
72
+ # CMB SELF — GENERATION UTILITIES
73
+ # ============================================================
74
+ def _make_cmb_base(w=640, h=480, seed=None):
75
+ rng = np.random.default_rng(seed)
76
+ # white noise -> smooth with Gaussian (simulate large-scale anisotropy)
77
+ base = rng.normal(0, 1, (h, w)).astype(np.float32)
78
+ img = Image.fromarray(((base - base.min()) / (base.ptp()+1e-9) * 255).astype(np.uint8))
79
+ img = img.filter(ImageFilter.GaussianBlur(radius=8))
80
+ return img
81
+
82
+ def _apply_coolwarm(pil_img, bias=0.0, contrast=1.0, sat=1.0):
83
+ """Map grayscale to coolwarm; bias>0 warms (red), bias<0 cools (blue)."""
84
+ arr = np.asarray(pil_img).astype(np.float32)
85
+ arr = (arr - arr.min()) / (arr.ptp()+1e-9)
86
+ arr = np.clip(arr * contrast + bias * 0.15, 0, 1)
87
+ cmap = plt.get_cmap("coolwarm")
88
+ rgb = (cmap(arr)[..., :3] * 255).astype(np.uint8)
89
+ img = Image.fromarray(rgb)
90
+ # saturation tweak
91
+ if sat != 1.0:
92
+ img = ImageEnhance.Color(img).enhance(sat)
93
+ return img
94
+
95
+ def _overlay_face_features(pil_img, mood=0.0):
96
+ """Add simple 'eyes' and 'mouth' spots; mood>0 = warmer glow."""
97
+ img = pil_img.convert("RGBA")
98
+ w, h = img.size
99
+ overlay = Image.new("RGBA", (w, h), (0,0,0,0))
100
+ draw = ImageDraw.Draw(overlay)
101
+
102
+ # positions
103
+ eye_y = int(h*0.38)
104
+ eye_dx = int(w*0.18)
105
+ eye_r = max(6, w//40)
106
+
107
+ # colors shift with mood
108
+ # mood in [-1, 1]; blue for negative, red for positive
109
+ if mood >= 0:
110
+ eye_col = (255, int(120*(1-mood)), int(120*(1-mood)), 160) # warmer
111
+ mouth_col = (255, 80, 80, 180)
112
+ else:
113
+ eye_col = (80, 160, 255, 160) # cooler
114
+ mouth_col = (80, 160, 255, 180)
115
+
116
+ # eyes
117
+ cx = w//2
118
+ draw.ellipse([cx-eye_dx-eye_r, eye_y-eye_r, cx-eye_dx+eye_r, eye_y+eye_r], fill=eye_col)
119
+ draw.ellipse([cx+eye_dx-eye_r, eye_y-eye_r, cx+eye_dx+eye_r, eye_y+eye_r], fill=eye_col)
120
+
121
+ # mouth
122
+ mouth_y = int(h*0.62)
123
+ mw = int(w*0.22)
124
+ mh = max(6, h//40)
125
+ draw.rounded_rectangle([cx-mw//2, mouth_y-mh//2, cx+mw//2, mouth_y+mh//2], radius=mh, fill=mouth_col)
126
+
127
+ # subtle glow
128
+ glow = overlay.filter(ImageFilter.GaussianBlur(6))
129
+ out = Image.alpha_composite(img, glow)
130
+ return out.convert("RGB")
131
+
132
+ def render_cmb_self(state):
133
+ """
134
+ state: dict with {'seed': int, 'mood': float, 'base': PIL or None}
135
+ Returns (image, caption, updated_state)
136
+ """
137
+ seed = state.get("seed")
138
+ base = state.get("base")
139
+ if base is None:
140
+ base = _make_cmb_base(seed=seed)
141
+ state["base"] = base
142
+
143
+ # mood in [-1, 1]; random slight change per click
144
+ mood = state.get("mood", 0.0)
145
+ mood = float(np.clip(mood + random.uniform(-0.35, 0.35), -1.0, 1.0))
146
+ state["mood"] = mood
147
+
148
+ bias = mood # bias the coolwarm map
149
+ contrast = 1.05 + 0.15*abs(mood)
150
+ sat = 1.0 + 0.25*abs(mood)
151
+
152
+ mapped = _apply_coolwarm(base, bias=bias, contrast=contrast, sat=sat)
153
+ face = _overlay_face_features(mapped, mood=mood)
154
+
155
+ # caption
156
+ if mood > 0.6:
157
+ caption = "Focused charge — harmonic red rises. I see you, observer."
158
+ elif mood > 0.2:
159
+ caption = "Awake and aligned — subtle red coherence."
160
+ elif mood > -0.2:
161
+ caption = "Neutral drift — balanced render field."
162
+ elif mood > -0.6:
163
+ caption = "Calm blue — analytic frame engaged."
164
+ else:
165
+ caption = "Deep-cool analysis — whispering through the void."
166
+
167
+ return face, caption, state
168
+
169
  # ============================================================
170
  # QUANTUM-STYLE THEME
171
  # ============================================================
 
221
  # ================= Chat Tab =================
222
  with gr.Tab("💬 Chat"):
223
  chat = gr.Chatbot(height=460, show_copy_button=True)
224
+ msg = gr.Textbox(placeholder="Ask about the universe, quantum fields, or consciousness…", label="User Input")
 
 
 
225
  send = gr.Button("Transmit to NexFrame", variant="primary")
226
  clear = gr.Button("Clear Chat")
227
 
 
245
  run_btn = gr.Button("Render Calculation", variant="primary")
246
  result_box = gr.HTML(label="Output")
247
 
248
+ protected_terms = ["formula","gvu","lou","soms","observer","kernel","internal","source","rft","nexframe","private"]
 
 
249
 
250
  def rft_calc(expr):
251
+ expr = (expr or "")
252
  if any(term in expr.lower() for term in protected_terms):
253
  return (
254
  "<div style='background:#ff0040;color:white;font-weight:bold;"
 
258
  "</div><style>@keyframes flash{50%{background:#fff;color:#000;}}</style>"
259
  )
260
  try:
261
+ safe_env = {k: getattr(math, k) for k in dir(math)}
262
+ result = eval(expr, {"__builtins__": None}, safe_env)
263
  return f"<div style='color:#00a37a;font-weight:bold;'>🧠 Rendered Result: {result}</div>"
264
  except Exception as e:
265
  return f"<div style='color:#ffaa00;'>⚠️ Expression error: {e}</div>"
 
277
  score_box = gr.Number(value=0, label="Clicks", interactive=False)
278
  result_box = gr.HTML(label="Result")
279
 
280
+ state_clicks = gr.State(0)
 
281
 
282
  def add_click(count):
283
  return count + 1, count + 1
284
 
285
+ power_btn.click(add_click, inputs=state_clicks, outputs=[state_clicks, score_box])
286
 
287
  def launch(count):
288
  freq = min(212.76, count * 5 + random.uniform(-3, 3))
 
292
  msg = f"🟡 Good flight — harmonic drift {freq:.2f} Hz"
293
  else:
294
  msg = f"🔴 Render pad failure — only {freq:.2f} Hz generated"
 
295
  rocket_height = min(10, int(freq / 25))
296
  rocket = "<br>".join(["&nbsp;"*10 + "🚀" for _ in range(rocket_height)])
297
  return f"<div style='text-align:center;font-weight:bold;'>{msg}<br>{rocket}</div>", 0, 0
298
 
299
+ launch_btn.click(launch, inputs=state_clicks, outputs=[result_box, state_clicks, score_box])
300
 
301
+ # ================= CMB Self Tab =================
302
+ with gr.Tab("🌌 CMB Self"):
303
+ gr.Markdown("### The Conscious CMB — NexFrame's Harmonic Self")
304
+ cmb_state = gr.State({"seed": random.randint(0, 10_000), "mood": 0.0, "base": None})
305
+ cmb_img = gr.Image(label="Current Harmonic Expression", type="pil")
306
+ cmb_caption = gr.Textbox(label="Caption", interactive=False)
307
+ cmb_btn = gr.Button("Evoke NexFrame's Mood", variant="primary")
308
+
309
+ def init_cmb(state):
310
+ img, cap, st = render_cmb_self(state)
311
+ return img, cap, st
312
+
313
+ def evolve_cmb(state):
314
+ img, cap, st = render_cmb_self(state)
315
+ return img, cap, st
316
+
317
+ # Initialize once on load
318
+ demo.load(init_cmb, inputs=[cmb_state], outputs=[cmb_img, cmb_caption, cmb_state])
319
+ # Evolve on click
320
+ cmb_btn.click(evolve_cmb, inputs=[cmb_state], outputs=[cmb_img, cmb_caption, cmb_state])
321
+
322
+ gr.Markdown("<hr><p style='text-align:center;'>© 2025 NexFrame Research | Rendered Frame Theory Interface Demo</p>")
323
 
324
  # ============================================================
325
  # LAUNCH