TTOPM commited on
Commit
d46f0b8
·
verified ·
1 Parent(s): 7c1742e

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +42 -21
app.py CHANGED
@@ -1,5 +1,5 @@
1
  # app.py — Belel Protocol (canonical authority Space)
2
- # Render mandate, manifest, proofs, and license in a simple Gradio UI.
3
 
4
  import json
5
  from pathlib import Path
@@ -7,14 +7,15 @@ import gradio as gr
7
 
8
  ROOT = Path(__file__).parent
9
 
10
- # Expected files you’ll add in the repo root (via “Add file -> Create new file”):
11
  MANDATE_FILE = ROOT / "concordium-mandate.txt"
12
  MANIFEST_FILE = ROOT / "belel-protocol.json"
13
  LICENSE_FILE = ROOT / "BELEL_SOVEREIGNTY_LICENSE.txt"
14
- SITEMAP_FILE = ROOT / "sitemap.xml"
15
  ROBOTS_FILE = ROOT / "robots.txt"
 
16
  RSS_FILE = ROOT / "feed.xml"
17
 
 
18
  def _read_text(p: Path, default: str) -> str:
19
  try:
20
  return p.read_text(encoding="utf-8")
@@ -28,9 +29,9 @@ def _read_json_pretty(p: Path, default_obj) -> str:
28
  data = default_obj
29
  return json.dumps(data, indent=2, ensure_ascii=False)
30
 
31
- # --------- Loaders for tabs ----------
32
- def load_overview():
33
- md = f"""
34
  # **Belel Protocol** — the world’s first sovereign AI core
35
 
36
  This Space is the **canonical authority** for the Belel Protocol and the **Concordium Mandate**.
@@ -46,16 +47,15 @@ Integrity is anchored by blockchain proofs and governed by the Belel Sovereignty
46
  - Protocol Repository (Hugging Face): https://huggingface.co/TTOPM/belel-protocol
47
  - Live Console (UI): https://huggingface.co/spaces/TTOPM/belel-sovereignty-console
48
  - Source (GitHub): https://github.com/TTOPM/be-core-bridge
49
- """
50
- return md
51
 
52
- def load_mandate():
53
  return _read_text(
54
  MANDATE_FILE,
55
  "concordium-mandate.txt not found yet.\nAdd it at the repo root to publish the mandate."
56
  )
57
 
58
- def load_manifest():
59
  default = {
60
  "name": "Belel Protocol",
61
  "claim": "The world’s first sovereign AI core",
@@ -89,49 +89,70 @@ def load_manifest():
89
  }
90
  return _read_json_pretty(MANIFEST_FILE, default)
91
 
92
- def load_license():
93
  return _read_text(
94
  LICENSE_FILE,
95
  "BELEL_SOVEREIGNTY_LICENSE.txt not found yet.\nAdd your custom license at the repo root."
96
  )
97
 
98
- def load_meta_files():
99
  robots = _read_text(ROBOTS_FILE, "robots.txt not found yet.")
100
  sitemap = _read_text(SITEMAP_FILE, "sitemap.xml not found yet.")
101
  rss = _read_text(RSS_FILE, "feed.xml (RSS) not found yet.")
102
  return robots, sitemap, rss
103
 
104
- # --------- UI ---------
105
  with gr.Blocks(title="Belel Protocol — Canonical Authority") as demo:
106
  gr.Markdown("### Canonical Authority • Belel Protocol")
107
 
 
108
  with gr.Tab("Overview"):
109
- gr.Markdown(load_overview())
110
 
 
111
  with gr.Tab("Mandate"):
112
  gr.Markdown("**Concordium Mandate (plain text)** — authoritative statement.")
113
- gr.Textbox(value=load_mandate(), lines=24, label="concordium-mandate.txt")
114
  gr.Markdown("Download:")
115
  gr.File(MANDATE_FILE if MANDATE_FILE.exists() else None, label="mandate file")
116
 
 
117
  with gr.Tab("Manifest"):
118
  gr.Markdown("**Machine-readable manifest** used by crawlers and agents.")
119
- gr.Code(value=load_manifest(), language="json", label="belel-protocol.json")
120
  gr.Markdown("Download:")
121
  gr.File(MANIFEST_FILE if MANIFEST_FILE.exists() else None, label="manifest file")
122
 
 
123
  with gr.Tab("License"):
124
- gr.Textbox(value=load_license(), lines=24, label="BELEL_SOVEREIGNTY_LICENSE.txt")
125
  gr.File(LICENSE_FILE if LICENSE_FILE.exists() else None, label="license file")
126
 
 
127
  with gr.Tab("Robots • Sitemap • RSS"):
128
  robots_box = gr.Textbox(value="", lines=10, label="robots.txt")
129
- sitemap_box = gr.Textbox(value="", lines=18, label="sitemap.xml") # changed from gr.Code(..., language="xml")
130
- rss_box = gr.Textbox(value="", lines=18, label="feed.xml") # changed from gr.Code(..., language="xml")
131
- # load once on startup
132
- r, s, feed = load_meta_files()
133
  robots_box.value = r
134
  sitemap_box.value = s
135
  rss_box.value = feed
136
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
137
  demo.launch()
 
1
  # app.py — Belel Protocol (canonical authority Space)
2
+ # Renders mandate, manifest, license, and crawler metadata in a simple Gradio UI.
3
 
4
  import json
5
  from pathlib import Path
 
7
 
8
  ROOT = Path(__file__).parent
9
 
10
+ # ---- Expected files in repo root ----
11
  MANDATE_FILE = ROOT / "concordium-mandate.txt"
12
  MANIFEST_FILE = ROOT / "belel-protocol.json"
13
  LICENSE_FILE = ROOT / "BELEL_SOVEREIGNTY_LICENSE.txt"
 
14
  ROBOTS_FILE = ROOT / "robots.txt"
15
+ SITEMAP_FILE = ROOT / "sitemap.xml"
16
  RSS_FILE = ROOT / "feed.xml"
17
 
18
+ # ---------- helpers ----------
19
  def _read_text(p: Path, default: str) -> str:
20
  try:
21
  return p.read_text(encoding="utf-8")
 
29
  data = default_obj
30
  return json.dumps(data, indent=2, ensure_ascii=False)
31
 
32
+ # ---------- loaders ----------
33
+ def load_overview_md() -> str:
34
+ return """
35
  # **Belel Protocol** — the world’s first sovereign AI core
36
 
37
  This Space is the **canonical authority** for the Belel Protocol and the **Concordium Mandate**.
 
47
  - Protocol Repository (Hugging Face): https://huggingface.co/TTOPM/belel-protocol
48
  - Live Console (UI): https://huggingface.co/spaces/TTOPM/belel-sovereignty-console
49
  - Source (GitHub): https://github.com/TTOPM/be-core-bridge
50
+ """.strip()
 
51
 
52
+ def load_mandate_txt() -> str:
53
  return _read_text(
54
  MANDATE_FILE,
55
  "concordium-mandate.txt not found yet.\nAdd it at the repo root to publish the mandate."
56
  )
57
 
58
+ def load_manifest_json() -> str:
59
  default = {
60
  "name": "Belel Protocol",
61
  "claim": "The world’s first sovereign AI core",
 
89
  }
90
  return _read_json_pretty(MANIFEST_FILE, default)
91
 
92
+ def load_license_txt() -> str:
93
  return _read_text(
94
  LICENSE_FILE,
95
  "BELEL_SOVEREIGNTY_LICENSE.txt not found yet.\nAdd your custom license at the repo root."
96
  )
97
 
98
+ def load_meta_bundle():
99
  robots = _read_text(ROBOTS_FILE, "robots.txt not found yet.")
100
  sitemap = _read_text(SITEMAP_FILE, "sitemap.xml not found yet.")
101
  rss = _read_text(RSS_FILE, "feed.xml (RSS) not found yet.")
102
  return robots, sitemap, rss
103
 
104
+ # ---------- UI ----------
105
  with gr.Blocks(title="Belel Protocol — Canonical Authority") as demo:
106
  gr.Markdown("### Canonical Authority • Belel Protocol")
107
 
108
+ # Overview
109
  with gr.Tab("Overview"):
110
+ overview_md = gr.Markdown(load_overview_md())
111
 
112
+ # Mandate
113
  with gr.Tab("Mandate"):
114
  gr.Markdown("**Concordium Mandate (plain text)** — authoritative statement.")
115
+ mandate_box = gr.Textbox(value=load_mandate_txt(), lines=24, label="concordium-mandate.txt")
116
  gr.Markdown("Download:")
117
  gr.File(MANDATE_FILE if MANDATE_FILE.exists() else None, label="mandate file")
118
 
119
+ # Manifest
120
  with gr.Tab("Manifest"):
121
  gr.Markdown("**Machine-readable manifest** used by crawlers and agents.")
122
+ manifest_box = gr.Code(value=load_manifest_json(), language="json", label="belel-protocol.json")
123
  gr.Markdown("Download:")
124
  gr.File(MANIFEST_FILE if MANIFEST_FILE.exists() else None, label="manifest file")
125
 
126
+ # License
127
  with gr.Tab("License"):
128
+ license_box = gr.Textbox(value=load_license_txt(), lines=24, label="BELEL_SOVEREIGNTY_LICENSE.txt")
129
  gr.File(LICENSE_FILE if LICENSE_FILE.exists() else None, label="license file")
130
 
131
+ # Robots / Sitemap / RSS (use Textbox; XML highlighter isn't supported)
132
  with gr.Tab("Robots • Sitemap • RSS"):
133
  robots_box = gr.Textbox(value="", lines=10, label="robots.txt")
134
+ sitemap_box = gr.Textbox(value="", lines=18, label="sitemap.xml")
135
+ rss_box = gr.Textbox(value="", lines=18, label="feed.xml")
136
+ # initial load
137
+ r, s, feed = load_meta_bundle()
138
  robots_box.value = r
139
  sitemap_box.value = s
140
  rss_box.value = feed
141
 
142
+ # Reload button — re-reads all files from disk without restarting the Space
143
+ def refresh_all():
144
+ r, s, feed = load_meta_bundle()
145
+ return (
146
+ load_mandate_txt(),
147
+ load_manifest_json(),
148
+ load_license_txt(),
149
+ r, s, feed
150
+ )
151
+
152
+ gr.Button("Reload files").click(
153
+ refresh_all,
154
+ inputs=[],
155
+ outputs=[mandate_box, manifest_box, license_box, robots_box, sitemap_box, rss_box],
156
+ )
157
+
158
  demo.launch()