ProofCore-Protocol commited on
Commit
9fb1d2b
·
verified ·
1 Parent(s): 30ed3f6

Create app.py

Browse files
Files changed (1) hide show
  1. app.py +88 -0
app.py ADDED
@@ -0,0 +1,88 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import gradio as gr
2
+ import hashlib
3
+ from proofcore.gradio import NotarizedOutput
4
+
5
+ # --- 1-Click Presets ---
6
+ PRESETS = {
7
+ "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.",
8
+ "LLM Benchmark Claim": "Model: Llama-3-70B-Instruct\nTask: MMLU (Massive Multitask Language Understanding)\nScore: 82.1% (Zero-shot)\nValidation Time: 14:02 UTC",
9
+ "AI Medical Diagnostic": "Patient ID: #8819\nScan Type: MRI\nDiagnosis: Normal sinus rhythm. No anomalies or micro-fractures detected."
10
+ }
11
+
12
+ def load_preset(name):
13
+ return PRESETS.get(name, "")
14
+
15
+ def simulate_tampering(original_text, tampered_text):
16
+ if not original_text or not tampered_text:
17
+ return "Waiting for input..."
18
+
19
+ orig_hash = hashlib.sha256(original_text.encode()).hexdigest()
20
+ tamp_hash = hashlib.sha256(tampered_text.encode()).hexdigest()
21
+
22
+ if orig_hash == tamp_hash:
23
+ return f"🟢 MATCH! Mathematical proofs align.\nHash: {orig_hash}"
24
+ else:
25
+ return f"❌ 1-bit Mismatch! Mathematical Proof Failed.\nOriginal: {orig_hash}\nTampered: {tamp_hash}"
26
+
27
+ def generate_markdown(deal_id):
28
+ if not deal_id:
29
+ return "Notarize content first to generate badge."
30
+ return f"[![ProofCore](https://api.proofcore.org/api/badge/{deal_id})](https://proofcore.org/app/{deal_id})"
31
+
32
+
33
+ # --- GRADIO UI ---
34
+ with gr.Blocks(theme=gr.themes.Monochrome(primary_hue="cyan")) as demo:
35
+ gr.HTML("""
36
+ <div style="text-align: center; margin-bottom: 20px;">
37
+ <h1 style="color: #00d2ff;">🛡️ Blockchain AI Notary</h1>
38
+ <p style="color: #94a3b8;">Zero-Auth Cryptographic Provenance on the TON Blockchain via ProofCore.</p>
39
+ </div>
40
+ """)
41
+
42
+ with gr.Tabs():
43
+ # ТАБА 1: ГЕНЕРАЦИЯ
44
+ with gr.Tab("1. Notarize Content"):
45
+ with gr.Row():
46
+ with gr.Column(scale=1):
47
+ preset_dropdown = gr.Dropdown(choices=list(PRESETS.keys()), label="⚡ 1-Click Presets")
48
+ inp = gr.Textbox(label="AI Output / Report Content", lines=6, placeholder="Type or generate something...")
49
+ preset_dropdown.change(fn=load_preset, inputs=preset_dropdown, outputs=inp)
50
+
51
+ btn = gr.Button("Notarize on TON Blockchain", variant="primary")
52
+
53
+ with gr.Column(scale=1):
54
+ # Используем наш новенький компонент из PyPI 0.1.5!
55
+ out = NotarizedOutput(label="Verified Immutable Record")
56
+
57
+ # Перехватываем deal_id из HTML (небольшой трюк) и генерим бейдж
58
+ markdown_out = gr.Textbox(label="GitHub README Badge", interactive=False, show_copy_button=True)
59
+
60
+ # Прокидываем логику
61
+ def passthrough(x): return x
62
+
63
+ btn.click(fn=passthrough, inputs=inp, outputs=out.textbox).then(
64
+ fn=out.process, inputs=out.textbox, outputs=out.outputs
65
+ )
66
+
67
+ # ТАБА 2: СИМУЛЯТОР ПОДДЕЛКИ (Tamper Simulator)
68
+ with gr.Tab("2. Verify & Tamper Simulator"):
69
+ gr.Markdown("### Why do we need this?")
70
+ gr.Markdown("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.")
71
+
72
+ with gr.Row():
73
+ with gr.Column():
74
+ orig_sim = gr.Textbox(label="Original Sealed Text", lines=5)
75
+ with gr.Column():
76
+ tamp_sim = gr.Textbox(label="Tampered Text (Edit me)", lines=5)
77
+
78
+ sim_result = gr.Textbox(label="Cryptographic Verification Result")
79
+
80
+ orig_sim.change(fn=simulate_tampering, inputs=[orig_sim, tamp_sim], outputs=sim_result)
81
+ tamp_sim.change(fn=simulate_tampering, inputs=[orig_sim, tamp_sim], outputs=sim_result)
82
+
83
+ # При клике на кнопку в первой табе, копируем текст и во вторую для удобства
84
+ btn.click(fn=passthrough, inputs=inp, outputs=orig_sim).then(
85
+ fn=passthrough, inputs=inp, outputs=tamp_sim
86
+ )
87
+
88
+ demo.launch()