everydaytok commited on
Commit
ba04f93
Β·
verified Β·
1 Parent(s): 0c97638

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +22 -19
app.py CHANGED
@@ -1,6 +1,6 @@
1
  #!/usr/bin/env python3
2
  """
3
- PRACTICALITY UNIFIED SERVER 23.0 β€” STABILIZED MANIFOLD & ALGEBRAIC REDUCTION
4
  ═══════════════════════════════════════════════════════════════════
5
  ARCHITECTURE:
6
  User Text β†’ [GEMINI 3.1 ENCODER] β†’ AXLProblemDef (Strict Math Representation)
@@ -9,12 +9,12 @@ ARCHITECTURE:
9
  β†’ [ALGEBRAIC REDUCTION LOOP] if Geometry Fails
10
  β†’ [GEMINI 3.1 COLLAPSER] β†’ Domain-language explanation
11
 
12
- LATEST UPDATES (23.0):
13
- - PYTORCH STABILIZER: Added X.grad.clamp_() and tightened default fallback
14
- bounds to +/- 1000 to prevent polynomial volume explosions (CE 10^14).
 
15
  - ALGEBRAIC PRE-SOLVING: If PyTorch fails to navigate the manifold (Gate 1 fails),
16
- the system feeds back to Gemini to perform Symbolic Variable Elimination
17
- (substituting simple equalities to reduce dimensionality), acting as a smart presolver.
18
  """
19
 
20
  import os, time, random, math, threading, warnings, queue, json, textwrap
@@ -35,14 +35,13 @@ from google.genai import types
35
  # ══════════════════════════════════════════════════════════════════
36
  # AI CONFIGURATION
37
  # ══════════════════════════════════════════════════════════════════
38
- DEFAULT_GEMINI_API_KEY = os.environ.get("AI_Key", "")
39
- GEMINI_MODEL = "gemini-3-flash-preview"
40
- # "gemma-4-26b-a4b-it" #
41
 
42
  warnings.filterwarnings("ignore")
43
  USE_GPU = torch.cuda.is_available()
44
  DEVICE = torch.device("cuda" if USE_GPU else "cpu")
45
- print(f"[UNIFIED SERVER] Compute: {DEVICE.type.upper()} | System 23.0 (Algebraic Reduction)")
46
 
47
  # ══════════════════════════════════════════════════════════════════════
48
  # SECTION 1: CONSTANTS
@@ -54,8 +53,7 @@ DEDUCE_ADAM_STEPS = 25
54
  N_MPRT_EXPLORE = 1000
55
  PROJECTION_CACHE: Dict = {}
56
 
57
- # 23.0: Reduced Max Rays PER ATTEMPT so the feedback loop triggers faster
58
- MAX_RAYS_PER_ATTEMPT = 1000000 # 24576 * 10 # ~245k rays per cycle before reframing
59
  RAY_BATCH_SIZE = 24576
60
  CE_EARN_RATIO = 0.90
61
  SCOUT_CE_THRESHOLD = 0.5
@@ -526,7 +524,6 @@ def _batched_deduce_and_evaluate(
526
  if isinstance(ce,torch.Tensor) and (ce<SOLVE_THRESHOLD).all(): break
527
  loss=ce.sum(); loss.backward()
528
  with torch.no_grad():
529
- # SYSTEM 23.0 FIX: Gradient Clamping to prevent numerical explosion
530
  X.grad.clamp_(-10.0, 10.0)
531
  X.grad*=mask
532
  optimizer.step()
@@ -1244,7 +1241,7 @@ def _parse_axl_json(raw_json: str) -> AXLProblemDef:
1244
  for v in d["variables"]:
1245
  variables.append({
1246
  "name": v["name"],
1247
- # SYSTEM 23.0 FIX: Tighter fallback bounds to prevent polynomial explosions
1248
  "lo": float(v.get("lo", -1000.0)),
1249
  "hi": float(v.get("hi", 1000.0))
1250
  })
@@ -1252,7 +1249,7 @@ def _parse_axl_json(raw_json: str) -> AXLProblemDef:
1252
  return AXLProblemDef(
1253
  name=d["name"],
1254
  description=d.get("description", ""),
1255
- axioms=set(),
1256
  variables=variables,
1257
  constraints=d.get("constraints", []),
1258
  scopes=d.get("scopes", []),
@@ -1378,7 +1375,7 @@ def global_solve_task(original_problem_text: str, api_key: str):
1378
 
1379
  _add_log(f"🏁 {solved_str} (CE: {ce:.5f}) | Iso: {best_ray}")
1380
 
1381
- # ── SYSTEM 23.0 FIX: Algebraic Reduction Feedback Loop ──
1382
  if not g1_pass and attempt < MAX_ATTEMPTS:
1383
  current_text = original_problem_text + f"\n\nPREVIOUS ATTEMPT FAILED (Best CE: {ce}):\nGEOMETRIC SOLVER FAILED to converge. The constraint manifold is too highly dimensional. Please apply ALGEBRAIC REDUCTION: substitute simple equalities into the complex constraints to eliminate variables, then output the simplified AXL."
1384
  _add_log(f"⚠ Geometric Solve Failed. Triggering Algebraic Reduction...")
@@ -1417,7 +1414,7 @@ def trigger_solve(problem_text: str, api_key: str):
1417
  threading.Thread(target=global_solve_task, args=(problem_text, api_key), daemon=True).start()
1418
 
1419
  # ══════════════════════════════════════════════════════════════════
1420
- # SECTION 15: GRADIO INTERFACE
1421
  # ══════════════════════════════════════════════════════════════════
1422
 
1423
  CSS = """
@@ -1435,6 +1432,12 @@ PLACEHOLDER_HINT = textwrap.dedent("""
1435
  β€’ "A decentralized exchange liquidity pool contains three tokens: x, y, and z. x*y*z=1000. x+2y+4z=60. y=2z. Find x, y, z."
1436
  """).strip()
1437
 
 
 
 
 
 
 
1438
  def build_live_html_dashboard():
1439
  with STATE_LOCK:
1440
  phase = GLOBAL_SOLVE_STATE["phase"]
@@ -1547,11 +1550,11 @@ with gr.Blocks(css=CSS, title="Practicality Unified Server") as demo:
1547
  demo.load(fetch_ui_state, inputs=None, outputs=[live_html, answer_box])
1548
 
1549
  gr.Markdown(
1550
- "Built with Gradio Β· Practicality 23.0 Β· Stable Manifold + Algebraic Reduction",
1551
  elem_classes=["status-bar"]
1552
  )
1553
 
1554
  if __name__ == "__main__":
1555
  print(f"[UNIFIED SERVER] Compute: {DEVICE.type.upper()}")
1556
- print(f"[UNIFIED SERVER] System 23.0: Manifold Stabilizer + Algebraic Reduction Loop.")
1557
  demo.launch(server_name="0.0.0.0", server_port=7860, share=False)
 
1
  #!/usr/bin/env python3
2
  """
3
+ PRACTICALITY UNIFIED SERVER 23.1 β€” STABILIZED MANIFOLD & ALGEBRAIC REDUCTION
4
  ═══════════════════════════════════════════════════════════════════
5
  ARCHITECTURE:
6
  User Text β†’ [GEMINI 3.1 ENCODER] β†’ AXLProblemDef (Strict Math Representation)
 
9
  β†’ [ALGEBRAIC REDUCTION LOOP] if Geometry Fails
10
  β†’ [GEMINI 3.1 COLLAPSER] β†’ Domain-language explanation
11
 
12
+ LATEST UPDATES (23.1):
13
+ - UI FIX: Restored the RAY_ICONS dictionary so the live dashboard renders properly.
14
+ - PYTORCH STABILIZER: Added X.grad.clamp_() and tightened default fallback bounds
15
+ to prevent polynomial volume explosions (CE 10^14).
16
  - ALGEBRAIC PRE-SOLVING: If PyTorch fails to navigate the manifold (Gate 1 fails),
17
+ the system feeds back to Gemini to perform Symbolic Variable Elimination.
 
18
  """
19
 
20
  import os, time, random, math, threading, warnings, queue, json, textwrap
 
35
  # ══════════════════════════════════════════════════════════════════
36
  # AI CONFIGURATION
37
  # ══════════════════════════════════════════════════════════════════
38
+ DEFAULT_GEMINI_API_KEY = os.environ.get("GEMINI_API_KEY", "")
39
+ GEMINI_MODEL = "gemini-3.1-pro-preview"
 
40
 
41
  warnings.filterwarnings("ignore")
42
  USE_GPU = torch.cuda.is_available()
43
  DEVICE = torch.device("cuda" if USE_GPU else "cpu")
44
+ print(f"[UNIFIED SERVER] Compute: {DEVICE.type.upper()} | System 23.1 (Algebraic Reduction)")
45
 
46
  # ══════════════════════════════════════════════════════════════════════
47
  # SECTION 1: CONSTANTS
 
53
  N_MPRT_EXPLORE = 1000
54
  PROJECTION_CACHE: Dict = {}
55
 
56
+ MAX_RAYS_PER_ATTEMPT = 24576 * 10 # ~245k rays per cycle before reframing
 
57
  RAY_BATCH_SIZE = 24576
58
  CE_EARN_RATIO = 0.90
59
  SCOUT_CE_THRESHOLD = 0.5
 
524
  if isinstance(ce,torch.Tensor) and (ce<SOLVE_THRESHOLD).all(): break
525
  loss=ce.sum(); loss.backward()
526
  with torch.no_grad():
 
527
  X.grad.clamp_(-10.0, 10.0)
528
  X.grad*=mask
529
  optimizer.step()
 
1241
  for v in d["variables"]:
1242
  variables.append({
1243
  "name": v["name"],
1244
+ # Fallback bounds prevent PyTorch volume explosions in non-linear manifolds
1245
  "lo": float(v.get("lo", -1000.0)),
1246
  "hi": float(v.get("hi", 1000.0))
1247
  })
 
1249
  return AXLProblemDef(
1250
  name=d["name"],
1251
  description=d.get("description", ""),
1252
+ axioms=set(), # Engine owns Axioms
1253
  variables=variables,
1254
  constraints=d.get("constraints", []),
1255
  scopes=d.get("scopes", []),
 
1375
 
1376
  _add_log(f"🏁 {solved_str} (CE: {ce:.5f}) | Iso: {best_ray}")
1377
 
1378
+ # ── ALGEBRAIC REDUCTION LOOP ──
1379
  if not g1_pass and attempt < MAX_ATTEMPTS:
1380
  current_text = original_problem_text + f"\n\nPREVIOUS ATTEMPT FAILED (Best CE: {ce}):\nGEOMETRIC SOLVER FAILED to converge. The constraint manifold is too highly dimensional. Please apply ALGEBRAIC REDUCTION: substitute simple equalities into the complex constraints to eliminate variables, then output the simplified AXL."
1381
  _add_log(f"⚠ Geometric Solve Failed. Triggering Algebraic Reduction...")
 
1414
  threading.Thread(target=global_solve_task, args=(problem_text, api_key), daemon=True).start()
1415
 
1416
  # ══════════════════════════════════════════════════════════════════
1417
+ # SECTION 15: GRADIO INTERFACE (Polling Global State)
1418
  # ══════════════════════════════════════════════════════════════════
1419
 
1420
  CSS = """
 
1432
  β€’ "A decentralized exchange liquidity pool contains three tokens: x, y, and z. x*y*z=1000. x+2y+4z=60. y=2z. Find x, y, z."
1433
  """).strip()
1434
 
1435
+ RAY_ICONS = {
1436
+ "seed": "🌱", "branch": "🌿", "tension": "⚑",
1437
+ "scout": "πŸ”­", "recombine": "🧬", "invert": "πŸ”„",
1438
+ "target": "🎯", "fallback": "·"
1439
+ }
1440
+
1441
  def build_live_html_dashboard():
1442
  with STATE_LOCK:
1443
  phase = GLOBAL_SOLVE_STATE["phase"]
 
1550
  demo.load(fetch_ui_state, inputs=None, outputs=[live_html, answer_box])
1551
 
1552
  gr.Markdown(
1553
+ "Built with Gradio Β· Practicality 23.1 Β· Stable Manifold + Algebraic Reduction",
1554
  elem_classes=["status-bar"]
1555
  )
1556
 
1557
  if __name__ == "__main__":
1558
  print(f"[UNIFIED SERVER] Compute: {DEVICE.type.upper()}")
1559
+ print(f"[UNIFIED SERVER] System 23.1: Manifold Stabilizer + Algebraic Reduction Loop.")
1560
  demo.launch(server_name="0.0.0.0", server_port=7860, share=False)