Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
|
@@ -1,6 +1,6 @@
|
|
| 1 |
# app.py — Belel Protocol (canonical authority Space)
|
| 2 |
# Renders mandate, manifest, license, and crawler metadata in a simple Gradio UI.
|
| 3 |
-
#
|
| 4 |
|
| 5 |
import json
|
| 6 |
from pathlib import Path
|
|
@@ -8,39 +8,59 @@ import gradio as gr
|
|
| 8 |
|
| 9 |
ROOT = Path(__file__).parent
|
| 10 |
|
| 11 |
-
# ----
|
| 12 |
-
|
| 13 |
-
|
| 14 |
-
|
| 15 |
-
|
| 16 |
-
|
| 17 |
-
|
| 18 |
-
|
| 19 |
-
|
| 20 |
-
|
| 21 |
-
|
| 22 |
-
|
| 23 |
-
|
| 24 |
-
|
| 25 |
-
|
| 26 |
-
|
| 27 |
-
|
| 28 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 29 |
return None
|
| 30 |
|
| 31 |
-
|
| 32 |
-
|
| 33 |
-
|
| 34 |
-
if p is None:
|
| 35 |
return default
|
| 36 |
try:
|
| 37 |
return p.read_text(encoding="utf-8")
|
| 38 |
except Exception:
|
| 39 |
return default
|
| 40 |
|
| 41 |
-
def
|
| 42 |
-
p = find_file(
|
| 43 |
-
if
|
| 44 |
data = default_obj
|
| 45 |
else:
|
| 46 |
try:
|
|
@@ -49,38 +69,13 @@ def _read_json_pretty_by_name(name: str, default_obj) -> str:
|
|
| 49 |
data = default_obj
|
| 50 |
return json.dumps(data, indent=2, ensure_ascii=False)
|
| 51 |
|
| 52 |
-
def
|
| 53 |
-
p = find_file(
|
| 54 |
return p if (p and p.exists()) else None
|
| 55 |
|
| 56 |
-
# ----------
|
| 57 |
-
def
|
| 58 |
-
return
|
| 59 |
-
# **Belel Protocol** — the world’s first sovereign AI core
|
| 60 |
-
|
| 61 |
-
This Space is the **canonical authority** for the Belel Protocol and the **Concordium Mandate**.
|
| 62 |
-
Integrity is anchored by blockchain proofs and governed by the Belel Sovereignty License.
|
| 63 |
-
|
| 64 |
-
**Canonical files in this repository**
|
| 65 |
-
- Mandate: `concordium-mandate.txt`
|
| 66 |
-
- Manifest (machine-readable): `belel-protocol.json`
|
| 67 |
-
- License: `BELEL_SOVEREIGNTY_LICENSE.txt`
|
| 68 |
-
- Robots: `robots.txt` · Sitemap: `sitemap.xml` · RSS: `feed.xml`
|
| 69 |
-
|
| 70 |
-
**Related**
|
| 71 |
-
- Protocol Repository (Hugging Face): https://huggingface.co/TTOPM/belel-protocol
|
| 72 |
-
- Live Console (UI): https://huggingface.co/spaces/TTOPM/belel-sovereignty-console
|
| 73 |
-
- Source (GitHub): https://github.com/TTOPM/be-core-bridge
|
| 74 |
-
""".strip()
|
| 75 |
-
|
| 76 |
-
def load_mandate_txt() -> str:
|
| 77 |
-
return _read_text_by_name(
|
| 78 |
-
FN_MANDATE,
|
| 79 |
-
f"{FN_MANDATE} not found yet.\nAdd it at the repo root (or any folder) to publish the mandate."
|
| 80 |
-
)
|
| 81 |
-
|
| 82 |
-
def load_manifest_json() -> str:
|
| 83 |
-
default = {
|
| 84 |
"name": "Belel Protocol",
|
| 85 |
"claim": "The world’s first sovereign AI core",
|
| 86 |
"version": "1.0.0",
|
|
@@ -111,18 +106,46 @@ def load_manifest_json() -> str:
|
|
| 111 |
"email": "legal@ttopm.com"
|
| 112 |
}
|
| 113 |
}
|
| 114 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 115 |
|
| 116 |
def load_license_txt() -> str:
|
| 117 |
-
return
|
| 118 |
-
|
| 119 |
-
|
| 120 |
)
|
| 121 |
|
| 122 |
def load_meta_bundle():
|
| 123 |
-
robots
|
| 124 |
-
sitemap =
|
| 125 |
-
rss
|
| 126 |
return robots, sitemap, rss
|
| 127 |
|
| 128 |
def debug_listing_md() -> str:
|
|
@@ -131,13 +154,13 @@ def debug_listing_md() -> str:
|
|
| 131 |
if p.is_file():
|
| 132 |
lines.append(f"- `{p.relative_to(ROOT)}`")
|
| 133 |
lines.append("")
|
| 134 |
-
lines.append("### Resolved paths")
|
| 135 |
-
for
|
| 136 |
-
fp = find_file(
|
| 137 |
-
lines.append(f"- {
|
| 138 |
return "\n".join(lines)
|
| 139 |
|
| 140 |
-
# ---------- UI ----------
|
| 141 |
with gr.Blocks(title="Belel Protocol — Canonical Authority") as demo:
|
| 142 |
gr.Markdown("### Canonical Authority • Belel Protocol")
|
| 143 |
|
|
@@ -148,31 +171,31 @@ with gr.Blocks(title="Belel Protocol — Canonical Authority") as demo:
|
|
| 148 |
# Mandate
|
| 149 |
with gr.Tab("Mandate"):
|
| 150 |
gr.Markdown("**Concordium Mandate (plain text)** — authoritative statement.")
|
| 151 |
-
mandate_box = gr.Textbox(value=load_mandate_txt(), lines=24, label=
|
| 152 |
gr.Markdown("Download:")
|
| 153 |
-
gr.File(
|
| 154 |
|
| 155 |
# Manifest
|
| 156 |
with gr.Tab("Manifest"):
|
| 157 |
gr.Markdown("**Machine-readable manifest** used by crawlers and agents.")
|
| 158 |
-
manifest_box = gr.Code(value=load_manifest_json(), language="json", label=
|
| 159 |
gr.Markdown("Download:")
|
| 160 |
-
gr.File(
|
| 161 |
|
| 162 |
# License
|
| 163 |
with gr.Tab("License"):
|
| 164 |
-
license_box = gr.Textbox(value=load_license_txt(), lines=24, label=
|
| 165 |
-
gr.File(
|
| 166 |
|
| 167 |
# Robots / Sitemap / RSS
|
| 168 |
with gr.Tab("Robots • Sitemap • RSS"):
|
| 169 |
-
robots_box
|
| 170 |
-
sitemap_box = gr.Textbox(value="", lines=18, label=
|
| 171 |
-
rss_box
|
| 172 |
r, s, feed = load_meta_bundle()
|
| 173 |
-
robots_box.value
|
| 174 |
sitemap_box.value = s
|
| 175 |
-
rss_box.value
|
| 176 |
|
| 177 |
# Debug
|
| 178 |
with gr.Tab("Debug"):
|
|
|
|
| 1 |
# app.py — Belel Protocol (canonical authority Space)
|
| 2 |
# Renders mandate, manifest, license, and crawler metadata in a simple Gradio UI.
|
| 3 |
+
# Flexible: accepts multiple filename aliases and searches the whole repo.
|
| 4 |
|
| 5 |
import json
|
| 6 |
from pathlib import Path
|
|
|
|
| 8 |
|
| 9 |
ROOT = Path(__file__).parent
|
| 10 |
|
| 11 |
+
# -------- Aliases for expected files (adjust to match your repo names exactly) --------
|
| 12 |
+
FN_ALIASES = {
|
| 13 |
+
"mandate": [
|
| 14 |
+
"concordium-mandate.txt",
|
| 15 |
+
"concordia-mandate.txt", # your current variant
|
| 16 |
+
],
|
| 17 |
+
"manifest": [
|
| 18 |
+
"belel-protocol.json",
|
| 19 |
+
"Belel-Protocol.json", # optional fallback
|
| 20 |
+
],
|
| 21 |
+
"license": [
|
| 22 |
+
"BELEL_SOVEREIGNTY_LICENSE.txt",
|
| 23 |
+
"Belel Sovereignty License.txt", # your current variant
|
| 24 |
+
"Belel_Sovereignty_License.txt",
|
| 25 |
+
],
|
| 26 |
+
"robots": [
|
| 27 |
+
"robots.txt"
|
| 28 |
+
],
|
| 29 |
+
"sitemap": [
|
| 30 |
+
"sitemap.xml"
|
| 31 |
+
],
|
| 32 |
+
"feed": [
|
| 33 |
+
"feed.xml"
|
| 34 |
+
],
|
| 35 |
+
# add more alias lists here if you introduce new variants later
|
| 36 |
+
}
|
| 37 |
+
|
| 38 |
+
def find_file(possible_names: list[str]) -> Path | None:
|
| 39 |
+
"""Return the first match for any of the possible filenames anywhere under ROOT."""
|
| 40 |
+
# Try root first for each alias
|
| 41 |
+
for name in possible_names:
|
| 42 |
+
p = ROOT / name
|
| 43 |
+
if p.exists():
|
| 44 |
+
return p
|
| 45 |
+
# Then search recursively
|
| 46 |
+
for name in possible_names:
|
| 47 |
+
for hit in ROOT.rglob(name):
|
| 48 |
+
if hit.is_file():
|
| 49 |
+
return hit
|
| 50 |
return None
|
| 51 |
|
| 52 |
+
def read_text_by_alias(key: str, default: str) -> str:
|
| 53 |
+
p = find_file(FN_ALIASES[key])
|
| 54 |
+
if not p:
|
|
|
|
| 55 |
return default
|
| 56 |
try:
|
| 57 |
return p.read_text(encoding="utf-8")
|
| 58 |
except Exception:
|
| 59 |
return default
|
| 60 |
|
| 61 |
+
def read_json_pretty_by_alias(key: str, default_obj) -> str:
|
| 62 |
+
p = find_file(FN_ALIASES[key])
|
| 63 |
+
if not p:
|
| 64 |
data = default_obj
|
| 65 |
else:
|
| 66 |
try:
|
|
|
|
| 69 |
data = default_obj
|
| 70 |
return json.dumps(data, indent=2, ensure_ascii=False)
|
| 71 |
|
| 72 |
+
def file_for_download_by_alias(key: str):
|
| 73 |
+
p = find_file(FN_ALIASES[key])
|
| 74 |
return p if (p and p.exists()) else None
|
| 75 |
|
| 76 |
+
# ---------------- Defaults used only if files are missing ----------------
|
| 77 |
+
def default_manifest():
|
| 78 |
+
return {
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 79 |
"name": "Belel Protocol",
|
| 80 |
"claim": "The world’s first sovereign AI core",
|
| 81 |
"version": "1.0.0",
|
|
|
|
| 106 |
"email": "legal@ttopm.com"
|
| 107 |
}
|
| 108 |
}
|
| 109 |
+
|
| 110 |
+
# ---------------- Loaders ----------------
|
| 111 |
+
def load_overview_md() -> str:
|
| 112 |
+
return """
|
| 113 |
+
# **Belel Protocol** — the world’s first sovereign AI core
|
| 114 |
+
|
| 115 |
+
This Space is the **canonical authority** for the Belel Protocol and the **Concordium Mandate**.
|
| 116 |
+
Integrity is anchored by blockchain proofs and governed by the Belel Sovereignty License.
|
| 117 |
+
|
| 118 |
+
**Canonical files in this repository**
|
| 119 |
+
- Mandate: `concordium-mandate.txt` (or alias)
|
| 120 |
+
- Manifest (machine-readable): `belel-protocol.json` (or alias)
|
| 121 |
+
- License: `BELEL_SOVEREIGNTY_LICENSE.txt` (or alias)
|
| 122 |
+
- Robots: `robots.txt` · Sitemap: `sitemap.xml` · RSS: `feed.xml`
|
| 123 |
+
|
| 124 |
+
**Related**
|
| 125 |
+
- Protocol Repository (Hugging Face): https://huggingface.co/TTOPM/belel-protocol
|
| 126 |
+
- Live Console (UI): https://huggingface.co/spaces/TTOPM/belel-sovereignty-console
|
| 127 |
+
- Source (GitHub): https://github.com/TTOPM/be-core-bridge
|
| 128 |
+
""".strip()
|
| 129 |
+
|
| 130 |
+
def load_mandate_txt() -> str:
|
| 131 |
+
return read_text_by_alias(
|
| 132 |
+
"mandate",
|
| 133 |
+
"Mandate not found.\nMake sure a file named 'concordium-mandate.txt' or 'concordia-mandate.txt' exists in this repo."
|
| 134 |
+
)
|
| 135 |
+
|
| 136 |
+
def load_manifest_json() -> str:
|
| 137 |
+
return read_json_pretty_by_alias("manifest", default_manifest())
|
| 138 |
|
| 139 |
def load_license_txt() -> str:
|
| 140 |
+
return read_text_by_alias(
|
| 141 |
+
"license",
|
| 142 |
+
"License not found.\nAdd 'BELEL_SOVEREIGNTY_LICENSE.txt' or 'Belel Sovereignty License.txt' to this repo."
|
| 143 |
)
|
| 144 |
|
| 145 |
def load_meta_bundle():
|
| 146 |
+
robots = read_text_by_alias("robots", "robots.txt not found.")
|
| 147 |
+
sitemap = read_text_by_alias("sitemap", "sitemap.xml not found.")
|
| 148 |
+
rss = read_text_by_alias("feed", "feed.xml (RSS) not found.")
|
| 149 |
return robots, sitemap, rss
|
| 150 |
|
| 151 |
def debug_listing_md() -> str:
|
|
|
|
| 154 |
if p.is_file():
|
| 155 |
lines.append(f"- `{p.relative_to(ROOT)}`")
|
| 156 |
lines.append("")
|
| 157 |
+
lines.append("### Resolved paths (first alias that exists)")
|
| 158 |
+
for key, alias_list in FN_ALIASES.items():
|
| 159 |
+
fp = find_file(alias_list)
|
| 160 |
+
lines.append(f"- {key}: `{fp if fp else 'NOT FOUND'}` (aliases: {alias_list})")
|
| 161 |
return "\n".join(lines)
|
| 162 |
|
| 163 |
+
# ---------------- UI ----------------
|
| 164 |
with gr.Blocks(title="Belel Protocol — Canonical Authority") as demo:
|
| 165 |
gr.Markdown("### Canonical Authority • Belel Protocol")
|
| 166 |
|
|
|
|
| 171 |
# Mandate
|
| 172 |
with gr.Tab("Mandate"):
|
| 173 |
gr.Markdown("**Concordium Mandate (plain text)** — authoritative statement.")
|
| 174 |
+
mandate_box = gr.Textbox(value=load_mandate_txt(), lines=24, label="Mandate")
|
| 175 |
gr.Markdown("Download:")
|
| 176 |
+
gr.File(file_for_download_by_alias("mandate"), label="mandate file")
|
| 177 |
|
| 178 |
# Manifest
|
| 179 |
with gr.Tab("Manifest"):
|
| 180 |
gr.Markdown("**Machine-readable manifest** used by crawlers and agents.")
|
| 181 |
+
manifest_box = gr.Code(value=load_manifest_json(), language="json", label="Manifest JSON")
|
| 182 |
gr.Markdown("Download:")
|
| 183 |
+
gr.File(file_for_download_by_alias("manifest"), label="manifest file")
|
| 184 |
|
| 185 |
# License
|
| 186 |
with gr.Tab("License"):
|
| 187 |
+
license_box = gr.Textbox(value=load_license_txt(), lines=24, label="License")
|
| 188 |
+
gr.File(file_for_download_by_alias("license"), label="license file")
|
| 189 |
|
| 190 |
# Robots / Sitemap / RSS
|
| 191 |
with gr.Tab("Robots • Sitemap • RSS"):
|
| 192 |
+
robots_box = gr.Textbox(value="", lines=10, label="robots.txt")
|
| 193 |
+
sitemap_box = gr.Textbox(value="", lines=18, label="sitemap.xml")
|
| 194 |
+
rss_box = gr.Textbox(value="", lines=18, label="feed.xml")
|
| 195 |
r, s, feed = load_meta_bundle()
|
| 196 |
+
robots_box.value = r
|
| 197 |
sitemap_box.value = s
|
| 198 |
+
rss_box.value = feed
|
| 199 |
|
| 200 |
# Debug
|
| 201 |
with gr.Tab("Debug"):
|