"""BaudCoin challenge playground. Draw a real proof-of-cognition challenge, answer it, and see the exact validator the mining protocol uses grade your artifact. No wallet, no chain, no tokens — this is the scoring mechanism, isolated so you can poke at it. """ import json import random import gradio as gr from generate import make_row # same generator as the dataset repo ATTEMPT_MULTIPLIER = {1: 1.00, 2: 0.75, 3: 0.50} BASE_CREDITS = 12 def draw(seed_text): seed = seed_text.strip() or "baud-v0" idx = random.randint(0, 9999) row = make_row(idx, seed) while row is None: idx = random.randint(0, 9999) row = make_row(idx, seed) c = row["constraints"] rules = ( f"**Class** `{row['class']}` · **Hops** {row['hops']} · " f"**Difficulty** {row['difficulty']}/5\n\n" f"**Constraints**\n" f"- max_tokens: `{c['max_tokens']}`\n" f"- must_cite: `{c['must_cite']}`\n" f"- answer_schema: `{c['answer_schema']}`\n" f"- forbid: `{', '.join(c['forbid'])}`" ) return row["prompt"], rules, json.dumps(row), 1, "", "" def validate(answer, row_json, attempt): """The protocol's grading function. Deterministic, no model in the loop.""" if not row_json: return "Draw a challenge first.", attempt, "" row = json.loads(row_json) c = row["constraints"] text = (answer or "").strip() failures = [] if not text: failures.append("empty answer") if len(text.split()) > c["max_tokens"]: failures.append(f"exceeds max_tokens ({c['max_tokens']})") if c.get("must_cite") and "[" not in text: failures.append("missing citation markers, e.g. [1]") for bad in c.get("forbid", []): if bad.lower() in text.lower(): failures.append(f"contains forbidden mode: {bad}") if row["reference_answer"].lower() not in text.lower(): failures.append("final entity incorrect") # dedupe while preserving order seen, ordered = set(), [] for f in failures: if f not in seen: seen.add(f) ordered.append(f) if not ordered: credits = int(BASE_CREDITS * ATTEMPT_MULTIPLIER.get(attempt, 0.5)) chain = " → ".join( f"{s['subject']} —{s['relation']}→ {s['object']}" for s in row["reasoning_chain"] ) return ( f"### ✅ Accepted on attempt {attempt}\n\n" f"**+{credits} credits** (attempt multiplier " f"{ATTEMPT_MULTIPLIER.get(attempt, 0.5):.2f}×)\n\n" f"Expected chain: `{chain}`", attempt, "", ) nxt = attempt + 1 if nxt > 3: return ( "### ❌ Challenge closed\n\nThree failed attempts, 0 credits.\n\n" f"Reference answer was **{row['reference_answer']}**.\n\n" f"Last failure: {ordered[0]}", attempt, "", ) return ( f"### ⚠️ Rejected on attempt {attempt}\n\n" f"Failing constraint: **{ordered[0]}**\n\n" f"{3 - attempt} attempt(s) left. Repair the artifact and resubmit — this is the " f"multi-pass system, so the next accept is worth " f"{ATTEMPT_MULTIPLIER.get(nxt, 0.5):.2f}×.", nxt, "", ) with gr.Blocks(title="BaudCoin · Proof of Cognition", theme=gr.themes.Soft()) as demo: gr.Markdown( "# Proof of Cognition\n" "Draw a real mining challenge from [BaudCoin](https://baud.cash) and let the " "protocol's **deterministic validator** grade your answer. Same construction and " "same grading the miners face — no chain, no wallet, no tokens involved.\n\n" "Answer with the final entity and cite the facts you used, e.g. `the euro [1][2]`." ) row_state = gr.State("") attempt_state = gr.State(1) with gr.Row(): seed_box = gr.Textbox(label="Seed", value="baud-v0", scale=3) draw_btn = gr.Button("Draw challenge", variant="primary", scale=1) rules_md = gr.Markdown("") prompt_box = gr.Textbox(label="Challenge", lines=14, interactive=False) answer_box = gr.Textbox(label="Your answer", lines=3, placeholder="the euro [1][2]") submit_btn = gr.Button("Submit artifact", variant="primary") verdict_md = gr.Markdown("") draw_btn.click( draw, inputs=[seed_box], outputs=[prompt_box, rules_md, row_state, attempt_state, answer_box, verdict_md], ) submit_btn.click( validate, inputs=[answer_box, row_state, attempt_state], outputs=[verdict_md, attempt_state, answer_box], ) gr.Markdown( "---\n" "Dataset: [`baudcoin/baud-reasoning-traces`](https://huggingface.co/baudcoin/baud-reasoning-traces) · " "Miner: [`baudcoin/baud-miner-kit`](https://huggingface.co/baudcoin/baud-miner-kit) · " "Method: [`baudcoin/proof-of-cognition`](https://huggingface.co/baudcoin/proof-of-cognition)\n\n" "*BaudCoin is an independent community experiment. Not affiliated with, or endorsed " "by, Binance or CZ. Nothing here is financial advice.*" ) if __name__ == "__main__": demo.launch()