Spaces:
Running
Running
Redesign: branded hero + real MCP onboarding (app.py)
Browse files
app.py
CHANGED
|
@@ -12,6 +12,11 @@ dataset (10 calls/day free anonymous; free key via its claim_free_key tool).
|
|
| 12 |
|
| 13 |
Optional Space secret DCHUB_API_KEY (a dchub_ key) lifts the bridge tools to
|
| 14 |
full-tier responses; without it they ride the anonymous free tier.
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 15 |
"""
|
| 16 |
import json
|
| 17 |
import os
|
|
@@ -22,6 +27,7 @@ import gradio as gr
|
|
| 22 |
|
| 23 |
API = "https://dchub.cloud"
|
| 24 |
FULL_MCP = "https://dchub.cloud/mcp"
|
|
|
|
| 25 |
TIMEOUT = 20
|
| 26 |
API_KEY = (os.environ.get("DCHUB_API_KEY") or "").strip()
|
| 27 |
UA = "huggingface-space-dchub-bridge/1.0 (+https://dchub.cloud)"
|
|
@@ -209,72 +215,185 @@ def hyperscaler_deals(limit: int = 10) -> str:
|
|
| 209 |
return _call_tool("hyperscaler_deals", {"limit": int(limit) or 10})
|
| 210 |
|
| 211 |
|
| 212 |
-
|
| 213 |
-
|
| 214 |
-
|
| 215 |
-
|
| 216 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 217 |
|
| 218 |
-
|
| 219 |
-
|
| 220 |
-
|
| 221 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 222 |
"""
|
| 223 |
|
| 224 |
-
|
| 225 |
-
|
| 226 |
-
|
| 227 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 228 |
out = gr.Markdown()
|
| 229 |
-
|
|
|
|
| 230 |
gr.Examples([["Northern Virginia"], ["Phoenix"], ["Columbus"],
|
| 231 |
["Cheyenne"], ["Dallas"], ["Omaha"]], inp)
|
| 232 |
-
with gr.Tab("Compare markets"):
|
| 233 |
cinp = gr.Textbox(label="Markets (comma-separated)",
|
| 234 |
-
value="Northern Virginia, Phoenix, Cheyenne, Omaha, Dallas"
|
|
|
|
|
|
|
| 235 |
cout = gr.Markdown()
|
| 236 |
-
|
| 237 |
-
|
| 238 |
-
|
| 239 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 240 |
gr.Button("Live grid scoreboard (greenest first)", variant="primary").click(
|
| 241 |
grid_scoreboard, [], gout)
|
| 242 |
-
with gr.Tab("Search facilities"):
|
| 243 |
-
|
| 244 |
-
|
| 245 |
-
|
| 246 |
-
|
| 247 |
-
|
| 248 |
-
|
| 249 |
-
|
|
|
|
|
|
|
|
|
|
| 250 |
gr.Button("Search 21,900+ facilities", variant="primary").click(
|
| 251 |
search_facilities, [s_q, s_c, s_s, s_o, s_m, s_l], sout)
|
| 252 |
-
with gr.Tab("Rank markets"):
|
| 253 |
-
|
| 254 |
-
|
| 255 |
-
|
| 256 |
-
|
| 257 |
-
|
| 258 |
-
|
|
|
|
| 259 |
gr.Button("Rank markets", variant="primary").click(
|
| 260 |
rank_markets, [r_c, r_r, r_l], rout)
|
| 261 |
-
with gr.Tab("Interconnection queue"):
|
| 262 |
q_i = gr.Dropdown(["", "ERCOT", "PJM", "MISO", "CAISO", "SPP", "NYISO",
|
| 263 |
-
"ISONE"], value="", label="ISO
|
| 264 |
-
|
|
|
|
| 265 |
gr.Button("Queue intelligence", variant="primary").click(
|
| 266 |
interconnection_queue, [q_i], qout)
|
| 267 |
-
with gr.Tab("Hyperscaler deals"):
|
| 268 |
-
d_l = gr.Number(label="
|
| 269 |
-
|
|
|
|
| 270 |
gr.Button("Recent AI-capex deals", variant="primary").click(
|
| 271 |
hyperscaler_deals, [d_l], dout)
|
| 272 |
-
|
| 273 |
-
|
| 274 |
-
f"
|
| 275 |
-
f"
|
|
|
|
|
|
|
| 276 |
|
| 277 |
if __name__ == "__main__":
|
| 278 |
# mcp_server=True exposes all 7 tools as MCP tools at /gradio_api/mcp/sse —
|
| 279 |
# usable by HF Agents, smolagents, and any MCP client.
|
| 280 |
-
demo.launch(mcp_server=True)
|
|
|
|
| 12 |
|
| 13 |
Optional Space secret DCHUB_API_KEY (a dchub_ key) lifts the bridge tools to
|
| 14 |
full-tier responses; without it they ride the anonymous free tier.
|
| 15 |
+
|
| 16 |
+
UI NOTE: the 7 tool functions below are the MCP contract (names + docstrings
|
| 17 |
+
become the tool schema at /gradio_api/mcp/schema) — keep them stable. UI-only
|
| 18 |
+
events that reuse them (e.g. textbox .submit) pass api_name=False so they
|
| 19 |
+
never mint a duplicate MCP tool.
|
| 20 |
"""
|
| 21 |
import json
|
| 22 |
import os
|
|
|
|
| 27 |
|
| 28 |
API = "https://dchub.cloud"
|
| 29 |
FULL_MCP = "https://dchub.cloud/mcp"
|
| 30 |
+
SPACE_MCP = "https://dchubcloud-dchub.hf.space/gradio_api/mcp/sse"
|
| 31 |
TIMEOUT = 20
|
| 32 |
API_KEY = (os.environ.get("DCHUB_API_KEY") or "").strip()
|
| 33 |
UA = "huggingface-space-dchub-bridge/1.0 (+https://dchub.cloud)"
|
|
|
|
| 215 |
return _call_tool("hyperscaler_deals", {"limit": int(limit) or 10})
|
| 216 |
|
| 217 |
|
| 218 |
+
# ── UI ──────────────────────────────────────────────────────────────────────
|
| 219 |
+
# Everything below is presentation only — no new MCP tools are minted here
|
| 220 |
+
# (UI-only events pass api_name=False).
|
| 221 |
+
|
| 222 |
+
CSS = """
|
| 223 |
+
.gradio-container { max-width: 1080px !important; margin: 0 auto !important; }
|
| 224 |
+
.dc-hero {
|
| 225 |
+
border-radius: 14px;
|
| 226 |
+
padding: 26px 28px 22px;
|
| 227 |
+
margin-bottom: 4px;
|
| 228 |
+
background: linear-gradient(120deg, #0b1220 0%, #101c33 55%, #1a2a17 100%);
|
| 229 |
+
border: 1px solid rgba(250, 204, 21, .25);
|
| 230 |
+
}
|
| 231 |
+
.dc-hero h1 {
|
| 232 |
+
margin: 0 0 6px;
|
| 233 |
+
font-size: 1.65rem;
|
| 234 |
+
line-height: 1.2;
|
| 235 |
+
color: #f8fafc;
|
| 236 |
+
}
|
| 237 |
+
.dc-hero h1 .amp { color: #facc15; }
|
| 238 |
+
.dc-hero .sub {
|
| 239 |
+
margin: 0 0 14px;
|
| 240 |
+
font-size: 1rem;
|
| 241 |
+
color: #cbd5e1;
|
| 242 |
+
max-width: 62rem;
|
| 243 |
+
}
|
| 244 |
+
.dc-hero .sub a { color: #facc15; text-decoration: none; }
|
| 245 |
+
.dc-chips { display: flex; flex-wrap: wrap; gap: 8px; }
|
| 246 |
+
.dc-chip {
|
| 247 |
+
font-size: .8rem;
|
| 248 |
+
padding: 4px 11px;
|
| 249 |
+
border-radius: 999px;
|
| 250 |
+
background: rgba(148, 163, 184, .14);
|
| 251 |
+
border: 1px solid rgba(148, 163, 184, .28);
|
| 252 |
+
color: #e2e8f0;
|
| 253 |
+
white-space: nowrap;
|
| 254 |
+
}
|
| 255 |
+
.dc-chip.build { background: rgba(34, 197, 94, .14); border-color: rgba(34, 197, 94, .45); color: #86efac; }
|
| 256 |
+
.dc-chip.caution { background: rgba(234, 179, 8, .14); border-color: rgba(234, 179, 8, .45); color: #fde047; }
|
| 257 |
+
.dc-chip.avoid { background: rgba(239, 68, 68, .14); border-color: rgba(239, 68, 68, .45); color: #fca5a5; }
|
| 258 |
+
.dc-foot { text-align: center; font-size: .85rem; opacity: .8; margin-top: 6px; }
|
| 259 |
+
.dc-mcp-note { font-size: .9rem; margin: 2px 0 8px; }
|
| 260 |
+
"""
|
| 261 |
|
| 262 |
+
HERO = f"""
|
| 263 |
+
<div class="dc-hero">
|
| 264 |
+
<h1><span class="amp">⚡</span> DC Hub — Power Index</h1>
|
| 265 |
+
<p class="sub"><strong>Can you actually get power to build a data center here?</strong>
|
| 266 |
+
Live 0–100 power-availability scores for 311 U.S. + global markets, with a verdict,
|
| 267 |
+
power cost, and modeled time-to-power — from <a href="https://dchub.cloud">dchub.cloud</a>.</p>
|
| 268 |
+
<div class="dc-chips">
|
| 269 |
+
<span class="dc-chip build">🟢 BUILD ≥ 60</span>
|
| 270 |
+
<span class="dc-chip caution">🟡 CAUTION 30–59</span>
|
| 271 |
+
<span class="dc-chip avoid">🔴 AVOID < 30</span>
|
| 272 |
+
<span class="dc-chip">311 markets</span>
|
| 273 |
+
<span class="dc-chip">21,900+ facilities · 4,900+ verified</span>
|
| 274 |
+
<span class="dc-chip">live grid telemetry</span>
|
| 275 |
+
<span class="dc-chip">1,400+ tracked deals</span>
|
| 276 |
+
<span class="dc-chip">CC-BY-4.0</span>
|
| 277 |
+
</div>
|
| 278 |
+
</div>
|
| 279 |
"""
|
| 280 |
|
| 281 |
+
CLAUDE_CODE_SNIPPET = f"""# This Space (7 tools, free)
|
| 282 |
+
claude mcp add --transport sse dchub-power-index {SPACE_MCP}
|
| 283 |
+
|
| 284 |
+
# Full DC Hub MCP (74 tools; 10 calls/day free, no key needed)
|
| 285 |
+
claude mcp add --transport http dchub {FULL_MCP}"""
|
| 286 |
+
|
| 287 |
+
JSON_SNIPPET = f"""{{
|
| 288 |
+
"mcpServers": {{
|
| 289 |
+
"dchub-power-index": {{ "url": "{SPACE_MCP}" }},
|
| 290 |
+
"dchub": {{ "url": "{FULL_MCP}" }}
|
| 291 |
+
}}
|
| 292 |
+
}}"""
|
| 293 |
+
|
| 294 |
+
SMOLAGENTS_SNIPPET = f"""from smolagents import CodeAgent, InferenceClientModel
|
| 295 |
+
from smolagents.mcp_client import MCPClient
|
| 296 |
+
|
| 297 |
+
with MCPClient({{"url": "{SPACE_MCP}"}}) as tools:
|
| 298 |
+
agent = CodeAgent(tools=tools, model=InferenceClientModel())
|
| 299 |
+
agent.run("Which U.S. market should I build a 100MW data center in?")"""
|
| 300 |
+
|
| 301 |
+
|
| 302 |
+
with gr.Blocks(title="DC Hub — Power Index",
|
| 303 |
+
theme=gr.themes.Soft(primary_hue="amber", neutral_hue="slate"),
|
| 304 |
+
css=CSS) as demo:
|
| 305 |
+
gr.HTML(HERO)
|
| 306 |
+
|
| 307 |
+
with gr.Accordion("🔌 Connect via MCP — Claude Code · Claude Desktop · Cursor · smolagents",
|
| 308 |
+
open=False):
|
| 309 |
+
gr.Markdown(
|
| 310 |
+
f"<p class='dc-mcp-note'>This Space <strong>is an MCP server</strong> "
|
| 311 |
+
f"(7 tools) at <code>{SPACE_MCP}</code>. The full DC Hub MCP — "
|
| 312 |
+
f"<strong>74 tools</strong>, real-time grid telemetry, fiber, gas, "
|
| 313 |
+
f"water, tax incentives, deal intelligence — is at "
|
| 314 |
+
f"<code>{FULL_MCP}</code> (10 calls/day free anonymous; mint a free "
|
| 315 |
+
f"key with its <code>claim_free_key</code> tool, or try it with zero "
|
| 316 |
+
f"setup at <a href='https://dchub.cloud/playground'>dchub.cloud/playground</a>).</p>")
|
| 317 |
+
with gr.Tabs():
|
| 318 |
+
with gr.Tab("Claude Code"):
|
| 319 |
+
gr.Code(CLAUDE_CODE_SNIPPET, language="shell", label="terminal")
|
| 320 |
+
with gr.Tab("Desktop · Cursor"):
|
| 321 |
+
gr.Code(JSON_SNIPPET, language="json", label="mcp config (JSON) — any MCP client")
|
| 322 |
+
with gr.Tab("smolagents"):
|
| 323 |
+
gr.Code(SMOLAGENTS_SNIPPET, language="python", label="python — HF Agents / smolagents")
|
| 324 |
+
|
| 325 |
+
with gr.Tab("⚡ Score a market"):
|
| 326 |
+
inp = gr.Textbox(label="U.S. data-center market", value="Northern Virginia",
|
| 327 |
+
placeholder="Northern Virginia, Phoenix, Columbus, Cheyenne…",
|
| 328 |
+
info="One market name — get the verdict, score, cost, and time-to-power.")
|
| 329 |
+
btn = gr.Button("Get DCPI score", variant="primary")
|
| 330 |
out = gr.Markdown()
|
| 331 |
+
btn.click(dcpi_score, inp, out)
|
| 332 |
+
inp.submit(dcpi_score, inp, out, api_name=False)
|
| 333 |
gr.Examples([["Northern Virginia"], ["Phoenix"], ["Columbus"],
|
| 334 |
["Cheyenne"], ["Dallas"], ["Omaha"]], inp)
|
| 335 |
+
with gr.Tab("🏆 Compare markets"):
|
| 336 |
cinp = gr.Textbox(label="Markets (comma-separated)",
|
| 337 |
+
value="Northern Virginia, Phoenix, Cheyenne, Omaha, Dallas",
|
| 338 |
+
info="Up to 8 U.S. markets — ranked best power-availability first.")
|
| 339 |
+
cbtn = gr.Button("Rank by power availability", variant="primary")
|
| 340 |
cout = gr.Markdown()
|
| 341 |
+
cbtn.click(compare_markets, cinp, cout)
|
| 342 |
+
cinp.submit(compare_markets, cinp, cout, api_name=False)
|
| 343 |
+
gr.Examples([["Northern Virginia, Phoenix, Cheyenne, Omaha, Dallas"],
|
| 344 |
+
["Atlanta, Columbus, Tulsa"],
|
| 345 |
+
["Dallas, Austin, San Antonio"]], cinp)
|
| 346 |
+
with gr.Tab("🌍 Grid scoreboard"):
|
| 347 |
+
gr.Markdown("Live ranked grids — US ISOs + GB, EU, Taiwan, Japan, South Korea, "
|
| 348 |
+
"Brazil: fuel mix, renewable share, and demand **right now**. "
|
| 349 |
+
"Greenest first.")
|
| 350 |
+
gout = gr.Code(language="json", label="live scoreboard")
|
| 351 |
gr.Button("Live grid scoreboard (greenest first)", variant="primary").click(
|
| 352 |
grid_scoreboard, [], gout)
|
| 353 |
+
with gr.Tab("🔎 Search facilities"):
|
| 354 |
+
with gr.Row():
|
| 355 |
+
s_q = gr.Textbox(label="Query", value="Ashburn",
|
| 356 |
+
placeholder="name / operator / location")
|
| 357 |
+
s_c = gr.Textbox(label="Country (ISO-2)", value="US", placeholder="US, GB, SG…")
|
| 358 |
+
s_s = gr.Textbox(label="State", placeholder="VA, TX…")
|
| 359 |
+
with gr.Row():
|
| 360 |
+
s_o = gr.Textbox(label="Operator", placeholder="Equinix, Digital Realty…")
|
| 361 |
+
s_m = gr.Number(label="Min capacity (MW)", value=0)
|
| 362 |
+
s_l = gr.Number(label="Limit", value=10)
|
| 363 |
+
sout = gr.Code(language="json", label="facilities")
|
| 364 |
gr.Button("Search 21,900+ facilities", variant="primary").click(
|
| 365 |
search_facilities, [s_q, s_c, s_s, s_o, s_m, s_l], sout)
|
| 366 |
+
with gr.Tab("📊 Rank markets"):
|
| 367 |
+
with gr.Row():
|
| 368 |
+
r_c = gr.Dropdown(["most_capacity", "cheapest_power", "most_operators",
|
| 369 |
+
"fastest"], value="most_capacity", label="Criteria")
|
| 370 |
+
r_r = gr.Dropdown(["us", "global", "canada", "eu", "apac", "americas"],
|
| 371 |
+
value="us", label="Region")
|
| 372 |
+
r_l = gr.Number(label="Limit", value=10)
|
| 373 |
+
rout = gr.Code(language="json", label="ranking")
|
| 374 |
gr.Button("Rank markets", variant="primary").click(
|
| 375 |
rank_markets, [r_c, r_r, r_l], rout)
|
| 376 |
+
with gr.Tab("🔌 Interconnection queue"):
|
| 377 |
q_i = gr.Dropdown(["", "ERCOT", "PJM", "MISO", "CAISO", "SPP", "NYISO",
|
| 378 |
+
"ISONE"], value="", label="ISO",
|
| 379 |
+
info="How much capacity is waiting to connect. Empty = national overview.")
|
| 380 |
+
qout = gr.Code(language="json", label="queue intelligence")
|
| 381 |
gr.Button("Queue intelligence", variant="primary").click(
|
| 382 |
interconnection_queue, [q_i], qout)
|
| 383 |
+
with gr.Tab("💸 Hyperscaler deals"):
|
| 384 |
+
d_l = gr.Number(label="Limit", value=10,
|
| 385 |
+
info="Most recent hyperscaler / AI-capex deals from the 1,400+ tracker.")
|
| 386 |
+
dout = gr.Code(language="json", label="deals")
|
| 387 |
gr.Button("Recent AI-capex deals", variant="primary").click(
|
| 388 |
hyperscaler_deals, [d_l], dout)
|
| 389 |
+
|
| 390 |
+
gr.HTML(
|
| 391 |
+
f"<div class='dc-foot'>Data: <a href='https://dchub.cloud'>DC Hub</a>, CC-BY-4.0 — "
|
| 392 |
+
f"the live infrastructure data layer for AI agents · "
|
| 393 |
+
f"<a href='{API}/playground'>playground</a> · "
|
| 394 |
+
f"<a href='{API}/signup'>free key</a></div>")
|
| 395 |
|
| 396 |
if __name__ == "__main__":
|
| 397 |
# mcp_server=True exposes all 7 tools as MCP tools at /gradio_api/mcp/sse —
|
| 398 |
# usable by HF Agents, smolagents, and any MCP client.
|
| 399 |
+
demo.launch(mcp_server=True)
|