import gradio as gr import hashlib from proofcore.gradio import NotarizedOutput # --- 1-Click Presets --- PRESETS = { "Smart Contract Audit (Solidity)": "AUDIT REPORT: Vault.sol\n\nSeverity: 0 High, 1 Low (Gas Optimization).\nNo Reentrancy or Overflow vulnerabilities detected. Code is safe for Mainnet deployment.", "LLM Benchmark Claim": "Model: Llama-3-70B-Instruct\nTask: MMLU (Massive Multitask Language Understanding)\nScore: 82.1% (Zero-shot)\nValidation Time: 14:02 UTC", "AI Medical Diagnostic": "Patient ID: #8819\nScan Type: MRI\nDiagnosis: Normal sinus rhythm. No anomalies or micro-fractures detected." } def load_preset(name): return PRESETS.get(name, "") def simulate_tampering(original_text, tampered_text): if not original_text or not tampered_text: return "
Waiting for input...
" orig_hash = hashlib.sha256(original_text.encode('utf-8')).hexdigest() tamp_hash = hashlib.sha256(tampered_text.encode('utf-8')).hexdigest() if orig_hash == tamp_hash: return f"
🟢 MATCH! Mathematical proofs align.
Hash: {orig_hash}
" else: return f"
❌ 1-bit Mismatch! Mathematical Proof Failed.
Original: {orig_hash}
Tampered: {tamp_hash}
" # --- GRADIO UI --- with gr.Blocks(theme=gr.themes.Monochrome(primary_hue="cyan")) as demo: gr.HTML("""

🛡️ Blockchain AI Notary

Zero-Auth Cryptographic Provenance on the TON Blockchain via ProofCore.

""") with gr.Tabs(): # --- TAB 1: NOTARIZATION --- with gr.Tab("1. Notarize Content (M2M)"): with gr.Row(): with gr.Column(scale=1): preset_dropdown = gr.Dropdown(choices=list(PRESETS.keys()), label="⚡ 1-Click Presets") inp = gr.Textbox(label="REPORT OR CONTENT TO SEAL", lines=8, placeholder="Type or generate something...") preset_dropdown.change(fn=load_preset, inputs=preset_dropdown, outputs=inp) btn = gr.Button("🛡 SEAL ON TON BLOCKCHAIN", variant="primary") with gr.Column(scale=1): # Наш компонент из PyPI out = NotarizedOutput(label="Verified Immutable Record") def passthrough(x): return x btn.click(fn=passthrough, inputs=inp, outputs=out.textbox).then( fn=out.process, inputs=out.textbox, outputs=out.outputs ) # --- TAB 2: TAMPER SIMULATOR --- with gr.Tab("2. Verify & Tamper Simulator"): gr.Markdown(""" ### Why Blockchain? Try to cheat the system. Change a **single letter or punctuation mark** in the sealed text below. Observe how the SHA-256 fingerprint entirely changes, proving mathematically that the text was altered. """) with gr.Row(): with gr.Column(): orig_sim = gr.Textbox(label="Original Sealed Text (From Tab 1)", lines=8, interactive=False) with gr.Column(): tamp_sim = gr.Textbox(label="Tampered Text (Edit me!)", lines=8) sim_result = gr.HTML(value="
Waiting for input...
") orig_sim.change(fn=simulate_tampering, inputs=[orig_sim, tamp_sim], outputs=sim_result) tamp_sim.change(fn=simulate_tampering, inputs=[orig_sim, tamp_sim], outputs=sim_result) btn.click(fn=passthrough, inputs=inp, outputs=orig_sim).then( fn=passthrough, inputs=inp, outputs=tamp_sim ) demo.launch()