ProofCore-Protocol commited on
Commit
18ae1b4
·
verified ·
1 Parent(s): fa2c7e3

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +20 -28
app.py CHANGED
@@ -14,73 +14,65 @@ def load_preset(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
  )
 
14
 
15
  def simulate_tampering(original_text, tampered_text):
16
  if not original_text or not tampered_text:
17
+ return "<div style='color: #64748b;'>Waiting for input...</div>"
18
 
19
+ orig_hash = hashlib.sha256(original_text.encode('utf-8')).hexdigest()
20
+ tamp_hash = hashlib.sha256(tampered_text.encode('utf-8')).hexdigest()
21
 
22
  if orig_hash == tamp_hash:
23
+ 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>"
24
  else:
25
+ 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>"
 
 
 
 
 
26
 
27
 
28
  # --- GRADIO UI ---
29
  with gr.Blocks(theme=gr.themes.Monochrome(primary_hue="cyan")) as demo:
30
  gr.HTML("""
31
  <div style="text-align: center; margin-bottom: 20px;">
32
+ <h1 style="color: #00d2ff; margin-bottom: 5px;">🛡️ Blockchain AI Notary</h1>
33
+ <p style="color: #94a3b8; margin-top: 0;">Zero-Auth Cryptographic Provenance on the TON Blockchain via ProofCore.</p>
34
  </div>
35
  """)
36
 
37
  with gr.Tabs():
38
+ # --- TAB 1: NOTARIZATION ---
39
+ with gr.Tab("1. Notarize Content (M2M)"):
40
  with gr.Row():
41
  with gr.Column(scale=1):
42
  preset_dropdown = gr.Dropdown(choices=list(PRESETS.keys()), label="⚡ 1-Click Presets")
43
+ inp = gr.Textbox(label="REPORT OR CONTENT TO SEAL", lines=8, placeholder="Type or generate something...")
44
  preset_dropdown.change(fn=load_preset, inputs=preset_dropdown, outputs=inp)
45
 
46
+ btn = gr.Button("🛡 SEAL ON TON BLOCKCHAIN", variant="primary")
47
 
48
  with gr.Column(scale=1):
49
+ # Наш компонент из PyPI
50
  out = NotarizedOutput(label="Verified Immutable Record")
 
 
 
51
 
 
52
  def passthrough(x): return x
53
 
54
  btn.click(fn=passthrough, inputs=inp, outputs=out.textbox).then(
55
  fn=out.process, inputs=out.textbox, outputs=out.outputs
56
  )
57
 
58
+ # --- TAB 2: TAMPER SIMULATOR ---
59
  with gr.Tab("2. Verify & Tamper Simulator"):
60
+ gr.Markdown("""
61
+ ### Why Blockchain? Try to cheat the system.
62
+ 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.
63
+ """)
64
 
65
  with gr.Row():
66
  with gr.Column():
67
+ orig_sim = gr.Textbox(label="Original Sealed Text (From Tab 1)", lines=8, interactive=False)
68
  with gr.Column():
69
+ tamp_sim = gr.Textbox(label="Tampered Text (Edit me!)", lines=8)
70
 
71
+ sim_result = gr.HTML(value="<div style='color: #64748b;'>Waiting for input...</div>")
72
 
73
  orig_sim.change(fn=simulate_tampering, inputs=[orig_sim, tamp_sim], outputs=sim_result)
74
  tamp_sim.change(fn=simulate_tampering, inputs=[orig_sim, tamp_sim], outputs=sim_result)
75
 
 
76
  btn.click(fn=passthrough, inputs=inp, outputs=orig_sim).then(
77
  fn=passthrough, inputs=inp, outputs=tamp_sim
78
  )