File size: 6,023 Bytes
a3c5476
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
"""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)