File size: 4,197 Bytes
9fb1d2b 18ae1b4 9fb1d2b 18ae1b4 9fb1d2b 18ae1b4 9fb1d2b 18ae1b4 9fb1d2b 18ae1b4 9fb1d2b 18ae1b4 9fb1d2b 18ae1b4 9fb1d2b 18ae1b4 9fb1d2b 18ae1b4 9fb1d2b 18ae1b4 9fb1d2b 18ae1b4 9fb1d2b 18ae1b4 9fb1d2b 18ae1b4 9fb1d2b 18ae1b4 9fb1d2b | 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 | 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 "<div style='color: #64748b;'>Waiting for input...</div>"
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"<div style='color: #4ade80; font-weight: bold;'>🟢 MATCH! Mathematical proofs align.</div><div style='font-family: monospace; font-size: 12px; color: #94a3b8; margin-top: 5px;'>Hash: {orig_hash}</div>"
else:
return f"<div style='color: #f87171; font-weight: bold;'>❌ 1-bit Mismatch! Mathematical Proof Failed.</div><div style='font-family: monospace; font-size: 12px; color: #94a3b8; margin-top: 5px;'>Original: {orig_hash}<br>Tampered: {tamp_hash}</div>"
# --- GRADIO UI ---
with gr.Blocks(theme=gr.themes.Monochrome(primary_hue="cyan")) as demo:
gr.HTML("""
<div style="text-align: center; margin-bottom: 20px;">
<h1 style="color: #00d2ff; margin-bottom: 5px;">🛡️ Blockchain AI Notary</h1>
<p style="color: #94a3b8; margin-top: 0;">Zero-Auth Cryptographic Provenance on the TON Blockchain via ProofCore.</p>
</div>
""")
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="<div style='color: #64748b;'>Waiting for input...</div>")
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() |