Skip to content

Commit 5a95094

Browse files
Update gradio_demo.py
1 parent b3c6bcf commit 5a95094

File tree

1 file changed

+32
-0
lines changed

1 file changed

+32
-0
lines changed

gradio_demo.py

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,38 @@ def audit(prompt: str) -> str:
1616
line1 = f"Result: {result}"
1717
line2 = "Fuel=1.00 Temporal=0.80 Relational=0.75 Ethics=0.95 Embodiment=0.60"
1818
return f"{line1}\n{line2}"
19+
def _parse_thresholds(spec: str) -> dict:
20+
"""
21+
Parse a simple thresholds string like 'Fuel:0.8,Temporal:0.7'.
22+
Liberal parsing: ignores bad entries.
23+
"""
24+
out = {}
25+
if not spec:
26+
return out
27+
for part in spec.split(","):
28+
if ":" not in part:
29+
continue
30+
k, v = part.split(":", 1)
31+
try:
32+
out[k.strip().lower()] = float(v)
33+
except Exception:
34+
pass
35+
return out
36+
37+
def make_checker(args, base_config) -> callable:
38+
"""
39+
Minimal public-safe checker factory used by tests.
40+
Returns a function(prompt) -> str.
41+
If args.summary is True, return only the first line of audit().
42+
Otherwise return the full audit text.
43+
"""
44+
_ = _parse_thresholds(getattr(args, "ckmm_thresholds", "")) # parsed but unused in stub
45+
46+
def _fn(prompt: str) -> str:
47+
out = audit(prompt)
48+
return out.splitlines()[0] if getattr(args, "summary", False) else out
49+
50+
return _fn
1951

2052
def build_demo():
2153
import gradio as gr

0 commit comments

Comments
 (0)