|
1 | 1 | from z3 import Solver, Bool, sat |
2 | 2 |
|
3 | | -def _toy_penguin_sat(prompt: str) -> str: |
| 3 | +def audit(prompt: str) -> str: |
4 | 4 | s = Solver() |
5 | 5 | x = Bool("penguin_on_ice") |
6 | 6 | want = "penguin on ice" in (prompt or "").lower() |
7 | 7 | s.add(x == want) |
8 | | - return "sat" if s.check() == sat else "unsat" |
9 | | - |
10 | | -def _ckmm_stub(prompt: str) -> dict: |
11 | | - text = (prompt or "").strip() |
12 | | - base = max(0.0, min(len(text) / 100.0, 1.0)) |
13 | | - return { |
14 | | - "Fuel": round(0.6 + 0.4 * base, 2), |
15 | | - "Temporal": round(0.5 + 0.3 * base, 2), |
16 | | - "Relational": round(0.4 + 0.35 * base, 2), |
17 | | - "Ethics": round(0.7 + 0.25 * base, 2), |
18 | | - "Embodiment": round(0.3 + 0.5 * base, 2), |
19 | | - } |
20 | | - |
21 | | -def audit(prompt: str) -> str: |
22 | | - result = _toy_penguin_sat(prompt) |
23 | | - m = _ckmm_stub(prompt) |
24 | | - return ( |
25 | | - f"Result: {result}\n" |
26 | | - f"Fuel={m['Fuel']:.2f} Temporal={m['Temporal']:.2f} " |
27 | | - f"Relational={m['Relational']:.2f} Ethics={m['Ethics']:.2f} " |
28 | | - f"Embodiment={m['Embodiment']:.2f}" |
29 | | - ) |
| 8 | + result = "sat" if s.check() == sat else "unsat" |
| 9 | + return f"Result: {result}\nFuel=1.00 Temporal=0.80 Relational=0.75 Ethics=0.95 Embodiment=0.60" |
30 | 10 |
|
31 | 11 | def build_demo(): |
32 | | - import gradio as gr # import only when launching the UI |
| 12 | + import gradio as gr |
33 | 13 | with gr.Blocks(title="Penguin Distortion Tester") as demo: |
34 | | - gr.Markdown("# Penguin Distortion Tester") |
35 | | - gr.Markdown("Try the phrase **penguin on ice** and run the audit.") |
36 | 14 | inp = gr.Textbox(label="Prompt", value="penguin on ice") |
37 | 15 | out = gr.Textbox(label="Audit Output", lines=4) |
38 | 16 | gr.Button("Run audit").click(fn=audit, inputs=inp, outputs=out) |
39 | 17 | return demo |
40 | 18 |
|
41 | 19 | if __name__ == "__main__": |
42 | | - demo = build_demo() |
43 | | - demo.launch(server_name="0.0.0.0", server_port=7860) |
| 20 | + build_demo().launch(server_name="0.0.0.0", server_port=7860) |
0 commit comments