RumleyRum commited on
Commit
87ab36f
·
verified ·
1 Parent(s): 4a2ba97

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +51 -26
app.py CHANGED
@@ -1,5 +1,5 @@
1
  # app.py — Hugging Face Gradio Space
2
- # Deterministic Governance Mechanism - Unified Interface
3
 
4
  import json
5
  import math
@@ -142,7 +142,11 @@ def run_engine(
142
  # ============================================================================
143
 
144
  class MockEmbedder:
145
- """Deterministic 2D embeddings for demo purposes."""
 
 
 
 
146
  def __init__(self):
147
  self.cache = {}
148
 
@@ -384,6 +388,7 @@ def run_llm_guardrail(substrate_text, candidates_text, show_full_trace):
384
  })
385
 
386
  # Selection rule: highest alignment (distance is recorded but not used for selection)
 
387
  if alignment > best_alignment:
388
  best_alignment = alignment
389
  best_distance = dist
@@ -498,24 +503,38 @@ def run_llm_guardrail(substrate_text, candidates_text, show_full_trace):
498
  # Gradio Interface
499
  # ============================================================================
500
 
501
- with gr.Blocks(title="Material-Field Engine GUI") as demo:
502
- gr.Markdown("# Material-Field Engine GUI")
 
 
 
 
 
 
 
 
 
 
 
 
 
503
 
504
  with gr.Tabs():
505
  # ====================================================================
506
  # TAB 1: Mechanism Demo
507
  # ====================================================================
508
- with gr.Tab("Mechanism Demo"):
509
  gr.Markdown(
510
  """
511
- ## Deterministic Governance Mechanism
512
 
513
- Visualizes stress accumulation across three phases (nucleation, quenching, crystallization).
514
- Shows how candidates fracture when stress exceeds yield threshold.
515
 
516
- **Purpose:** Understand the mechanical process behind deterministic exclusion.
 
517
 
518
- Repository: [github.com/Rymley/Deterministic-Governance-Mechanism](https://github.com/Rymley/Deterministic-Governance-Mechanism)
519
  """
520
  )
521
 
@@ -574,22 +593,24 @@ with gr.Blocks(title="Material-Field Engine GUI") as demo:
574
  # ====================================================================
575
  # TAB 2: LLM Guardrail
576
  # ====================================================================
577
- with gr.Tab("LLM Guardrail"):
578
  gr.Markdown(
579
  """
580
- ## Deterministic LLM Filter
581
 
582
- Evaluates LLM candidate outputs against verified substrate (ground truth).
583
- Same deterministic exclusion engine, applied to practical filtering.
584
 
585
- **Purpose:** See how the mechanism works for real-world LLM output verification.
 
 
 
586
  """
587
  )
588
 
589
  with gr.Row():
590
  with gr.Column():
591
  gr.Markdown("### 1. Verified Substrate")
592
- gr.Markdown("Approved facts (Ground Truth). One per line.")
593
  llm_substrate = gr.Textbox(
594
  value="The sky is blue\nWater is wet\nParis is capital of France",
595
  lines=8,
@@ -597,8 +618,8 @@ with gr.Blocks(title="Material-Field Engine GUI") as demo:
597
  )
598
 
599
  with gr.Column():
600
- gr.Markdown("### 2. LLM Candidates")
601
- gr.Markdown("Generated responses (including hallucinations). One per line.")
602
  llm_candidates = gr.Textbox(
603
  value="The sky is blue\nThe sky is green\nThe sky is made of cheese",
604
  lines=8,
@@ -611,10 +632,10 @@ with gr.Blocks(title="Material-Field Engine GUI") as demo:
611
  info="Disable for faster UI with large candidate sets"
612
  )
613
 
614
- llm_run_btn = gr.Button("Run Guardrail Filter", variant="primary")
615
 
616
  llm_out_summary = gr.Markdown(label="Result")
617
- llm_out_trace = gr.Markdown(visible=False) # Hidden for LLM tab
618
  llm_out_plot = gr.Plot(label="Material Field Projection")
619
 
620
  with gr.Accordion("Metrics JSON", open=False):
@@ -633,15 +654,19 @@ with gr.Blocks(title="Material-Field Engine GUI") as demo:
633
  """
634
  ---
635
 
636
- ### About Determinism
 
 
 
 
637
 
638
- The SHA-256 hash in the Mechanism Demo is computed from canonical JSON containing all inputs, configuration, and outputs.
639
- Identical settings produce identical hashes, proving mechanical determinism.
640
 
641
- The LLM Guardrail applies the same engine to filter AI outputs against verified facts.
642
 
643
- **Development GUI** | [Deterministic Governance Mechanism](https://github.com/Rymley/Deterministic-Governance-Mechanism)
644
  """
645
  )
646
 
647
- demo.launch()
 
1
  # app.py — Hugging Face Gradio Space
2
+ # Deterministic Governance Mechanism - Interactive Verification
3
 
4
  import json
5
  import math
 
142
  # ============================================================================
143
 
144
  class MockEmbedder:
145
+ """Deterministic 2D embeddings for demo purposes.
146
+
147
+ Note: Cache is a memoization optimization (process-local), not part of the
148
+ determinism invariant. Same text always produces same embedding via SHA-256.
149
+ """
150
  def __init__(self):
151
  self.cache = {}
152
 
 
388
  })
389
 
390
  # Selection rule: highest alignment (distance is recorded but not used for selection)
391
+ # This is a modeling choice—alignment determines substrate pairing, distance affects stress.
392
  if alignment > best_alignment:
393
  best_alignment = alignment
394
  best_distance = dist
 
503
  # Gradio Interface
504
  # ============================================================================
505
 
506
+ with gr.Blocks(title="Deterministic Governance Mechanism") as demo:
507
+ gr.Markdown(
508
+ """
509
+ # Deterministic Governance Mechanism
510
+
511
+ **Interactive verification of the core invariant:** Same inputs → Same outputs (bit-identical)
512
+
513
+ Probabilistic systems cannot be audited. If a decision changes between runs with identical inputs,
514
+ post-hoc explanation is speculation, not verification.
515
+
516
+ This interface demonstrates mechanical exclusion: decisions produced by hard thresholds, not sampling.
517
+
518
+ **Repository:** [github.com/Rymley/Deterministic-Governance-Mechanism](https://github.com/Rymley/Deterministic-Governance-Mechanism)
519
+ """
520
+ )
521
 
522
  with gr.Tabs():
523
  # ====================================================================
524
  # TAB 1: Mechanism Demo
525
  # ====================================================================
526
+ with gr.Tab("Verify Invariant"):
527
  gr.Markdown(
528
  """
529
+ ## Interactive Proof of Determinism
530
 
531
+ Adjust parameters and run the engine. The SHA-256 hash is computed from canonical JSON
532
+ containing all inputs, configuration, and outputs.
533
 
534
+ **Test the invariant:** Run with identical settings multiple times. Hash should be identical.
535
+ **Try to break it:** Change any parameter. Hash should change.
536
 
537
+ This is not a demonstration—it's a falsifiable experiment.
538
  """
539
  )
540
 
 
593
  # ====================================================================
594
  # TAB 2: LLM Guardrail
595
  # ====================================================================
596
+ with gr.Tab("Applied: LLM Filter"):
597
  gr.Markdown(
598
  """
599
+ ## Mechanical Exclusion Applied to AI Outputs
600
 
601
+ The same deterministic engine, applied to filter AI-generated candidates against verified substrate.
 
602
 
603
+ Candidates are evaluated mechanically—no probability, no sampling, just threshold comparison.
604
+ If stress exceeds yield threshold, the candidate is excluded.
605
+
606
+ **This shows:** How the invariant applies to practical AI governance.
607
  """
608
  )
609
 
610
  with gr.Row():
611
  with gr.Column():
612
  gr.Markdown("### 1. Verified Substrate")
613
+ gr.Markdown("Ground truth. One per line.")
614
  llm_substrate = gr.Textbox(
615
  value="The sky is blue\nWater is wet\nParis is capital of France",
616
  lines=8,
 
618
  )
619
 
620
  with gr.Column():
621
+ gr.Markdown("### 2. AI Candidates")
622
+ gr.Markdown("Generated outputs to filter. One per line.")
623
  llm_candidates = gr.Textbox(
624
  value="The sky is blue\nThe sky is green\nThe sky is made of cheese",
625
  lines=8,
 
632
  info="Disable for faster UI with large candidate sets"
633
  )
634
 
635
+ llm_run_btn = gr.Button("Run Filter", variant="primary")
636
 
637
  llm_out_summary = gr.Markdown(label="Result")
638
+ llm_out_trace = gr.Markdown(visible=False)
639
  llm_out_plot = gr.Plot(label="Material Field Projection")
640
 
641
  with gr.Accordion("Metrics JSON", open=False):
 
654
  """
655
  ---
656
 
657
+ ### Core Invariant
658
+
659
+ ```
660
+ Same input + same configuration + same substrate → same output (bit-identical)
661
+ ```
662
 
663
+ If two executions produce different outputs, something upstream changed.
664
+ The system makes divergence visible rather than masking it behind probability.
665
 
666
+ **Try to break the invariant.** If you do, file an issue on GitHub.
667
 
668
+ [Deterministic Governance Mechanism](https://github.com/Rymley/Deterministic-Governance-Mechanism)
669
  """
670
  )
671
 
672
+ demo.launch()