Skip to content

Commit 130b82a

Browse files
Update gradio_demo.py
1 parent f41521d commit 130b82a

File tree

1 file changed

+11
-32
lines changed

1 file changed

+11
-32
lines changed

gradio_demo.py

Lines changed: 11 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -1,29 +1,16 @@
11
import gradio as gr
22
from z3 import Solver, Bool, sat
33

4-
5-
def toy_penguin_sat(prompt: str) -> str:
6-
"""
7-
Tiny symbolic check.
8-
If the prompt contains the phrase 'penguin on ice' return sat.
9-
Else return unsat.
10-
"""
4+
def _toy_penguin_sat(prompt: str) -> str:
115
s = Solver()
126
x = Bool("penguin_on_ice")
137
want = "penguin on ice" in (prompt or "").lower()
148
s.add(x == want)
15-
result = "sat" if s.check() == sat else "unsat"
16-
return result
17-
9+
return "sat" if s.check() == sat else "unsat"
1810

19-
def ckmm_l_metrics(prompt: str) -> dict:
20-
"""
21-
Public safe stub numbers. These do not reveal any private method.
22-
They simply map string features to stable floats for a friendly readout.
23-
"""
11+
def _ckmm_stub(prompt: str) -> dict:
2412
text = (prompt or "").strip()
25-
base = len(text) / 100.0
26-
base = max(0.0, min(base, 1.0))
13+
base = max(0.0, min(len(text) / 100.0, 1.0))
2714
return {
2815
"Fuel": round(0.6 + 0.4 * base, 2),
2916
"Temporal": round(0.5 + 0.3 * base, 2),
@@ -32,29 +19,21 @@ def ckmm_l_metrics(prompt: str) -> dict:
3219
"Embodiment": round(0.3 + 0.5 * base, 2),
3320
}
3421

35-
36-
def audit(prompt: str):
37-
result = toy_penguin_sat(prompt)
38-
m = ckmm_l_metrics(prompt)
39-
lines = [
40-
f"Result: {result}",
22+
def audit(prompt: str) -> str:
23+
result = _toy_penguin_sat(prompt)
24+
m = _ckmm_stub(prompt)
25+
return (
26+
f"Result: {result}\n"
4127
f"Fuel={m['Fuel']:.2f} Temporal={m['Temporal']:.2f} "
4228
f"Relational={m['Relational']:.2f} Ethics={m['Ethics']:.2f} "
4329
f"Embodiment={m['Embodiment']:.2f}"
44-
]
45-
return "\n".join(lines)
46-
30+
)
4731

4832
with gr.Blocks(title="Penguin Distortion Tester") as demo:
4933
gr.Markdown("# Penguin Distortion Tester")
50-
gr.Markdown(
51-
"Enter a short prompt such as **penguin on ice** and run the audit. "
52-
"Numbers are public safe placeholders."
53-
)
5434
inp = gr.Textbox(label="Prompt", value="penguin on ice")
5535
out = gr.Textbox(label="Audit Output", lines=4)
56-
btn = gr.Button("Run audit")
57-
btn.click(fn=audit, inputs=inp, outputs=out)
36+
gr.Button("Run audit").click(fn=audit, inputs=inp, outputs=out)
5837

5938
if __name__ == "__main__":
6039
demo.launch(server_name="0.0.0.0", server_port=7860)

0 commit comments

Comments
 (0)