Spaces:
Running
Download README_DEV.md from thomwolf/hub-galaxy: direct link, hf CLI and curl.
- Browser
- Download file 6.48 kB
-
https://huggingface.co/spaces/thomwolf/hub-galaxy/resolve/main/README_DEV.md
- Command line
-
hf download hf://spaces/thomwolf/hub-galaxy/README_DEV.md
-
curl -L -o README_DEV.md https://huggingface.co/spaces/thomwolf/hub-galaxy/resolve/main/README_DEV.md
Hub galaxy Space: developer notes
A static site (Space SDK static, no server). Plain HTML + WebGL2 + one Web Worker, no build step for the front end.
index.html page + UI markup
css/style.css look (fonts bundled in fonts/: Inter variable, IBM Plex Mono 400/500/600)
js/app.js renderer (port of video/galaxy.js: soft specks, crisp bodies, halo variant "a", family cores,
star field, bloom pyramid, filmic composite), camera, picking, labels, UI
js/worker.js search + id resolution (all id data lives in the worker)
js/vendor/fzstd.js zstd decoder (MIT, 8 kB) for the id buckets
data/ generated by build/build_data.py (below)
build/build_data.py data build (deterministic)
build/shoot.js local test: static server + headless Chrome (SwiftShader) + screenshots
Rebuild the data
From the repository root (state-of-os-video/), about 2 minutes (most of it is zstd -19 on the id buckets):
source/.venv/bin/python -I space/build/build_data.py
Inputs, read only: video/galaxy/{pos.f32,birth.f32,meta.u8,families.json,anchors.json,labels.json,stats.json} and
source/raw/hub-stats-raw/models_slim.parquet (columns id, createdAt, likes). The script rebuilds the
birth-sorted order exactly like source/build_galaxy/build.py (lexsort((row, fractional_year(createdAt)))) and
asserts that it matches birth.f32, the ids in labels.json and the likesLog byte of meta.u8. Needs the zstd CLI.
gzip files are written with mtime=0, so a rebuild is byte-identical.
Index spaces
i: index in the film's birth-sorted arrays (video/galaxy/*).g: global index used everywhere in the Space. Points are split into layers;gruns through layer 0, then layer 1, and so on, and inside each layer points stay in birth order. So "points born by date d" is a prefix of each layer, and the renderer draws each layer with onedrawArrays(0, k).
Layers (data/points-L.bin.gz)
| L | kind | points | content |
|---|---|---|---|
| 0 | preview | 200,000 | every tree root, every model with >= 100 likes, the 73 anchors, plus a hash-uniform sample of the rest. Drawn first (1.25 MB). |
| 1 | family | 859,972 | every remaining point with a top-255 family index. Always drawn. |
| 2-4 | dust | ~742k each | the remaining dust (no top-255 family), split in 3 hash-interleaved layers. Dropped on slow GPUs. |
Each file is gzip of a planar little-endian buffer for its n points:
x int16[n] | y int16[n] | z int16[n] | meta uint8[4n]. Position = int16 * posScale (1100/32767 galaxy units,
0.034 units per step). meta is the film's 4 bytes [familyIdx, countryIdx, flags, likesLog] (see video/galaxy/README.md).
Birth is not stored per point. manifest.layers[L] has day0 and counts[] = number of points born on each UTC day
(day = days since 2022-01-01), from day0 on. The client rebuilds the per-point birth (day + (rank in day + 0.5)/count)
and the number of points born by any date. The counter sums all layers, so it is exact even when dust is not drawn.
data/manifest.json
{version, asOf, N, day0, ndays, posScale, nbucket, legacyDay, layers:[{file, n, offset (first g), bytes (decoded), day0, counts, kind}], anchors:[{id, label, g, family, likes, why}], families:[{idx, label, org, country, count, rootId, firstBirth, center, radius}] (top 255), stats:{inFamily, dust, robotics, families, legacy}}.
Ids (loaded lazily by the worker)
data/buckets.u8.gz: one byte per point ingorder, the id bucketfnv1a32(lowercase namespace) % 256. The namespace is the part before/(empty for legacy ids without one).data/ids/NNN.txt.zst: bucket NNN, one line per model in increasingg:idorid\tlikes(likes omitted when 0). zstd -19, decoded by fzstd. 256 files, 31.4 MB in total, 90 to 630 kB each.- g -> id: bucket
b = B[g], rankk= number of points before g in that bucket (the worker builds per-bucket g lists once, 13 MB of Uint32 in the worker), linekof bucketb. - exact id -> g: hash the namespace, load that one bucket, find the line, map rank
kback tog. So exact lookup over all 3.29M ids costs one bucket download, not the whole table. data/top.txt.gz: autocomplete, the 50k most-liked models,id\tg\tlikesper line, sorted by likes. Substring search runs on this list (in the worker); exact ids outside it go through the buckets.data/labels.json.gz: ambient callout candidates from the film'slabels.json,[[g, id, score, robotics], ...].
The fetch helpers check magic bytes, so they work whether or not a server or CDN already decoded the gzip.
Rendering notes
- One VAO per layer: three
SHORTattributes into the planar position buffer, a float birth buffer,uvec4meta. - Picking: on hover (throttled to one pass per 120 ms, only when the pointer rests), the visible set is drawn again with a
pick shader into an RGBA8 + depth target, scissored to a 19x19 px window under the cursor (33x33 on touch). The colour is
g + 1, nearest depth wins, and the hit nearest the cursor is taken. No CPU scan of the points. - The GL scene is only re-rendered when the camera, date, mode or data change. The 2D overlay (labels, markers) runs every frame.
- Tier probe: after layers 0 and 1, 3 frames are timed (readPixels forces a GPU sync) and extrapolated to the dust layers.
high= all 3 dust layers,mid= 1 or 2,low= none plus 1x pixel ratio. Undrawn dust layers are not downloaded (a search that lands in one loads it on demand). Brightness is renormalised so a decimated galaxy keeps the same look. - URL params:
?tier=high|mid|lowforces a tier,?debugexposeswindow.APP(used by build/shoot.js).
Test locally
node space/build/shoot.js # all scenarios -> space/screenshots/*.png
node space/build/shoot.js only=01-initial,10-selftest
It serves space/ on 127.0.0.1 (random port) and launches /usr/bin/google-chrome headless with its own temp profile,
the pipe transport (no debugging port, so it never touches a Chrome on 9222) and --use-angle=swiftshader --enable-unsafe-swiftshader. puppeteer-core is loaded from video/node_modules. 10-selftest checks g -> id and
id -> g through the worker against values computed in Python, and a GPU pick round trip.
For a manual look: cd space && python3 -m http.server 8000 --bind 127.0.0.1, then open http://127.0.0.1:8000/.