Spaces:
Running
Running
| """DC Hub — Power Index demo + MCP server (Hugging Face Space). | |
| A live demo of the DC Hub Power Index (DCPI) that ALSO runs as an MCP server | |
| (launch(mcp_server=True)) so Hugging Face Agents / smolagents and any MCP client | |
| can query it. The complete DC Hub MCP — 47 tools across 21,000+ data-center | |
| facilities, real-time grid telemetry, fiber, gas, and 2,000+ M&A deals — lives at | |
| https://dchub.cloud/mcp. Connect that for the full dataset (10 calls/day free). | |
| """ | |
| import requests | |
| import gradio as gr | |
| API = "https://dchub.cloud" | |
| FULL_MCP = "https://dchub.cloud/mcp" | |
| TIMEOUT = 20 | |
| def _verdict(score): | |
| try: | |
| s = float(score) | |
| except (TypeError, ValueError): | |
| return "—" | |
| if s >= 60: | |
| return "🟢 BUILD" | |
| if s >= 30: | |
| return "🟡 CAUTION" | |
| return "🔴 AVOID" | |
| def _slug(market): | |
| return (market or "").strip().lower().replace(",", "").replace(" ", "-") | |
| def dcpi_score(market: str) -> str: | |
| """Get the DC Hub Power Index (DCPI) for a U.S. data-center market: a 0-100 | |
| power-availability score with a BUILD / CAUTION / AVOID verdict, average power | |
| cost (cents/kWh), and modeled time-to-power (months). Answers "can I actually | |
| get power to build a data center in this market, and how soon?". | |
| Args: | |
| market: A U.S. market name, e.g. "Northern Virginia", "Phoenix", "Columbus", | |
| "Dallas", "Atlanta", "Cheyenne", "Omaha", "Tulsa". | |
| """ | |
| try: | |
| r = requests.get(f"{API}/api/v1/dcpi/scores/{_slug(market)}", timeout=TIMEOUT) | |
| if r.status_code == 404: | |
| return (f"No DCPI data for **{market}**. Try a major U.S. market — Northern " | |
| f"Virginia, Phoenix, Columbus, Dallas, Atlanta, Cheyenne, Omaha, Tulsa.") | |
| r.raise_for_status() | |
| d = r.json() | |
| score = d.get("composite_score") | |
| ttp = d.get("queue_wait_months") | |
| ttp_s = f"~{int(ttp)} months" if isinstance(ttp, (int, float)) else "n/a" | |
| return ( | |
| f"### {d.get('market_name', market.title())} " | |
| f"({d.get('state', '')}, {d.get('iso', '')}) — DC Hub Power Index\n" | |
| f"- **Verdict: {_verdict(score)}** · composite **{score}/100**\n" | |
| f"- Modeled time-to-power: **{ttp_s}**\n" | |
| f"- Avg power cost: **{d.get('avg_kwh_cents', '?')} ¢/kWh**\n" | |
| f"- Excess-power headroom: {d.get('excess_power_score', '?')}/100 · " | |
| f"grid constraint: {d.get('constraint_score', '?')}/100\n\n" | |
| f"_Modeled estimate from public ISO/EIA/queue data · DC Hub (dchub.cloud) · CC-BY-4.0._\n\n" | |
| f"_Full grid headroom, interconnection queue, fiber + 47 tools: connect the DC Hub MCP → **{FULL_MCP}**._" | |
| ) | |
| except Exception as e: | |
| return f"DC Hub lookup failed ({e}). Query the full live MCP at {FULL_MCP}." | |
| def compare_markets(markets: str) -> str: | |
| """Rank several U.S. data-center markets by the DC Hub Power Index (DCPI), | |
| best power-availability (BUILD) first, to decide where to build. | |
| Args: | |
| markets: Comma-separated market names, e.g. | |
| "Northern Virginia, Phoenix, Cheyenne, Omaha". | |
| """ | |
| rows = [] | |
| for m in [x.strip() for x in (markets or "").split(",") if x.strip()][:8]: | |
| try: | |
| r = requests.get(f"{API}/api/v1/dcpi/scores/{_slug(m)}", timeout=TIMEOUT) | |
| if r.status_code == 200: | |
| d = r.json() | |
| rows.append((float(d.get("composite_score") or 0), | |
| d.get("market_name", m.title()), | |
| d.get("avg_kwh_cents"), d.get("queue_wait_months"))) | |
| except Exception: | |
| pass | |
| if not rows: | |
| return "No DCPI data for those markets. Try major U.S. metros." | |
| rows.sort(reverse=True) | |
| out = ["### DCPI ranking — best power-availability first\n"] | |
| for s, name, cost, ttp in rows: | |
| ttp_s = f"~{int(ttp)}mo" if isinstance(ttp, (int, float)) else "n/a" | |
| out.append(f"- {_verdict(s)} **{name}** — {s}/100 · {cost}¢/kWh · {ttp_s} to power") | |
| out.append(f"\n_Full ranking across 311 markets: DC Hub MCP → {FULL_MCP}._") | |
| return "\n".join(out) | |
| INTRO = f"""# ⚡ DC Hub — Power Index (live) | |
| **Can you actually get power to build a data center here?** DC Hub scores 311 | |
| U.S. + global markets on power availability — a 0-100 index with a | |
| **BUILD / CAUTION / AVOID** verdict, power cost, and modeled time-to-power. Live | |
| from [dchub.cloud](https://dchub.cloud). | |
| This Space is **also an MCP server** — point your Hugging Face Agent / MCP client | |
| at it, or connect the **full DC Hub MCP** (47 tools — 21,000+ facilities, real-time | |
| grid telemetry, fiber, gas, 2,000+ M&A deals) at **`{FULL_MCP}`** (10 calls/day | |
| free, no key needed). | |
| """ | |
| with gr.Blocks(title="DC Hub — Power Index", theme=gr.themes.Soft()) as demo: | |
| gr.Markdown(INTRO) | |
| with gr.Tab("Score a market"): | |
| inp = gr.Textbox(label="U.S. data-center market", value="Northern Virginia") | |
| out = gr.Markdown() | |
| gr.Button("Get DCPI score", variant="primary").click(dcpi_score, inp, out) | |
| gr.Examples([["Northern Virginia"], ["Phoenix"], ["Columbus"], | |
| ["Cheyenne"], ["Dallas"], ["Omaha"]], inp) | |
| with gr.Tab("Compare markets"): | |
| cinp = gr.Textbox(label="Markets (comma-separated)", | |
| value="Northern Virginia, Phoenix, Cheyenne, Omaha, Dallas") | |
| cout = gr.Markdown() | |
| gr.Button("Rank by power availability", variant="primary").click( | |
| compare_markets, cinp, cout) | |
| gr.Markdown( | |
| f"_Data: DC Hub (dchub.cloud), CC-BY-4.0 · the live infrastructure data " | |
| f"layer for AI agents · [connect the full MCP]({FULL_MCP}) · " | |
| f"[free key](https://dchub.cloud/signup)_") | |
| if __name__ == "__main__": | |
| # mcp_server=True exposes dcpi_score + compare_markets as MCP tools at | |
| # /gradio_api/mcp/sse — usable by HF Agents, smolagents, and any MCP client. | |
| demo.launch(mcp_server=True) | |