File size: 21,550 Bytes
7cec2a1
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
361bd80
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
7cec2a1
361bd80
 
 
7cec2a1
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
361bd80
7cec2a1
 
361bd80
7cec2a1
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
361bd80
 
 
 
 
 
 
 
 
 
7cec2a1
 
 
 
90c56e1
7cec2a1
361bd80
 
 
 
 
 
 
 
90c56e1
361bd80
90c56e1
 
 
361bd80
90c56e1
 
 
 
 
7cec2a1
 
361bd80
 
7cec2a1
 
 
361bd80
 
7cec2a1
361bd80
7cec2a1
361bd80
7cec2a1
361bd80
7cec2a1
361bd80
7cec2a1
 
 
 
361bd80
7cec2a1
 
 
 
 
 
361bd80
7cec2a1
 
 
 
361bd80
7cec2a1
361bd80
7cec2a1
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
361bd80
 
 
 
 
7cec2a1
 
 
 
 
90c56e1
 
361bd80
90c56e1
 
361bd80
7cec2a1
 
 
 
 
 
361bd80
90c56e1
7cec2a1
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
361bd80
7cec2a1
 
 
 
 
 
 
 
 
 
 
90c56e1
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
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
"""
Build Small Hackathon β€” Registration Dashboard
================================================
A sponsor-facing dashboard that reads the private org registration dataset and
renders aggregate, anonymized charts.

PRIVACY: This app NEVER displays names, emails, HF usernames, or project
descriptions. Only counts and distributions are shown, so the link is safe to
share with sponsors without exposing any registrant's personal information.

DEPLOY (Hugging Face Spaces, Gradio SDK):
  1. Add this app.py + requirements.txt + README.md to a new Space.
  2. In the Space's Settings β†’ Variables and secrets, add a secret:
        HF_TOKEN = <a token with READ access to the build-small-hackathon org>
  3. (Optional) add DASHBOARD_PASSWORD = <some shared password> to gate access
     when the Space is public. Sponsors then log in with user `sponsor` + that
     password. Leave it unset for an open dashboard.
"""

import os
import ast
import time
import tempfile
import logging
from collections import Counter

import pandas as pd
import plotly.graph_objects as go
from plotly.subplots import make_subplots
import gradio as gr
from huggingface_hub import HfApi

logging.basicConfig(level=logging.INFO)
logger = logging.getLogger(__name__)

DATASET_NAME = "build-small-hackathon/build-small-hackathon-registrations"
HF_TOKEN = os.environ.get("HF_TOKEN")
DASHBOARD_PASSWORD = os.environ.get("DASHBOARD_PASSWORD")  # optional gate

# Columns we deliberately never surface in any aggregate (PII / free text).
PII_COLUMNS = ["full_name", "email", "hf_username", "project_description"]

# ---------------------------------------------------------------- brand tokens
CREAM = "#fbf6e8"
INK = "#2a1d0a"
INK_SOFT = "#6b4423"
GREEN = "#4a7c2e"
GREEN_DEEP = "#2d5016"
GREEN_MID = "#6b9039"
GREEN_LIGHT = "#9bc466"
AMBER = "#c9b072"
RUST = "#b5651d"
GRID = "rgba(139,111,71,0.16)"
SEQ = [GREEN, GREEN_MID, GREEN_LIGHT, AMBER, RUST, INK_SOFT, GREEN_DEEP]

BODY_FONT = "Spline Sans, -apple-system, BlinkMacSystemFont, sans-serif"
DISPLAY_FONT = "Fraunces, Georgia, serif"

HEAD = """
<link rel="preconnect" href="https://fonts.googleapis.com">
<link rel="preconnect" href="https://fonts.gstatic.com" crossorigin>
<link href="https://fonts.googleapis.com/css2?family=Fraunces:opsz,wght@9..144,400;9..144,600;9..144,900&family=Spline+Sans:wght@400;500;600;700&display=swap" rel="stylesheet">
"""

# ---------------------------------------------------------------- data loading
_CACHE = {"df": None, "ts": 0.0}
CACHE_TTL = 300  # seconds β€” avoids hammering the Hub when several viewers open it


def _strip_pii(df):
    """Drop PII so it can never leak into a chart, tooltip, or table."""
    return df.drop(columns=[c for c in PII_COLUMNS if c in df.columns])


def fetch_dataframe(force=False):
    """Download the dataset's train parquet directly (force=True ignores cache).

    Mirrors how the registration Space itself reads the data, which is robust
    against stale dataset-script caches. PII is stripped on every return path.
    """
    now = time.time()
    if not force and _CACHE["df"] is not None and (now - _CACHE["ts"]) < CACHE_TTL:
        return _strip_pii(_CACHE["df"])

    api = HfApi(token=HF_TOKEN)
    files = api.list_repo_files(DATASET_NAME, repo_type="dataset")
    parquet_files = [f for f in files if f.endswith(".parquet") and "train" in f]
    if not parquet_files:
        raise RuntimeError("No train parquet file found in the dataset.")

    with tempfile.TemporaryDirectory() as tmp:
        path = api.hf_hub_download(
            repo_id=DATASET_NAME,
            filename=parquet_files[0],
            repo_type="dataset",
            cache_dir=tmp,
            force_download=True,
            token=HF_TOKEN,
        )
        df = pd.read_parquet(path)

    df = _strip_pii(df)
    _CACHE["df"] = df
    _CACHE["ts"] = now
    return _strip_pii(df)


# ---------------------------------------------------------------- small helpers
def parse_list(val):
    """The app stores some fields as stringified lists, e.g. "['First timer']"."""
    if isinstance(val, list):
        return val
    if isinstance(val, str) and val.strip().startswith("["):
        try:
            parsed = ast.literal_eval(val)
            return parsed if isinstance(parsed, list) else [str(parsed)]
        except (ValueError, SyntaxError):
            return []
    if val:
        return [str(val)]
    return []


def short(label):
    """Trim the long ' β€” explanation' tails off choice labels for chart axes."""
    if not isinstance(label, str):
        return str(label)
    for sep in ("β€”", " - "):
        if sep in label:
            return label.split(sep)[0].strip()
    return label.strip()


def track_label(label):
    s = str(label)
    if "Backyard" in s:
        return "🏑 Backyard AI"
    if "Thousand Token Wood" in s:
        return "πŸ„ Thousand Token Wood"
    if "Both" in s:
        return "Both tracks"
    return "Undecided"


# ---------------------------------------------------------------- figure styling
def style(fig, height=320, legend=False):
    fig.update_layout(
        height=height,
        paper_bgcolor=CREAM,
        plot_bgcolor=CREAM,
        font=dict(family=BODY_FONT, size=13, color=INK),
        title=dict(font=dict(family=DISPLAY_FONT, size=18, color=GREEN_DEEP), x=0.02, xanchor="left"),
        margin=dict(l=12, r=18, t=46, b=12),
        showlegend=legend,
        legend=dict(font=dict(size=11), bgcolor="rgba(0,0,0,0)"),
        hoverlabel=dict(bgcolor=GREEN_DEEP, font=dict(color=CREAM, family=BODY_FONT)),
        colorway=SEQ,
    )
    fig.update_xaxes(showgrid=False, zeroline=False, linecolor=GRID, tickcolor=GRID)
    fig.update_yaxes(showgrid=True, gridcolor=GRID, zeroline=False, linecolor=GRID, tickcolor=GRID)
    return fig


def empty_fig(msg="No data yet"):
    fig = go.Figure()
    fig.add_annotation(text=msg, showarrow=False, font=dict(family=DISPLAY_FONT, size=18, color=INK_SOFT))
    fig.update_xaxes(visible=False)
    fig.update_yaxes(visible=False)
    return style(fig, height=260)


def hbar(counts, title, color=GREEN, height=320):
    """Horizontal bar from a {label: count} mapping, largest on top."""
    if not counts:
        return empty_fig()
    items = sorted(counts.items(), key=lambda kv: kv[1])
    labels = [k for k, _ in items]
    values = [v for _, v in items]
    fig = go.Figure(go.Bar(
        x=values, y=labels, orientation="h",
        marker=dict(color=color, line=dict(color=GREEN_DEEP, width=0.5)),
        text=values, textposition="outside",
        cliponaxis=False,
        hovertemplate="%{y}: %{x}<extra></extra>",
    ))
    fig.update_layout(title=title)
    fig = style(fig, height=height)
    fig.update_xaxes(showgrid=True, gridcolor=GRID)
    fig.update_yaxes(showgrid=False)
    return fig


def donut(counts, title, color_map=None, height=320):
    if not counts:
        return empty_fig()
    labels = list(counts.keys())
    values = list(counts.values())
    colors = [color_map.get(l) for l in labels] if color_map else SEQ
    fig = go.Figure(go.Pie(
        labels=labels, values=values, hole=0.58,
        marker=dict(colors=colors, line=dict(color=CREAM, width=2)),
        textinfo="percent", textfont=dict(family=BODY_FONT, size=12, color=CREAM),
        hovertemplate="%{label}: %{value} (%{percent})<extra></extra>",
        sort=False,
    ))
    fig.update_layout(title=title)
    return style(fig, height=height, legend=True)


# ---------------------------------------------------------------- chart builders
def fig_momentum(df):
    if df.empty or "timestamp" not in df.columns:
        return empty_fig()
    dt = pd.to_datetime(df["timestamp"], errors="coerce").dropna()
    if dt.empty:
        return empty_fig()
    daily = dt.dt.floor("D").value_counts().sort_index()
    cumulative = daily.cumsum()

    fig = make_subplots(specs=[[{"secondary_y": True}]])
    fig.add_trace(go.Bar(
        x=daily.index, y=daily.values, name="Per day",
        marker=dict(color=GREEN_LIGHT), opacity=0.85,
        hovertemplate="%{x|%b %d}: %{y} registrations<extra></extra>",
    ), secondary_y=False)
    fig.add_trace(go.Scatter(
        x=cumulative.index, y=cumulative.values, name="Cumulative",
        mode="lines", line=dict(color=GREEN_DEEP, width=3, shape="spline"),
        fill="tozeroy", fillcolor="rgba(45,80,22,0.10)",
        hovertemplate="%{x|%b %d}: %{y} total<extra></extra>",
    ), secondary_y=True)
    fig.update_layout(title="Registration momentum", bargap=0.25)
    fig = style(fig, height=380, legend=True)
    fig.update_yaxes(title_text="Per day", secondary_y=False, showgrid=False)
    fig.update_yaxes(title_text="Cumulative", secondary_y=True, gridcolor=GRID)
    return fig


def fig_heard(df):
    if df.empty or "how_heard" not in df.columns:
        return empty_fig()
    counts = df["how_heard"].dropna().map(short).value_counts().to_dict()
    return hbar(counts, "Where builders heard about us", color=GREEN, height=380)


def fig_track(df):
    if df.empty or "track_interest" not in df.columns:
        return empty_fig()
    counts = df["track_interest"].dropna().map(track_label).value_counts().to_dict()
    cmap = {
        "🏑 Backyard AI": GREEN,
        "πŸ„ Thousand Token Wood": RUST,
        "Both tracks": GREEN_MID,
        "Undecided": AMBER,
    }
    return donut(counts, "Track interest", color_map=cmap)


def fig_returning(df):
    if df.empty or "previous_participation" not in df.columns:
        return empty_fig()
    gradio_events = {"MCP 1st Birthday", "Agents & MCP Hackathon"}
    returning = first_time = other = 0
    for val in df["previous_participation"]:
        items = set(parse_list(val))
        if items & gradio_events:
            returning += 1
        elif "First timer" in items:
            first_time += 1
        else:
            other += 1
    counts = {
        "Returning Gradio builders": returning,
        "First-timers": first_time,
        "Other hackathon vets": other,
    }
    counts = {k: v for k, v in counts.items() if v}
    cmap = {
        "Returning Gradio builders": GREEN_DEEP,
        "First-timers": GREEN_LIGHT,
        "Other hackathon vets": AMBER,
    }
    return donut(counts, "Community make-up", color_map=cmap)


def fig_experience(df):
    if df.empty or "experience_level" not in df.columns:
        return empty_fig()
    order = ["Beginner", "Intermediate", "Advanced", "Expert"]
    raw = df["experience_level"].dropna().map(short)
    counts = raw.value_counts().to_dict()
    labels = [o for o in order if o in counts]
    values = [counts[o] for o in labels]
    fig = go.Figure(go.Bar(
        x=labels, y=values,
        marker=dict(color=[GREEN_LIGHT, GREEN_MID, GREEN, GREEN_DEEP][:len(labels)]),
        text=values, textposition="outside", cliponaxis=False,
        hovertemplate="%{x}: %{y}<extra></extra>",
    ))
    fig.update_layout(title="Developer experience")
    return style(fig, height=320)


def fig_usage(df):
    if df.empty or "gradio_usage" not in df.columns:
        return empty_fig()
    counts = df["gradio_usage"].dropna().map(short).value_counts().to_dict()
    return hbar(counts, "How they use Gradio today", color=GREEN_MID, height=320)


BADGE_ORDER = [
    "πŸ”Œ Off the Grid", "🎯 Well-Tuned", "🎨 Off-Brand",
    "πŸ¦™ Llama Champion", "πŸ“‘ Sharing is Caring", "πŸ““ Field Notes",
]


def fig_quests(df):
    if df.empty or "bonus_quests" not in df.columns:
        return empty_fig()
    counter = Counter()
    for val in df["bonus_quests"]:
        for item in parse_list(val):
            counter[short(item)] += 1
    counts = {k: counter.get(k, 0) for k in BADGE_ORDER if counter.get(k, 0)}
    return hbar(counts, "Bonus-quest appetite", color=RUST, height=340)


MODEL_FAMILIES = {
    "Qwen": ["qwen"],
    "Llama": ["llama"],
    "Gemma": ["gemma"],
    "SmolLM": ["smollm", "smol-lm", "smol lm"],
    "Phi": ["phi-", "phi3", "phi4", "phi-3", "phi-4", "phi2", "phi "],
    "Mistral": ["mistral", "ministral"],
    "MiniCPM": ["minicpm", "mini-cpm", "mini cpm"],
    "DeepSeek": ["deepseek"],
    "Granite": ["granite"],
    "Falcon": ["falcon"],
    "GPT-OSS": ["gpt-oss", "gptoss"],
}


def fig_models(df):
    if df.empty or "planned_small_model" not in df.columns:
        return empty_fig()
    counter = Counter()
    for val in df["planned_small_model"].dropna():
        text = str(val).lower()
        if not text.strip():
            continue
        for family, keys in MODEL_FAMILIES.items():
            if any(k in text for k in keys):
                counter[family] += 1
    counts = dict(counter)
    if not counts:
        return empty_fig("No models named yet")
    return hbar(counts, "Most-mentioned model families", color=GREEN, height=340)


# ---------------------------------------------------------------- KPI + footer
def kpi_card(label, value, sub, delay):
    return f"""
    <div class="bsh-kpi" style="animation-delay:{delay}ms">
        <div class="bsh-kpi-label">{label}</div>
        <div class="bsh-kpi-value">{value}</div>
        <div class="bsh-kpi-sub">{sub}</div>
    </div>"""


def pct(part, whole):
    return f"{round(100 * part / whole)}%" if whole else "β€”"


def build_top(df):
    """Banner on the left + the four KPI tiles stacked in a column on the right."""
    if df is None or len(df) == 0:
        cards = (
            kpi_card("Total registrations", "β€”", "loading…", 0)
            + kpi_card("Returning Gradio builders", "β€”", "", 90)
            + kpi_card("Industry developers", "β€”", "", 180)
            + kpi_card("Advanced &amp; expert", "β€”", "", 270)
        )
    else:
        total = len(df)
        gradio_events = {"MCP 1st Birthday", "Agents & MCP Hackathon"}
        returning = sum(1 for v in df.get("previous_participation", []) if set(parse_list(v)) & gradio_events)

        usage = df.get("gradio_usage", pd.Series(dtype=str)).fillna("")
        industry = int(usage.str.startswith("Professional").sum())

        exp = df.get("experience_level", pd.Series(dtype=str)).fillna("")
        advanced = int(exp.str.startswith(("Advanced", "Expert")).sum())

        cards = (
            kpi_card("Total registrations", f"{total:,}", "builders signed up", 0)
            + kpi_card("Returning Gradio builders", f"{returning:,}", f"{pct(returning, total)} came back for more", 90)
            + kpi_card("Industry developers", pct(industry, total), f"{industry:,} build with Gradio at work", 180)
            + kpi_card("Advanced &amp; expert", pct(advanced, total), f"{advanced:,} seasoned AI devs", 270)
        )

    banner = f'<div class="bsh-banner-wrap"><img src="{BANNER}" alt="Build Small Hackathon" /></div>'
    kpi_col = f'<div class="bsh-kpi-col">{cards}</div>'
    return f'<div class="bsh-top">{banner}{kpi_col}</div>'


def build_footer(df):
    total = len(df)
    updated = time.strftime("%b %d, %Y Β· %H:%M UTC", time.gmtime())
    return f"""
    <div class="bsh-footer">
        Aggregated &amp; anonymized β€” no personal information is shown Β·
        <b>N = {total:,}</b> registrations Β· Last refreshed {updated}
    </div>"""


# ---------------------------------------------------------------- orchestration
def build_everything():
    try:
        df = fetch_dataframe()
    except Exception as e:
        logger.error(f"Data load failed: {e}")
        msg = empty_fig("Could not load data β€” check the HF_TOKEN secret")
        warn = ('<div class="bsh-footer" style="color:#8b2e25">'
                'Could not load the dataset. Confirm the Space has an <code>HF_TOKEN</code> '
                'secret with read access to the org.</div>')
        return (build_top(None), msg, msg, msg, msg, msg, msg, msg, msg, warn)

    return (
        build_top(df),
        fig_momentum(df),
        fig_heard(df),
        fig_track(df),
        fig_returning(df),
        fig_experience(df),
        fig_usage(df),
        fig_quests(df),
        fig_models(df),
        build_footer(df),
    )


# ---------------------------------------------------------------- styling (CSS)
CUSTOM_CSS = """
.gradio-container { background: #f3ead6 !important; font-family: 'Spline Sans', sans-serif !important; }
footer { display: none !important; }

/* Top row: banner on the left, KPI tiles stacked on the right */
.bsh-top {
    display: flex;
    gap: 12px;
    align-items: stretch;
    margin-bottom: 4px;
}
.bsh-banner-wrap {
    flex: 2 1 0;
    min-width: 0;
    border-radius: 16px;
    overflow: hidden;
    border: 1px solid rgba(139,111,71,0.30);
    box-shadow: 0 4px 18px rgba(45,80,22,0.16);
    line-height: 0;
}
.bsh-banner-wrap img { width: 100%; height: auto; display: block; }
.bsh-kpi-col {
    flex: 1 1 0;
    min-width: 0;
    display: flex;
    flex-direction: column;
    gap: 10px;
}

/* Header text strip β€” sits below the banner/KPI row (reduced height) */
.bsh-strip {
    position: relative; overflow: hidden;
    background: #fbf6e8; border: 1px solid rgba(139,111,71,0.30);
    border-radius: 14px; padding: 8px 20px; margin: 8px 0 2px;
    box-shadow: 0 2px 8px rgba(45,80,22,0.08);
}
.bsh-strip::before {
    content: ""; position: absolute; left: 0; top: 0; bottom: 0; width: 4px;
    background: linear-gradient(180deg, #4a7c2e, #2d5016);
}
.bsh-eyebrow {
    font-size: 10px; letter-spacing: 2px; text-transform: uppercase;
    color: #6b4423; font-weight: 600; margin-bottom: 1px;
}
.bsh-h1 {
    font-family: 'Fraunces', Georgia, serif; font-weight: 900;
    font-size: clamp(18px, 2.6vw, 23px); color: #2d5016; line-height: 1.04;
    margin-bottom: 2px;
}
.bsh-sub { color: #6b4423; font-size: 12px; line-height: 1.35; max-width: 80ch; }

/* KPI cards (stacked in the right-hand column) */
.bsh-kpi {
    flex: 1 1 0;
    background: #fbf6e8; border: 1px solid rgba(139,111,71,0.30);
    border-radius: 14px; padding: 10px 16px;
    box-shadow: 0 2px 8px rgba(45,80,22,0.08);
    opacity: 0; transform: translateY(10px);
    animation: bshRise 0.55s cubic-bezier(.2,.7,.3,1) forwards;
    position: relative; overflow: hidden;
    display: flex; flex-direction: column; justify-content: center;
}
.bsh-kpi::before {
    content: ""; position: absolute; left: 0; top: 0; bottom: 0; width: 4px;
    background: linear-gradient(180deg, #4a7c2e, #2d5016);
}
.bsh-kpi-label {
    font-size: 10px; letter-spacing: 1.4px; text-transform: uppercase;
    color: #6b4423; font-weight: 600;
}
.bsh-kpi-value {
    font-family: 'Fraunces', Georgia, serif; font-weight: 900;
    font-size: 30px; color: #2d5016; line-height: 1.05; margin: 1px 0;
}
.bsh-kpi-sub { font-size: 11.5px; color: #6b4423; opacity: 0.85; }
@keyframes bshRise { to { opacity: 1; transform: translateY(0); } }

.bsh-section {
    font-family: 'Fraunces', Georgia, serif; font-weight: 600;
    color: #2d5016; font-size: 15px; letter-spacing: 0.3px;
    margin: 14px 0 2px; padding-left: 2px;
}
.bsh-section::before { content: "❋ "; color: #6b9039; }

.bsh-footer {
    text-align: center; font-size: 12px; color: #6b4423;
    margin: 16px 0 6px; opacity: 0.9;
}
.bsh-footer code {
    background: rgba(74,124,46,0.10); padding: 1px 6px; border-radius: 4px; font-size: 11px;
}

#bsh-refresh {
    background: linear-gradient(135deg, #4a7c2e, #2d5016) !important;
    color: #f5ecd9 !important; border: 1px solid #6b4423 !important;
    font-weight: 600 !important; border-radius: 10px !important;
}
#bsh-refresh:hover { filter: brightness(1.07); }

@media (max-width: 820px) {
    .bsh-top { flex-direction: column; }
    .bsh-kpi-col { display: grid; grid-template-columns: 1fr 1fr; }
    .bsh-kpi { flex: none; }
}
"""

BANNER = ("https://cdn-uploads.huggingface.co/production/uploads/"
          "60d2dc1007da9c17c72708f8/VhVvEN0e8oZKxjIzT9Qi0.png")

STRIP_HTML = """
<div class="bsh-strip">
    <div class="bsh-eyebrow">Registration Dashboard Β· Live Overview</div>
    <div class="bsh-h1">Build Small Hackathon</div>
    <div class="bsh-sub">Who's joining us in the woods β€” a live, anonymized read on the
    builders this event is reaching. June 5–15, 2026.</div>
</div>
"""

# ---------------------------------------------------------------- UI
with gr.Blocks(title="Build Small Hackathon β€” Dashboard") as demo:

    top = gr.HTML(build_top(None))
    gr.HTML(STRIP_HTML)

    with gr.Row():
        momentum = gr.Plot(label=None)

    with gr.Row():
        heard = gr.Plot(label=None)

    gr.HTML('<div class="bsh-section">Engagement</div>')
    with gr.Row():
        track = gr.Plot(label=None)
        returning = gr.Plot(label=None)

    gr.HTML('<div class="bsh-section">Audience quality</div>')
    with gr.Row():
        experience = gr.Plot(label=None)
        usage = gr.Plot(label=None)

    gr.HTML('<div class="bsh-section">Technical appetite</div>')
    with gr.Row():
        quests = gr.Plot(label=None)
        models = gr.Plot(label=None)

    footer = gr.HTML()

    with gr.Row():
        refresh = gr.Button("↻ Refresh data", elem_id="bsh-refresh", scale=0)

    outputs = [top, momentum, heard, track, returning, experience, usage, quests, models, footer]
    demo.load(fn=build_everything, inputs=None, outputs=outputs)
    refresh.click(fn=lambda: build_everything(), inputs=None, outputs=outputs)


if __name__ == "__main__":
    auth = ("sponsor", DASHBOARD_PASSWORD) if DASHBOARD_PASSWORD else None
    demo.launch(
        css=CUSTOM_CSS,
        head=HEAD,
        auth=auth,
        theme=gr.themes.Soft(primary_hue="green", secondary_hue="amber", neutral_hue="stone"),
    )