Skip to content

Commit 2c1ed2b

Browse files
Update gradio_demo.py
1 parent 1b4935c commit 2c1ed2b

File tree

1 file changed

+5
-28
lines changed

1 file changed

+5
-28
lines changed

gradio_demo.py

Lines changed: 5 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -1,43 +1,20 @@
11
from z3 import Solver, Bool, sat
22

3-
def _toy_penguin_sat(prompt: str) -> str:
3+
def audit(prompt: str) -> str:
44
s = Solver()
55
x = Bool("penguin_on_ice")
66
want = "penguin on ice" in (prompt or "").lower()
77
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"
3010

3111
def build_demo():
32-
import gradio as gr # import only when launching the UI
12+
import gradio as gr
3313
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.")
3614
inp = gr.Textbox(label="Prompt", value="penguin on ice")
3715
out = gr.Textbox(label="Audit Output", lines=4)
3816
gr.Button("Run audit").click(fn=audit, inputs=inp, outputs=out)
3917
return demo
4018

4119
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

Comments
 (0)