binarykernel / app.py
binarydoc's picture
Upload app.py with huggingface_hub
49e96b5 verified
Raw
History Blame Contribute Delete
18.6 kB
from __future__ import annotations
from pathlib import Path
from datetime import datetime, timezone
import gradio as gr
from huggingface_hub import whoami
ROOT = Path(__file__).resolve().parent
LOGO_AVATAR = ROOT / "assets" / "logo-avatar.png"
LOGO_MARK = ROOT / "assets" / "logo.png"
LOGO_LOCKUP = ROOT / "assets" / "logo-lockup.png"
FAVICON = next((p for p in (LOGO_AVATAR, LOGO_MARK) if p.is_file()), None)
SITE_URL = "https://binarykernel-site.vercel.app"
SPACE_URL = "https://huggingface.co/spaces/binarydoc/binarykernel"
LINKS = {
"Landing page": SITE_URL,
"Jira": "https://binarykernel.atlassian.net/jira/projects",
"Slack": "https://slack.com",
"Hermes docs": "https://hermes-agent.nousresearch.com/docs/",
"HF profile": "https://huggingface.co/binarydoc",
}
# ====== SVG Pipeline Visual ======
PIPELINE_SVG = """<svg viewBox="0 0 920 520" xmlns="http://www.w3.org/2000/svg" style="width:100%;height:auto;display:block;font-family:system-ui,-apple-system,sans-serif;">
<defs>
<linearGradient id="g-purple" x1="0%" y1="0%" x2="100%" y2="100%">
<stop offset="0%" stop-color="#6C63FF"/><stop offset="100%" stop-color="#4A44CC"/>
</linearGradient>
<linearGradient id="g-pink" x1="0%" y1="0%" x2="100%" y2="100%">
<stop offset="0%" stop-color="#FF6B6B"/><stop offset="100%" stop-color="#CC4444"/>
</linearGradient>
<linearGradient id="g-amber" x1="0%" y1="0%" x2="100%" y2="100%">
<stop offset="0%" stop-color="#FFD93D"/><stop offset="100%" stop-color="#CCA500"/>
</linearGradient>
<linearGradient id="g-teal" x1="0%" y1="0%" x2="100%" y2="100%">
<stop offset="0%" stop-color="#00E6C8"/><stop offset="100%" stop-color="#00B39A"/>
</linearGradient>
<linearGradient id="g-coral" x1="0%" y1="0%" x2="100%" y2="100%">
<stop offset="0%" stop-color="#FF8A65"/><stop offset="100%" stop-color="#CC6B47"/>
</linearGradient>
<marker id="arrow" viewBox="0 0 10 10" refX="9" refY="5" markerWidth="7" markerHeight="7" orient="auto">
<path d="M0,1 L9,5 L0,9" fill="none" stroke="rgba(255,255,255,0.3)" stroke-width="1.5" stroke-linecap="round" stroke-linejoin="round"/>
</marker>
<pattern id="grid" width="30" height="30" patternUnits="userSpaceOnUse">
<circle cx="15" cy="15" r="0.6" fill="rgba(255,255,255,0.04)"/>
</pattern>
</defs>
<rect width="100%" height="100%" fill="#0a0a12"/>
<rect width="100%" height="100%" fill="url(#grid)"/>
<ellipse cx="460" cy="300" rx="350" ry="180" fill="rgba(108,99,255,0.06)"/>
<!-- Labels -->
<text x="40" y="35" fill="rgba(255,255,255,0.15)" font-size="10" font-weight="700" letter-spacing="2">SOURCE</text>
<line x1="40" y1="42" x2="110" y2="42" stroke="rgba(255,255,255,0.08)" stroke-width="1"/>
<text x="250" y="35" fill="rgba(255,255,255,0.15)" font-size="10" font-weight="700" letter-spacing="2">SYNC</text>
<text x="480" y="35" fill="rgba(255,255,255,0.15)" font-size="10" font-weight="700" letter-spacing="2">AGENTS</text>
<text x="720" y="35" fill="rgba(255,255,255,0.15)" font-size="10" font-weight="700" letter-spacing="2">OUTPUTS</text>
<!-- Flow arrows -->
<line x1="155" y1="130" x2="220" y2="130" stroke="#6C63FF" stroke-width="2" marker-end="url(#arrow)" opacity="0.5"/>
<line x1="310" y1="130" x2="370" y2="130" stroke="#6C63FF" stroke-width="2" marker-end="url(#arrow)" opacity="0.5"/>
<line x1="460" y1="130" x2="520" y2="130" stroke="#6C63FF" stroke-width="2" marker-end="url(#arrow)" opacity="0.5"/>
<line x1="610" y1="130" x2="670" y2="130" stroke="#6C63FF" stroke-width="2" marker-end="url(#arrow)" opacity="0.5"/>
<line x1="460" y1="370" x2="460" y2="400" stroke="rgba(255,255,255,0.1)" stroke-width="1.5" marker-end="url(#arrow)"/>
<line x1="460" y1="400" x2="250" y2="400" stroke="rgba(255,255,255,0.1)" stroke-width="1.5" marker-end="url(#arrow)"/>
<line x1="460" y1="400" x2="670" y2="400" stroke="rgba(255,255,255,0.1)" stroke-width="1.5" marker-end="url(#arrow)"/>
<!-- Row 1 — Core flow -->
<rect x="40" y="100" width="115" height="60" rx="14" fill="url(#g-purple)"/>
<text x="97" y="127" fill="white" font-size="14" font-weight="700" text-anchor="middle">Zorin CLI</text>
<text x="97" y="145" fill="rgba(255,255,255,0.6)" font-size="10" text-anchor="middle">Hermes Agent</text>
<rect x="220" y="100" width="90" height="60" rx="14" fill="url(#g-amber)"/>
<text x="265" y="127" fill="#1a1a0a" font-size="14" font-weight="700" text-anchor="middle">Supermemory</text>
<text x="265" y="145" fill="rgba(0,0,0,0.5)" font-size="10" text-anchor="middle">API hosted</text>
<rect x="370" y="100" width="90" height="60" rx="14" fill="url(#g-teal)"/>
<text x="415" y="127" fill="#0a1a14" font-size="14" font-weight="700" text-anchor="middle">VPS Pi</text>
<text x="415" y="145" fill="rgba(0,0,0,0.5)" font-size="10" text-anchor="middle">Workspace Agent</text>
<rect x="520" y="100" width="90" height="60" rx="14" fill="url(#g-pink)"/>
<text x="565" y="127" fill="white" font-size="14" font-weight="700" text-anchor="middle">Swarm</text>
<text x="565" y="145" fill="rgba(255,255,255,0.6)" font-size="10" text-anchor="middle">10 Workers</text>
<rect x="670" y="100" width="90" height="60" rx="14" fill="url(#g-coral)"/>
<text x="715" y="127" fill="white" font-size="14" font-weight="700" text-anchor="middle">Outputs</text>
<text x="715" y="145" fill="rgba(255,255,255,0.6)" font-size="10" text-anchor="middle">Slack Telegram</text>
<!-- Row 2 — Tools -->
<rect x="40" y="175" width="115" height="46" rx="10" fill="rgba(255,255,255,0.03)" stroke="rgba(255,255,255,0.08)" stroke-width="1"/>
<text x="97" y="196" fill="rgba(255,255,255,0.5)" font-size="11" font-weight="500" text-anchor="middle">Cursor IDE</text>
<text x="97" y="210" fill="rgba(255,255,255,0.25)" font-size="9" text-anchor="middle">Hermes MCP</text>
<rect x="220" y="175" width="90" height="46" rx="10" fill="rgba(255,255,255,0.03)" stroke="rgba(255,255,255,0.08)" stroke-width="1"/>
<text x="265" y="196" fill="rgba(255,255,255,0.5)" font-size="11" font-weight="500" text-anchor="middle">Pi Agent</text>
<text x="265" y="210" fill="rgba(255,255,255,0.25)" font-size="9" text-anchor="middle">coding agent</text>
<rect x="370" y="175" width="90" height="46" rx="10" fill="rgba(255,255,255,0.03)" stroke="rgba(255,255,255,0.08)" stroke-width="1"/>
<text x="415" y="196" fill="rgba(255,255,255,0.5)" font-size="11" font-weight="500" text-anchor="middle">Bitbucket</text>
<text x="415" y="210" fill="rgba(255,255,255,0.25)" font-size="9" text-anchor="middle">CI/CD sync</text>
<rect x="520" y="175" width="90" height="46" rx="10" fill="rgba(255,255,255,0.03)" stroke="rgba(255,255,255,0.08)" stroke-width="1"/>
<text x="565" y="196" fill="rgba(255,255,255,0.5)" font-size="11" font-weight="500" text-anchor="middle">Hostinger</text>
<text x="565" y="210" fill="rgba(255,255,255,0.25)" font-size="9" text-anchor="middle">314 MCP tools</text>
<!-- Row 3 — Infra boxes -->
<rect x="40" y="245" width="290" height="60" rx="14" fill="rgba(0,230,200,0.04)" stroke="rgba(0,230,200,0.12)" stroke-width="1" stroke-dasharray="4,4"/>
<text x="58" y="262" fill="rgba(0,230,200,0.45)" font-size="9" font-weight="600">VPS hostinger 100.115.96.51</text>
<rect x="58" y="273" width="62" height="22" rx="6" fill="rgba(0,230,200,0.08)" stroke="rgba(0,230,200,0.15)" stroke-width="0.5"/>
<text x="89" y="288" fill="rgba(0,230,200,0.5)" font-size="8" text-anchor="middle">Traefik</text>
<rect x="128" y="273" width="62" height="22" rx="6" fill="rgba(0,230,200,0.08)" stroke="rgba(0,230,200,0.15)" stroke-width="0.5"/>
<text x="159" y="288" fill="rgba(0,230,200,0.5)" font-size="8" text-anchor="middle">Chat UI</text>
<rect x="198" y="273" width="62" height="22" rx="6" fill="rgba(0,230,200,0.08)" stroke="rgba(0,230,200,0.15)" stroke-width="0.5"/>
<text x="229" y="288" fill="rgba(0,230,200,0.5)" font-size="8" text-anchor="middle">9Router</text>
<rect x="268" y="273" width="52" height="22" rx="6" fill="rgba(0,230,200,0.08)" stroke="rgba(0,230,200,0.15)" stroke-width="0.5"/>
<text x="294" y="288" fill="rgba(0,230,200,0.5)" font-size="8" text-anchor="middle">Mongo</text>
<rect x="350" y="245" width="220" height="60" rx="14" fill="rgba(108,99,255,0.04)" stroke="rgba(108,99,255,0.12)" stroke-width="1" stroke-dasharray="4,4"/>
<text x="368" y="262" fill="rgba(108,99,255,0.45)" font-size="9" font-weight="600">HF Space binarydoc/binarykernel</text>
<rect x="368" y="273" width="62" height="22" rx="6" fill="rgba(108,99,255,0.08)" stroke="rgba(108,99,255,0.15)" stroke-width="0.5"/>
<text x="399" y="288" fill="rgba(108,99,255,0.5)" font-size="8" text-anchor="middle">Gradio</text>
<rect x="438" y="273" width="62" height="22" rx="6" fill="rgba(108,99,255,0.08)" stroke="rgba(108,99,255,0.15)" stroke-width="0.5"/>
<text x="469" y="288" fill="rgba(108,99,255,0.5)" font-size="8" text-anchor="middle">zero-a10g</text>
<rect x="508" y="273" width="52" height="22" rx="6" fill="rgba(108,99,255,0.08)" stroke="rgba(108,99,255,0.15)" stroke-width="0.5"/>
<text x="534" y="288" fill="rgba(108,99,255,0.5)" font-size="8" text-anchor="middle">OAuth</text>
<rect x="590" y="245" width="170" height="60" rx="14" fill="rgba(255,107,107,0.04)" stroke="rgba(255,107,107,0.12)" stroke-width="1" stroke-dasharray="4,4"/>
<text x="608" y="262" fill="rgba(255,107,107,0.45)" font-size="9" font-weight="600">VM 1806872 hermes.binarydoc</text>
<rect x="608" y="273" width="70" height="22" rx="6" fill="rgba(255,107,107,0.08)" stroke="rgba(255,107,107,0.15)" stroke-width="0.5"/>
<text x="643" y="288" fill="rgba(255,107,107,0.5)" font-size="8" text-anchor="middle">9Router</text>
<rect x="686" y="273" width="64" height="22" rx="6" fill="rgba(255,107,107,0.08)" stroke="rgba(255,107,107,0.15)" stroke-width="0.5"/>
<text x="718" y="288" fill="rgba(255,107,107,0.5)" font-size="8" text-anchor="middle">Headroom</text>
<!-- Row 4 — Destinations -->
<rect x="60" y="380" width="130" height="48" rx="12" fill="url(#g-amber)"/>
<text x="125" y="404" fill="#1a1a0a" font-size="13" font-weight="700" text-anchor="middle">Bitbucket</text>
<text x="125" y="418" fill="rgba(0,0,0,0.5)" font-size="9" text-anchor="middle">Config Sync</text>
<rect x="250" y="380" width="130" height="48" rx="12" fill="url(#g-pink)"/>
<text x="315" y="404" fill="white" font-size="13" font-weight="700" text-anchor="middle">Slack</text>
<text x="315" y="418" fill="rgba(255,255,255,0.6)" font-size="9" text-anchor="middle">Publishing</text>
<rect x="440" y="380" width="130" height="48" rx="12" fill="url(#g-teal)"/>
<text x="505" y="404" fill="#0a1a14" font-size="13" font-weight="700" text-anchor="middle">Telegram</text>
<text x="505" y="418" fill="rgba(0,0,0,0.5)" font-size="9" text-anchor="middle">@binaryzorin_bot</text>
<rect x="630" y="380" width="130" height="48" rx="12" fill="url(#g-purple)"/>
<text x="695" y="404" fill="white" font-size="13" font-weight="700" text-anchor="middle">HF Space</text>
<text x="695" y="418" fill="rgba(255,255,255,0.6)" font-size="9" text-anchor="middle">You are here</text>
<!-- Legend -->
<g transform="translate(40, 455)">
<text x="0" y="0" fill="rgba(255,255,255,0.2)" font-size="9" font-weight="600" letter-spacing="1">LEGEND</text>
<rect x="0" y="12" width="10" height="7" rx="2" fill="url(#g-purple)"/>
<text x="15" y="19" fill="rgba(255,255,255,0.35)" font-size="8">Core</text>
<rect x="60" y="12" width="10" height="7" rx="2" fill="url(#g-amber)"/>
<text x="75" y="19" fill="rgba(255,255,255,0.35)" font-size="8">Sync</text>
<rect x="115" y="12" width="10" height="7" rx="2" fill="url(#g-teal)"/>
<text x="130" y="19" fill="rgba(255,255,255,0.35)" font-size="8">Infra</text>
<rect x="170" y="12" width="10" height="7" rx="2" fill="url(#g-pink)"/>
<text x="185" y="19" fill="rgba(255,255,255,0.35)" font-size="8">Output</text>
<rect x="225" y="12" width="10" height="7" rx="2" fill="url(#g-coral)"/>
<text x="240" y="19" fill="rgba(255,255,255,0.35)" font-size="8">Dest</text>
</g>
</svg>"""
def greet(profile: gr.OAuthProfile | None) -> str:
if profile is None:
return (
"### Welcome to BinaryKernel\n\n"
"Browse the hub freely. Sign in with Hugging Face to unlock your "
"operator profile and organisation memberships.\n\n"
f"[Open the BinaryKernel landing page]({SITE_URL})"
)
name = profile.name or profile.username or "operator"
username = profile.username or ""
suffix = f" (`@{username}`)" if username else ""
return (
f"### Hello, {name}{suffix}\n\n"
"You are signed in. Use the surfaces below — LoginButton does **not** "
"gate the app; unsigned visitors can still use public features."
)
def list_organizations(oauth_token: gr.OAuthToken | None) -> str:
if oauth_token is None:
return "### Organisations\n\nSign in with Hugging Face to list organisations."
try:
info = whoami(oauth_token.token)
orgs = info.get("orgs") or []
if not orgs:
return "### Organisations\n\nNo organisation memberships returned."
names = [org.get("name") or org.get("fullname") or "?" for org in orgs]
return "### Organisations\n\n" + "\n".join(f"- `{name}`" for name in names)
except Exception as exc:
return f"### Organisations\n\nCould not fetch organisations:\n\n```\n{exc}\n```"
def list_repos(oauth_token: gr.OAuthToken | None) -> str:
if oauth_token is None:
return "### Repositories\n\nSign in with Hugging Face to list your repositories."
try:
info = whoami(oauth_token.token)
repos = info.get("repos") or info.get("orgRepos") or []
bullets = "\n".join(
f"- [`{r.get('name', '?')}`](https://huggingface.co/{r.get('name', '')})"
for r in repos[:20]
)
return f"### Repositories\n\n{bullets}"
except Exception as exc:
return f"### Repositories\n\nError: {exc}" if exc else "### Repositories\n\nNone found."
def get_pipeline_status() -> str:
now = datetime.now(timezone.utc).strftime("%Y-%m-%d %H:%M UTC")
return (
f"**Pipeline Dashboard** · last updated {now}\n\n"
"This diagram shows the live cross-device infrastructure. "
"All nodes share memory through supermemory with `container_tag: hermes`.\n\n"
"| Node | Status |\n"
"|------|--------|\n"
"| **Zorin CLI** | `provider: supermemory` active ✓ |\n"
"| **Supermemory** | Hosted API — cross-device sync live ✓ |\n"
"| **VPS Pi** | ⚠️ **OFFLINE** (last seen 14h ago) |\n"
"| **Forgejo** | ⚠️ UNKNOWN (VPS offline) |\n"
"| **Traefik** | ⚠️ UNKNOWN (VPS offline) |\n"
"| **Swarm** | ⚠️ UNREACHABLE (VPS offline) |\n"
"| **Cursor** | Hermes MCP server wired ✓ |\n"
"| **Bitbucket** | Push/pull sync every 2h |\n"
"| **Tailscale** | `hermes-zorin.tail455136.ts.net` — endpoint unreachable |\n"
"| **HF Space** | zero-a10g · Gradio 5.49.1 · OAuth ✓ |\n\n"
"**Memory limits:** 20,000 chars · Health check: every 4h\n\n"
"⚠️ **ALERT:** VPS workspace agent (100.115.96.51) is offline. SSH and Tailscale serve endpoints are unreachable. "
"Pipeline is in DEGRADED state. Local supermemory is connected and functional."
)
with gr.Blocks(theme=gr.themes.Soft(), title="BinaryKernel Hub", favicon=str(FAVICON)) as demo:
gr.HTML(
f"""
<div style="display:flex;align-items:center;gap:12px;margin-bottom:8px">
<img src="file={LOGO_AVATAR}" width="40" height="40" style="border-radius:50%">
<div>
<h1 style="margin:0;font-size:20px">BinaryKernel Hub</h1>
<p style="margin:0;color:var(--body-text-color-subdued);font-size:13px">
Operator hub · cross-device AI agent pipeline
</p>
</div>
</div>
"""
)
with gr.Row():
with gr.Column(scale=1):
login_btn = gr.LoginButton()
greeting = gr.Markdown(greet(None))
login_btn.change(fn=greet, inputs=login_btn, outputs=greeting)
with gr.Column(scale=2):
gr.Markdown("### Quick Links")
for label, url in LINKS.items():
gr.Markdown(f"- [{label}]({url})")
with gr.Tab("Pipeline Dashboard"):
gr.Markdown("## BinaryKernel Infrastructure")
gr.HTML(PIPELINE_SVG)
status = gr.Markdown(get_pipeline_status())
refresh_btn = gr.Button("Refresh status", variant="secondary", size="sm")
refresh_btn.click(fn=get_pipeline_status, outputs=status)
gr.Markdown(
"---\n"
"*Pipeline visual · click Refresh to update timestamp*"
)
with gr.Tab("System Status"):
gr.Markdown(
"### System Status\n\n"
f"- **Space ID:** `binarydoc/binarykernel`\n"
f"- **Host:** https://binarydoc-binarykernel.hf.space\n"
f"- **Hardware:** zero-a10g (dedicated GPU)\n"
f"- **Gradio:** {gr.__version__}\n"
f"- **Region:** us\n"
f"- **Dev mode:** active\n"
)
with gr.Tab("Organisations"):
org_btn = gr.Button("List organisations", variant="primary")
org_output = gr.Markdown()
org_btn.click(fn=list_organizations, inputs=login_btn, outputs=org_output)
with gr.Tab("Repositories"):
repo_btn = gr.Button("List repositories", variant="primary")
repo_output = gr.Markdown()
repo_btn.click(fn=list_repos, inputs=login_btn, outputs=repo_output)
with gr.Tab("Supermemory Sync"):
gr.Markdown(
"### Cross-Device Sync Pipeline\n\n"
"All Hermes nodes share a supermemory hosted API with `container_tag: hermes`.\n"
"Memory limits: 20000/6000. Health check runs every 4 hours.\n\n"
"- **Zorin CLI** — `provider: supermemory`, SDK active\n"
"- **VPS Workspace Agent** — `provider: supermemory`, SDK v3.57.0\n"
"- **Cursor IDE** — Hermes MCP server wired\n"
"- **Pi Agent** — `@earendil-works/pi-coding-agent` running\n"
"- **Tailscale serve** — `hermes-zorin.tail455136.ts.net`\n"
"- **Backups** — Bitbucket push/pull every 2h, session snapshot every 2h\n"
)
gr.Markdown(
"\n---\n"
"<div style='text-align:center;color:var(--body-text-color-subdued);font-size:0.8em'>"
"Built with Gradio · Source on "
f"<a href='{SPACE_URL}'>Hugging Face Spaces</a>"
" · Powered by zero-a10g</div>"
)
if __name__ == "__main__":
demo.launch()