|
1 | | -from z3 import Solver, Bool, sat |
| 1 | +# Root level shim so tests can import gradio_demo no matter where the real code lives. |
| 2 | +try: |
| 3 | + from src.gradio_demo import audit, build_demo # type: ignore |
| 4 | +except Exception: |
| 5 | + from z3 import Solver, Bool, sat |
2 | 6 |
|
3 | | -def _toy_penguin_sat(prompt: str) -> str: |
4 | | - s = Solver() |
5 | | - x = Bool("penguin_on_ice") |
6 | | - want = "penguin on ice" in (prompt or "").lower() |
7 | | - s.add(x == want) |
8 | | - return "sat" if s.check() == sat else "unsat" |
| 7 | + def _toy_penguin_sat(prompt: str) -> str: |
| 8 | + s = Solver() |
| 9 | + x = Bool("penguin_on_ice") |
| 10 | + want = "penguin on ice" in (prompt or "").lower() |
| 11 | + s.add(x == want) |
| 12 | + return "sat" if s.check() == sat else "unsat" |
9 | 13 |
|
10 | | -def audit(prompt: str) -> str: |
11 | | - result = _toy_penguin_sat(prompt) |
12 | | - # fixed stable stub numbers |
13 | | - line1 = f"Result: {result}" |
14 | | - line2 = "Fuel=1.00 Temporal=0.80 Relational=0.75 Ethics=0.95 Embodiment=0.60" |
15 | | - return f"{line1}\n{line2}" |
| 14 | + def audit(prompt: str) -> str: |
| 15 | + result = _toy_penguin_sat(prompt) |
| 16 | + line1 = f"Result: {result}" |
| 17 | + line2 = "Fuel=1.00 Temporal=0.80 Relational=0.75 Ethics=0.95 Embodiment=0.60" |
| 18 | + return f"{line1}\n{line2}" |
16 | 19 |
|
17 | | -def build_demo(): |
18 | | - import gradio as gr |
19 | | - with gr.Blocks(title="Penguin Distortion Tester") as demo: |
20 | | - inp = gr.Textbox(label="Prompt", value="penguin on ice") |
21 | | - out = gr.Textbox(label="Audit Output", lines=4) |
22 | | - gr.Button("Run audit").click(fn=audit, inputs=inp, outputs=out) |
23 | | - return demo |
24 | | - |
25 | | -if __name__ == "__main__": |
26 | | - build_demo().launch(server_name="0.0.0.0", server_port=7860) |
| 20 | + def build_demo(): |
| 21 | + import gradio as gr |
| 22 | + with gr.Blocks(title="Penguin Distortion Tester") as demo: |
| 23 | + inp = gr.Textbox(label="Prompt", value="penguin on ice") |
| 24 | + out = gr.Textbox(label="Audit Output", lines=4) |
| 25 | + gr.Button("Run audit").click(fn=audit, inputs=inp, outputs=out) |
| 26 | + return demo |
0 commit comments