Download app.py from ProofCore-Protocol/Blockchain-AI-Notary: direct link, hf CLI and curl.
- Browser
- Download file 4.2 kB
-
https://huggingface.co/spaces/ProofCore-Protocol/Blockchain-AI-Notary/resolve/main/app.py
- Command line
-
hf download hf://spaces/ProofCore-Protocol/Blockchain-AI-Notary/app.py
-
curl -L -o app.py https://huggingface.co/spaces/ProofCore-Protocol/Blockchain-AI-Notary/resolve/main/app.py
4.2 kB
| 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() |