Spaces:
Running on Zero
Running on Zero
Shared start page, workspace and same-tab sign-in
Browse files- README.md +292 -288
- app.py +377 -370
- brand.css +293 -0
- brand_theme.py +61 -0
- hf_login.py +54 -37
- style.css +203 -218
README.md
CHANGED
|
@@ -1,288 +1,292 @@
|
|
| 1 |
-
---
|
| 2 |
-
title: Automatic Token Generation
|
| 3 |
-
emoji: 🌊
|
| 4 |
-
colorFrom: green
|
| 5 |
-
colorTo: gray
|
| 6 |
-
sdk: gradio
|
| 7 |
-
sdk_version: 5.49.1
|
| 8 |
-
app_file: app.py
|
| 9 |
-
pinned: false
|
| 10 |
-
python_version: '3.12'
|
| 11 |
-
hf_oauth: true
|
| 12 |
-
---
|
| 13 |
-
|
| 14 |
-
# Automatic Token Generation
|
| 15 |
-
|
| 16 |
-
A prompt-free automatic-writing experiment. Load a public Hugging Face base model,
|
| 17 |
-
press **Begin**, and watch it generate from a special beginning token alone. No
|
| 18 |
-
written prompt, hidden literary instruction, or chat template is inserted. For
|
| 19 |
-
models without BOS, EOS is used as the initial document boundary. The initial
|
| 20 |
-
boundary is not displayed; generated special tokens are hidden in the prose but
|
| 21 |
-
remain visible in the inspector and count toward the token total.
|
| 22 |
-
|
| 23 |
-
## Run locally
|
| 24 |
-
|
| 25 |
-
Use Python 3.11–3.13. On Windows:
|
| 26 |
-
|
| 27 |
-
```powershell
|
| 28 |
-
powershell -ExecutionPolicy Bypass -File .\start.ps1
|
| 29 |
-
```
|
| 30 |
-
|
| 31 |
-
Open http://localhost:7860. The first model load requires internet access.
|
| 32 |
-
Dependencies and weights stay in `.venv` and `.model-cache` respectively.
|
| 33 |
-
CPU is supported; CUDA is used automatically when a compatible PyTorch build and
|
| 34 |
-
GPU are available. Start with SmolLM2-135M; larger models can be slow on CPU.
|
| 35 |
-
|
| 36 |
-
## Hugging Face Space
|
| 37 |
-
|
| 38 |
-
Create a **Gradio** Space and upload `app.py`, `engine.py`, `models.py`, `style.css`,
|
| 39 |
-
`gpu_runtime.py`, `hf_login.py`, `english_bias.py`, `representations.py`, `projection_axes.py`, `token_space.py`, `token_space.js`, `attention_view.py`, `requirements.txt`, and this `README.md`. The README contains the Space metadata.
|
| 40 |
-
The app detects Spaces and binds to `0.0.0.0:7860` there; local runs bind to localhost.
|
| 41 |
-
`FLOW_HOST` and `PORT` can override these defaults. No API token is
|
| 42 |
-
needed for the supported public, ungated models. Start with CPU Basic and a small
|
| 43 |
-
model; hardware determines the practical model size. This project is prepared for
|
| 44 |
-
Spaces but does not create or publish a remote Space automatically.
|
| 45 |
-
|
| 46 |
-
Run `python scripts/prepare_space.py` to create `outputs/let-it-flow-space.zip`.
|
| 47 |
-
Extract the archive and upload its
|
| 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 |
-
The
|
| 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 |
-
The
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
---
|
| 2 |
+
title: Automatic Token Generation
|
| 3 |
+
emoji: 🌊
|
| 4 |
+
colorFrom: green
|
| 5 |
+
colorTo: gray
|
| 6 |
+
sdk: gradio
|
| 7 |
+
sdk_version: 5.49.1
|
| 8 |
+
app_file: app.py
|
| 9 |
+
pinned: false
|
| 10 |
+
python_version: '3.12'
|
| 11 |
+
hf_oauth: true
|
| 12 |
+
---
|
| 13 |
+
|
| 14 |
+
# Automatic Token Generation
|
| 15 |
+
|
| 16 |
+
A prompt-free automatic-writing experiment. Load a public Hugging Face base model,
|
| 17 |
+
press **Begin**, and watch it generate from a special beginning token alone. No
|
| 18 |
+
written prompt, hidden literary instruction, or chat template is inserted. For
|
| 19 |
+
models without BOS, EOS is used as the initial document boundary. The initial
|
| 20 |
+
boundary is not displayed; generated special tokens are hidden in the prose but
|
| 21 |
+
remain visible in the inspector and count toward the token total.
|
| 22 |
+
|
| 23 |
+
## Run locally
|
| 24 |
+
|
| 25 |
+
Use Python 3.11–3.13. On Windows:
|
| 26 |
+
|
| 27 |
+
```powershell
|
| 28 |
+
powershell -ExecutionPolicy Bypass -File .\start.ps1
|
| 29 |
+
```
|
| 30 |
+
|
| 31 |
+
Open http://localhost:7860. The first model load requires internet access.
|
| 32 |
+
Dependencies and weights stay in `.venv` and `.model-cache` respectively.
|
| 33 |
+
CPU is supported; CUDA is used automatically when a compatible PyTorch build and
|
| 34 |
+
GPU are available. Start with SmolLM2-135M; larger models can be slow on CPU.
|
| 35 |
+
|
| 36 |
+
## Hugging Face Space
|
| 37 |
+
|
| 38 |
+
Create a **Gradio** Space and upload `app.py`, `engine.py`, `models.py`, `style.css`,
|
| 39 |
+
`brand.css`, `brand_theme.py`, `gpu_runtime.py`, `hf_login.py`, `english_bias.py`, `representations.py`, `projection_axes.py`, `token_space.py`, `token_space.js`, `attention_view.py`, `requirements.txt`, and this `README.md`. The README contains the Space metadata.
|
| 40 |
+
The app detects Spaces and binds to `0.0.0.0:7860` there; local runs bind to localhost.
|
| 41 |
+
`FLOW_HOST` and `PORT` can override these defaults. No API token is
|
| 42 |
+
needed for the supported public, ungated models. Start with CPU Basic and a small
|
| 43 |
+
model; hardware determines the practical model size. This project is prepared for
|
| 44 |
+
Spaces but does not create or publish a remote Space automatically.
|
| 45 |
+
|
| 46 |
+
Run `python scripts/prepare_space.py` to create `outputs/let-it-flow-space.zip`.
|
| 47 |
+
Extract the archive and upload its sixteen files to the root of your Gradio Space.
|
| 48 |
+
`brand.css`, `brand_theme.py` and `hf_login.py` are shared with Automatic Drawing and
|
| 49 |
+
Token Visualiser, so the three Spaces keep the same start page, workspace and sign-in.
|
| 50 |
+
|
| 51 |
+
## Token space
|
| 52 |
+
|
| 53 |
+
The opening screen shows sign-in (on ZeroGPU) and model selection, and follows the
|
| 54 |
+
browser's light or dark setting. Successful loading hides the picker
|
| 55 |
+
and reveals a viewport-filling 3D token view. The full generated text is retained in a
|
| 56 |
+
scrollable, resizable top overlay. A combined Start / Pause / Resume button sits in a
|
| 57 |
+
bottom overlay dock. Expand Settings, model & attention for the remaining controls.
|
| 58 |
+
The overlay fills the app viewport, including when embedded in the Space page. The round
|
| 59 |
+
↺ button at the bottom right (**Change model / sign in**) requests Stop if generation is
|
| 60 |
+
running and returns to the start page.
|
| 61 |
+
|
| 62 |
+
Each generated token appears at a fixed position derived from its input embedding.
|
| 63 |
+
A deterministic PCA is fitted to up to 2,048 evenly sampled vocabulary embeddings;
|
| 64 |
+
all vocabulary tokens use that same centered projection and scale. These are
|
| 65 |
+
stored token embeddings, not contextual activations or a map of thoughts. The
|
| 66 |
+
three projected axes have no named semantic meaning and lose information.
|
| 67 |
+
|
| 68 |
+
Drag to orbit, Shift-drag (or right-drag) to pan, and scroll to zoom from 0.15x
|
| 69 |
+
to 40x. Double-click a token to focus the camera on it; double-click the background
|
| 70 |
+
or use Reset camera to return to the overview. Click a token to inspect its ID,
|
| 71 |
+
generation position, and earlier embedding neighbours.
|
| 72 |
+
|
| 73 |
+
The View selector switches between Live (six-second fading trails) and History
|
| 74 |
+
(the last 512 token occurrences, retained even after Stop). Fading uses an independent
|
| 75 |
+
browser timer and wall-clock time; the renderer reconnects if the page replaces
|
| 76 |
+
the canvas. Repeated token snapshots never reset their fade timestamps.
|
| 77 |
+
|
| 78 |
+
Connections can show generation order (teal), embedding similarity (amber), or no
|
| 79 |
+
lines. Each token links to up to three distinct earlier token IDs with the highest
|
| 80 |
+
positive cosine similarity among the preceding 512 occurrences. Repeated IDs
|
| 81 |
+
are excluded from similarity links and the latest earlier occurrence represents
|
| 82 |
+
each ID. Similarity is computed in the full original embedding space, not from
|
| 83 |
+
the 3D projection. These are stored embedding relationships, not attention or
|
| 84 |
+
causal influence. History labels are reduced for dense views; click to inspect.
|
| 85 |
+
Retained history is bounded to 512 occurrences; the text retains the complete session.
|
| 86 |
+
The viewer uses a perspective 3D projection rendered on a local canvas, with no
|
| 87 |
+
external script or graphics-service dependency. Reduced-motion preferences disable
|
| 88 |
+
idle camera rotation. The full stream text in the top overlay remains available to copy
|
| 89 |
+
or export; probability details and secondary controls are in the lower accordion.
|
| 90 |
+
|
| 91 |
+
## Attention view
|
| 92 |
+
|
| 93 |
+
Capture attention is enabled by default. Choose Attention weights under Connections
|
| 94 |
+
(the default), then Begin. Purple directed lines show the eight highest measured
|
| 95 |
+
attention weights from the latest query token, or from a token you click in History.
|
| 96 |
+
Thicker lines indicate larger weights. Self-attention is drawn as a loop.
|
| 97 |
+
Click a token to see actual percentages, including any boundary-token weight.
|
| 98 |
+
Top-eight values are not renormalized; the detail shows their total probability mass.
|
| 99 |
+
Attention targets that have faded or fallen outside retained history reappear as faint context nodes, including the boundary token. Their weights are unchanged. Expired selections no longer block the latest attention row.
|
| 100 |
+
|
| 101 |
+
Layer -1 selects the last attention layer; head -1 averages across heads. Otherwise
|
| 102 |
+
use zero-based indices. Model status reports the layer/head counts. Changes apply
|
| 103 |
+
while generating; stored historical rows retain the settings used when captured.
|
| 104 |
+
A query's attention is captured while it predicts the following token, not from the
|
| 105 |
+
new token before that new token has been fed through the model. The final generated
|
| 106 |
+
token therefore has no attention row until generation continues.
|
| 107 |
+
|
| 108 |
+
The model uses its eager attention implementation. A forward hook copies only the
|
| 109 |
+
last query row from the selected layer, avoiding retention of all layers' complete
|
| 110 |
+
attention matrices. This can be slower than optimized attention, especially with
|
| 111 |
+
long memory. Capture may be disabled. Unsupported custom attention architectures
|
| 112 |
+
can generate with capture disabled. Attention weights describe one operation in the
|
| 113 |
+
network and are not a complete causal explanation or access to private reasoning.
|
| 114 |
+
|
| 115 |
+
## Clickable paused text
|
| 116 |
+
|
| 117 |
+
While generation is paused, the top text overlay becomes a token-aware reader.
|
| 118 |
+
Click a token occurrence to highlight it in the text, focus its position in 3D,
|
| 119 |
+
and show its captured attention. Step back and Step forward stay synchronized with
|
| 120 |
+
the text highlight. Resume restores the normal full-text overlay. Repeated token
|
| 121 |
+
IDs remain separate occurrences. All generated tokens can be located in 3D from
|
| 122 |
+
the text; only the last 512 token occurrences retain attention rows.
|
| 123 |
+
|
| 124 |
+
The reader uses the tokenizer's streaming decoder to preserve the exact text.
|
| 125 |
+
When several byte-level tokens jointly produce one Unicode character, clicking
|
| 126 |
+
that text exposes individual token choices. For unsupported streaming decoders,
|
| 127 |
+
the exact prose is retained with selectable token pieces below it. Model text is
|
| 128 |
+
inserted using textContent, not interpreted as HTML. Clickable text does not change
|
| 129 |
+
sampling, token IDs, the generated passage, or RNG state.
|
| 130 |
+
|
| 131 |
+
## Pause and token stepping
|
| 132 |
+
|
| 133 |
+
Pause generation finishes the current inference step and stops sampling. It switches
|
| 134 |
+
the viewer to a non-fading attention inspection mode. Step back and Step forward
|
| 135 |
+
move through generated token occurrences. Only the last 512 occurrences retain attention; older tokens can still be located by their embeddings. The
|
| 136 |
+
view hides future tokens relative to the selected query and shows that query's
|
| 137 |
+
recorded attention, including faint older targets. Rows that were not captured
|
| 138 |
+
are labelled as unavailable; the final token has no row until it predicts another.
|
| 139 |
+
Stepping does not generate text, delete tokens, change the random state, or recompute
|
| 140 |
+
attention with different layer/head settings. Resume generation continues the same
|
| 141 |
+
text and RNG sequence and restores the prior viewer mode. Stop keeps its normal
|
| 142 |
+
fading behavior. Pausing also works after a pass has completed.
|
| 143 |
+
|
| 144 |
+
## Model presets
|
| 145 |
+
|
| 146 |
+
Eight presets are available: SmolLM2 135M and 360M, GPT-2, Qwen3 0.6B Base,
|
| 147 |
+
Qwen3 0.6B instruction tuned, Qwen2.5 0.5B Base, and Gemma 3 1B in base and
|
| 148 |
+
instruction-tuned versions. These include the model families in Token Visualiser.
|
| 149 |
+
Gemma uses public safetensors repositories (`unsloth/gemma-3-1b-pt` and
|
| 150 |
+
`unsloth/gemma-3-1b-it`) instead of the Visualiser's GGUF file. Public repository
|
| 151 |
+
metadata, download sizes, tokenizers, and attention-compatible model architectures
|
| 152 |
+
were checked; full pretrained inference was smoke-tested with the default SmolLM2.
|
| 153 |
+
The added model architectures were checked using reduced test configurations.
|
| 154 |
+
Gemma downloads about 2 GB and is slower on CPU; the Qwen models download about
|
| 155 |
+
1?1.5 GB. Base models are labelled separately from instruction-tuned models.
|
| 156 |
+
Custom public model repository IDs and main repository URLs remain supported.
|
| 157 |
+
The dropdown sends canonical repository IDs; descriptions are shown separately.
|
| 158 |
+
Older display labels are also resolved on the backend for cached browser pages.
|
| 159 |
+
Prompt-free output is not restricted to prose: code and other learned document
|
| 160 |
+
formats may emerge, and temperature controls randomness rather than genre.
|
| 161 |
+
|
| 162 |
+
## Controls
|
| 163 |
+
|
| 164 |
+
The main button starts as Start, changes to Pause during generation, and becomes
|
| 165 |
+
Resume after pausing. It waits for the current inference step before enabling
|
| 166 |
+
Resume. After a model end token, Start begins a new stream. The round ↺ button at
|
| 167 |
+
the bottom right returns to the start page immediately, stopping the
|
| 168 |
+
current generation before clearing the session. The selected model remains in the
|
| 169 |
+
shared process until another model is loaded; other visitors' sessions are not reset.
|
| 170 |
+
|
| 171 |
+
Each successful model load draws a fresh 32-bit random seed and replaces any
|
| 172 |
+
previous manual seed in the settings field. Start / Resume uses that seed for a
|
| 173 |
+
new stream; resuming preserves the existing RNG state. You can still enter a seed
|
| 174 |
+
manually, or clear the field to request a random seed on the next new stream.
|
| 175 |
+
New stream begins again with the selected seed; Clear stream clears the text.
|
| 176 |
+
The bottom Settings drawer is collapsed by default and scrolls when expanded.
|
| 177 |
+
|
| 178 |
+
**Automatically continue** is on by default. Generation keeps flowing past the
|
| 179 |
+
pass limit without restarting the model cache or random sequence. Stop, an emitted
|
| 180 |
+
end token, and the 16,384-token session limit still end the stream. Toggle it off
|
| 181 |
+
live to use Tokens per pass; if that limit has already been passed, generation
|
| 182 |
+
stops after the current token. This removes manual continuation pauses; CPU and
|
| 183 |
+
context-rebuilding delays can still occur.
|
| 184 |
+
|
| 185 |
+
- **Begin:** replace the stream and initialize a new random sequence.
|
| 186 |
+
- **Stop:** request cancellation; the current inference step completes first.
|
| 187 |
+
- **Continue:** preserve generated token IDs and RNG state, including across a stop.
|
| 188 |
+
- **Start fresh:** clear the page, then press Begin or Continue to start.
|
| 189 |
+
- **Live sampling controls:** temperature, top-p, sign-aware repetition penalty,
|
| 190 |
+
optional seed, memory span, tokens per pass, and a display delay.
|
| 191 |
+
Defaults: temperature 1.3, top-p 1.0, repetition penalty 1.1, memory 128 tokens.
|
| 192 |
+
Try 64 tokens for more drift; longer memory sustains a subject more easily.
|
| 193 |
+
Sliders update the current stream without restarting it. Changes take effect
|
| 194 |
+
from the next token after the server receives the update; an inference step
|
| 195 |
+
already in progress finishes with its previous settings. The status shows the
|
| 196 |
+
sampling settings actually used for the latest token. Pass length can be raised
|
| 197 |
+
before the pass ends, or lowered to stop at the new limit. Reading delay updates
|
| 198 |
+
for subsequent pauses. A seed applies only to a new stream. Results are reproducible
|
| 199 |
+
for the same model revision, settings, hardware/software, and context boundaries;
|
| 200 |
+
different hardware or pass boundaries may cause numerical differences.
|
| 201 |
+
- **Watch the next token:** show the latest choice, the eight most probable
|
| 202 |
+
candidates, and the selected token even if it falls outside those eight. It is
|
| 203 |
+
a live snapshot, not a retained history. Toggle it during generation to show
|
| 204 |
+
or hide the inspector on the next token. Spaces and newlines appear using quoted representations.
|
| 205 |
+
- **Export:** prepare a UTF-8 text download, or copy directly from the page.
|
| 206 |
+
|
| 207 |
+
## What the probabilities mean
|
| 208 |
+
|
| 209 |
+
Each step takes the model's logits, applies repetition penalty over the active
|
| 210 |
+
context (including the initial boundary while present), then temperature. Top-p
|
| 211 |
+
keeps the smallest leading set reaching the requested probability mass. The
|
| 212 |
+
inspector shows the resulting **renormalized sampling distribution**, not the
|
| 213 |
+
unmodified model probabilities. The selected token is sampled from exactly that
|
| 214 |
+
distribution. Other tokens reports the probability mass outside the shown rows.
|
| 215 |
+
No fabricated reasoning or token alternatives are used. The text is generated
|
| 216 |
+
output, not evidence of consciousness or a view of private reasoning.
|
| 217 |
+
|
| 218 |
+
## Limits and shared hosting
|
| 219 |
+
|
| 220 |
+
The public ZeroGPU Space preloads the curated catalog in half precision at startup. Each visitor selects a model independently; changing a selection does not replace another visitor's model. GPU generation is queued in short sessions, with state returned to Gradio after each token. Live controls and pause signals are shared safely with the GPU worker. Attention and text history stay with the visitor's session.
|
| 221 |
+
|
| 222 |
+
In local CPU mode, one model is held in memory for the process. Loading and generation share a queue
|
| 223 |
+
to avoid simultaneous model allocation. Loading another model affects all
|
| 224 |
+
visitors; previous streams cannot continue under a different model revision.
|
| 225 |
+
Text and random state are per browser session. Clear or copy/export your text
|
| 226 |
+
before switching models. Browser refresh discards the session.
|
| 227 |
+
|
| 228 |
+
Only public, ungated, decoder-only safetensors models supported by standard
|
| 229 |
+
Transformers code are accepted. Remote model Python code is disabled. GGUF,
|
| 230 |
+
custom-code architectures, and gated/private access are outside this version.
|
| 231 |
+
Downloads are pinned to a resolved commit and cached. The default total download
|
| 232 |
+
cap is 2 GB (`FLOW_MAX_DOWNLOAD_GB` can change it); this is not a RAM guarantee.
|
| 233 |
+
Use compatible small models. Cached files persist until manually removed; ephemeral
|
| 234 |
+
Space storage may be reset by a restart or rebuild.
|
| 235 |
+
|
| 236 |
+
With automatic continuation off, a pass generates at most 1,024 tokens. Continue extends it up to 16,384 tokens per
|
| 237 |
+
session. The context defaults to the most recent 128 tokens. The Memory span slider
|
| 238 |
+
can select 16?2,048 tokens, bounded by the model's smaller advertised context limit.
|
| 239 |
+
Memory changes apply while generating, including shrinking or expanding the active
|
| 240 |
+
window. Expanding it can bring earlier visible text back into context. All earlier context and cached
|
| 241 |
+
activations are excluded once they fall outside the selected window. When full, older text remains on screen but
|
| 242 |
+
stops influencing generation. KV cache is rebuilt as needed when the window
|
| 243 |
+
slides. This bounds memory but can slow long streams. An emitted end token ends
|
| 244 |
+
the stream naturally; it is not suppressed to force more prose.
|
| 245 |
+
|
| 246 |
+
## Verification
|
| 247 |
+
|
| 248 |
+
```powershell
|
| 249 |
+
.\.venv\Scripts\python.exe -m unittest discover -s tests -v
|
| 250 |
+
```
|
| 251 |
+
|
| 252 |
+
The automated tests cover real sampling math, seeded continuation, stopping,
|
| 253 |
+
model boundaries, EOS, context rollover, and HTML escaping. A real-model smoke
|
| 254 |
+
check can be run with `python scripts/smoke.py` after installing dependencies;
|
| 255 |
+
it downloads SmolLM2-135M and checks prompt-free generation and continuation.
|
| 256 |
+
With the server running, `python scripts/check_server.py` also exercises the
|
| 257 |
+
Gradio API, including seeded replay, live slider/inspector updates while generation
|
| 258 |
+
is running, stopping, exporting, and resetting a session.
|
| 259 |
+
|
| 260 |
+
Frontend behavior checks: `node tests/check_token_space.cjs` (arrival, fading while paused, reset, orbit and zoom).
|
| 261 |
+
|
| 262 |
+
## Public ZeroGPU deployment
|
| 263 |
+
|
| 264 |
+
Sign in with Hugging Face to use your personal ZeroGPU quota. Curated models are preloaded in half precision, including GPT-2 XL (1.5B). Actual eager attention is captured on the GPU. Generation yields session state back to Gradio and automatically requests another short GPU session while automatic continuation is enabled. GPU queue delays can occur between sessions. Pausing releases the GPU. Local CPU mode retains custom public model loading with a 2 GB download cap.
|
| 265 |
+
|
| 266 |
+
## English-biased sampling
|
| 267 |
+
|
| 268 |
+
English bias (default 2; 0 disables it) adds a soft token prior before temperature and top-p filtering. The prior uses wordfreq English word frequencies compared with eight other Latin-script languages, English subword fragments, and Unicode script information. Punctuation, digits, special tokens, and incomplete byte tokens remain neutral. No prompt or chat template is added. Shared words, names, and subword ambiguity mean English is not guaranteed. The next-token inspector displays the actual distribution after this adjustment. The slider applies live and persists across GPU chunks. wordfreq data attribution and licensing: https://github.com/rspeer/wordfreq/blob/master/NOTICE.md
|
| 269 |
+
|
| 270 |
+
## Coloured layer overlays
|
| 271 |
+
|
| 272 |
+
The attention panel defaults to early, middle and final layers. All layers uses a continuous cyan/violet/amber palette; Selected layer/head preserves the original inspection controls. Each layer overlay averages its attention heads. Curves separate overlapping connections; thickness encodes raw attention weight. Hover a curve for its layer, target and weight. Legend buttons hide/show layers, Shift-click isolates one, and hover highlights one. The links-per-layer selector and minimum-weight filter affect the display only.
|
| 273 |
+
|
| 274 |
+
During generation, all layer means are captured, keeping the eight strongest targets for each query in a compact 512-slot CPU tensor ring. Full attention matrices are not retained. Live transport sends the latest query; pausing sends retained layer records for token-by-token replay. Positions stay in the same embedding projection. Layer comparisons are measurements of attention, not explanations of all model computations. The chosen layer/head is also saved separately.
|
| 275 |
+
|
| 276 |
+
## Representations through layers
|
| 277 |
+
|
| 278 |
+
Capture layer representations is optional and enabled initially for this experiment. Pause and select Layer representations in View. The layer slider shows the input to the first block, successive hidden states, and the final normalised output. Play layers interpolates between recorded positions; the selected-token trail joins the recorded stages. Attention, when available, follows the nearest displayed layer, averaged across heads. Input stage has no attention overlay.
|
| 279 |
+
|
| 280 |
+
Only the last-position hidden states from the original generation calls are retained for capture. Each token trajectory belongs to the moment that occurrence was processed to predict the following token; the cloud is not a single full-context snapshot. The latest generated token has no trajectory until it is processed in another forward pass. Recording is bounded to the latest 128 processed token positions, plus the initial boundary when captured.
|
| 281 |
+
|
| 282 |
+
Vectors are unit-normalised. One shared PCA basis and scale are fitted jointly across all stages of the first eight captured tokens, or fewer when a pass/pause ends early, then frozen for that stream. Calibration vectors are discarded after fitting; only the basis and 3D coordinates persist. This compares directions in a fixed compressed space, not semantic distance or importance. Input may include positional processing depending on architecture. Switching back to Live or History restores the original input-embedding view. No extra model calls, prompt tokens or random draws are introduced by layer playback.
|
| 283 |
+
|
| 284 |
+
## Experimental original-dimension axes
|
| 285 |
+
|
| 286 |
+
All projected dimensions is off initially. Enable the checkbox above the connection panel for faint white guides, with opacity and origin options. Every original feature coordinate direction is transformed by the active PCA basis. A single common extent makes the guides visible while preserving their relative projected lengths. Axes may overlap or collapse when compressed into 3D; these are not attention links, model layers, semantic labels or individual learned parameters. Hover identifies a zero-based dimension index.
|
| 287 |
+
|
| 288 |
+
The default translates these directions to the PCA mean. Original vector origin instead uses the affine projection of the zero vector. In Layer representations, the basis belongs to the frozen, unit-normalised hidden-state projection, so axes stay fixed during layer playback. Embedding and representation geometry are sent only when first available or with full snapshots, rather than on every generated token. Controls are local to the visualisation and do not change generation.
|
| 289 |
+
|
| 290 |
+
## Sign-in and embedded browsers
|
| 291 |
+
|
| 292 |
+
The start page has the only sign-in button. It opens the canonical hf.space OAuth route in the same tab (`_top`), leaving the huggingface.co iframe, and returns to the direct app after login. This avoids doing the cookie-based OAuth round trip inside the huggingface.co iframe. Gradio's normal OAuth state validation, callback, expiry checks and logout remain in use. Query strings from the embedding page are not copied into the login URL. If a browser blocks all cookies, users still need to allow site cookies for sign-in to complete. The direct app URL is https://jejunepixels-let-it-flow.hf.space/.
|
app.py
CHANGED
|
@@ -1,370 +1,377 @@
|
|
| 1 |
-
"""Automatic Token Generation — a prompt-free Hugging Face Space."""
|
| 2 |
-
from gpu_runtime import ZERO_GPU, spaces
|
| 3 |
-
import html
|
| 4 |
-
import secrets
|
| 5 |
-
from pathlib import Path
|
| 6 |
-
import time
|
| 7 |
-
|
| 8 |
-
import gradio as gr
|
| 9 |
-
|
| 10 |
-
from engine import Flow, generate
|
| 11 |
-
from models import ModelStore, PRESETS, MODEL_LABELS, repository
|
| 12 |
-
from token_space import SCENE, frame
|
| 13 |
-
from hf_login import TopLevelLoginButton
|
| 14 |
-
|
| 15 |
-
|
| 16 |
-
|
| 17 |
-
|
| 18 |
-
|
| 19 |
-
|
| 20 |
-
|
| 21 |
-
entry
|
| 22 |
-
|
| 23 |
-
|
| 24 |
-
|
| 25 |
-
|
| 26 |
-
|
| 27 |
-
|
| 28 |
-
|
| 29 |
-
|
| 30 |
-
|
| 31 |
-
|
| 32 |
-
|
| 33 |
-
|
| 34 |
-
|
| 35 |
-
|
| 36 |
-
|
| 37 |
-
|
| 38 |
-
|
| 39 |
-
f'<
|
| 40 |
-
f'<
|
| 41 |
-
f'<
|
| 42 |
-
|
| 43 |
-
|
| 44 |
-
|
| 45 |
-
f'<
|
| 46 |
-
'
|
| 47 |
-
'
|
| 48 |
-
|
| 49 |
-
|
| 50 |
-
|
| 51 |
-
|
| 52 |
-
|
| 53 |
-
|
| 54 |
-
|
| 55 |
-
|
| 56 |
-
flow.
|
| 57 |
-
flow.
|
| 58 |
-
flow.
|
| 59 |
-
flow.
|
| 60 |
-
flow.
|
| 61 |
-
flow.
|
| 62 |
-
flow.
|
| 63 |
-
flow.
|
| 64 |
-
flow.
|
| 65 |
-
flow.
|
| 66 |
-
flow.
|
| 67 |
-
flow.
|
| 68 |
-
flow.
|
| 69 |
-
flow.
|
| 70 |
-
flow.
|
| 71 |
-
flow.
|
| 72 |
-
flow.
|
| 73 |
-
flow.
|
| 74 |
-
|
| 75 |
-
|
| 76 |
-
|
| 77 |
-
|
| 78 |
-
|
| 79 |
-
|
| 80 |
-
|
| 81 |
-
|
| 82 |
-
|
| 83 |
-
|
| 84 |
-
|
| 85 |
-
|
| 86 |
-
|
| 87 |
-
|
| 88 |
-
|
| 89 |
-
|
| 90 |
-
|
| 91 |
-
|
| 92 |
-
|
| 93 |
-
|
| 94 |
-
|
| 95 |
-
|
| 96 |
-
flow.
|
| 97 |
-
flow.
|
| 98 |
-
|
| 99 |
-
|
| 100 |
-
|
| 101 |
-
|
| 102 |
-
|
| 103 |
-
flow.
|
| 104 |
-
flow.
|
| 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 |
-
flow.
|
| 136 |
-
flow.
|
| 137 |
-
|
| 138 |
-
|
| 139 |
-
|
| 140 |
-
|
| 141 |
-
|
| 142 |
-
|
| 143 |
-
|
| 144 |
-
|
| 145 |
-
|
| 146 |
-
|
| 147 |
-
|
| 148 |
-
|
| 149 |
-
|
| 150 |
-
|
| 151 |
-
|
| 152 |
-
|
| 153 |
-
|
| 154 |
-
|
| 155 |
-
|
| 156 |
-
|
| 157 |
-
|
| 158 |
-
f"
|
| 159 |
-
f" ·
|
| 160 |
-
f" ·
|
| 161 |
-
|
| 162 |
-
|
| 163 |
-
|
| 164 |
-
|
| 165 |
-
|
| 166 |
-
|
| 167 |
-
|
| 168 |
-
|
| 169 |
-
|
| 170 |
-
|
| 171 |
-
|
| 172 |
-
flow.
|
| 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 |
-
output
|
| 228 |
-
|
| 229 |
-
|
| 230 |
-
|
| 231 |
-
|
| 232 |
-
|
| 233 |
-
|
| 234 |
-
|
| 235 |
-
|
| 236 |
-
|
| 237 |
-
flow.
|
| 238 |
-
flow.
|
| 239 |
-
flow.
|
| 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 |
-
with gr.Row():
|
| 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 |
-
gr.
|
| 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 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
"""Automatic Token Generation — a prompt-free Hugging Face Space."""
|
| 2 |
+
from gpu_runtime import ZERO_GPU, spaces
|
| 3 |
+
import html
|
| 4 |
+
import secrets
|
| 5 |
+
from pathlib import Path
|
| 6 |
+
import time
|
| 7 |
+
|
| 8 |
+
import gradio as gr
|
| 9 |
+
|
| 10 |
+
from engine import Flow, generate
|
| 11 |
+
from models import ModelStore, PRESETS, MODEL_LABELS, repository
|
| 12 |
+
from token_space import SCENE, frame
|
| 13 |
+
from hf_login import TopLevelLoginButton
|
| 14 |
+
from brand_theme import brand_theme
|
| 15 |
+
|
| 16 |
+
STORE = ModelStore()
|
| 17 |
+
POOL = {}
|
| 18 |
+
if ZERO_GPU:
|
| 19 |
+
for model_id in PRESETS:
|
| 20 |
+
print(f"Preloading {model_id}", flush=True)
|
| 21 |
+
entry = ModelStore()
|
| 22 |
+
entry.load(model_id)
|
| 23 |
+
POOL[model_id] = entry
|
| 24 |
+
|
| 25 |
+
def session_store(flow):
|
| 26 |
+
return POOL.get(flow.selected_repo, STORE) if ZERO_GPU else STORE
|
| 27 |
+
|
| 28 |
+
|
| 29 |
+
|
| 30 |
+
def inspector(tokenizer, step, number):
|
| 31 |
+
rows = []
|
| 32 |
+
for token_id, probability in step["candidates"]:
|
| 33 |
+
piece = tokenizer.decode([token_id], skip_special_tokens=False,
|
| 34 |
+
clean_up_tokenization_spaces=False)
|
| 35 |
+
# repr makes spaces and linebreaks visible; escaping prevents generated HTML execution.
|
| 36 |
+
label = html.escape(repr(piece))
|
| 37 |
+
selected = token_id == step["chosen"]
|
| 38 |
+
rows.append(f'<div class="candidate {"selected" if selected else ""}">'
|
| 39 |
+
f'<div class="candidate-label"><code>{label}</code>'
|
| 40 |
+
f'<span>{probability:.2%}{" · selected" if selected else ""}</span></div>'
|
| 41 |
+
f'<div class="track"><div style="width:{probability * 100:.4f}%"></div></div>'
|
| 42 |
+
f'<small>token {token_id}</small></div>')
|
| 43 |
+
return (f'<div class="inspector"><div class="eyebrow">CHOICE {number}</div>'
|
| 44 |
+
'<h3>What could come next?</h3><p>Probabilities immediately before the latest token was selected.</p>'
|
| 45 |
+
+ "".join(rows) + f'<p>Other tokens: {step["other"]:.2%}</p>'
|
| 46 |
+
f'<small>Top-p retained {step["retained_mass"]:.2%} of the distribution after '
|
| 47 |
+
'temperature, repetition penalty and English bias. Bars show probabilities renormalized over that set. '
|
| 48 |
+
'The selected token may be outside the eight leading candidates.</small></div>')
|
| 49 |
+
|
| 50 |
+
|
| 51 |
+
EMPTY = '<div class="inspector"><div class="eyebrow">WATCH THE NEXT TOKEN</div><h3>A field of possibilities.</h3><p>Enable the inspector and begin. Each choice will show candidate tokens, their sampling probabilities, and the selected token.</p></div>'
|
| 52 |
+
|
| 53 |
+
|
| 54 |
+
def clear(flow):
|
| 55 |
+
import uuid
|
| 56 |
+
flow.stream_id = uuid.uuid4().hex
|
| 57 |
+
flow.tokens.clear()
|
| 58 |
+
flow.space_history.clear()
|
| 59 |
+
flow.attention_history.clear()
|
| 60 |
+
flow.layer_rows = flow.layer_keys = None
|
| 61 |
+
flow.layer_queries = [-1] * 512
|
| 62 |
+
flow.representations = None
|
| 63 |
+
flow.sent_dimension_axes_key = ""
|
| 64 |
+
flow.text_snapshot_cache = None
|
| 65 |
+
flow.continue_automatically = False
|
| 66 |
+
flow.pass_remaining = None
|
| 67 |
+
flow.paused = False
|
| 68 |
+
flow.running = False
|
| 69 |
+
flow.reset_requested = False
|
| 70 |
+
flow.text = ""
|
| 71 |
+
flow.model_key = ""
|
| 72 |
+
flow.seed = flow.rng_state = None
|
| 73 |
+
flow.ended = False
|
| 74 |
+
flow.stop.clear()
|
| 75 |
+
return "", EMPTY, "A blank page. Press Begin when you’re ready."
|
| 76 |
+
|
| 77 |
+
|
| 78 |
+
def load_model(repo, flow):
|
| 79 |
+
try:
|
| 80 |
+
if ZERO_GPU:
|
| 81 |
+
selected = repository(repo)
|
| 82 |
+
if selected not in POOL:
|
| 83 |
+
raise ValueError("Choose a preloaded model from the list.")
|
| 84 |
+
flow.selected_repo = selected
|
| 85 |
+
description = POOL[selected].description
|
| 86 |
+
else:
|
| 87 |
+
description = STORE.load(repo)
|
| 88 |
+
text, panel, status = clear(flow)
|
| 89 |
+
badge = "<span>" + html.escape(repository(repo)) + "</span>"
|
| 90 |
+
return description, text, panel, status, frame(flow, session_store(flow)), secrets.randbits(32), badge, gr.update(visible=False), gr.update(visible=True)
|
| 91 |
+
except Exception as error:
|
| 92 |
+
raise gr.Error(f"Could not load model: {error}") from error
|
| 93 |
+
|
| 94 |
+
|
| 95 |
+
def stop(flow):
|
| 96 |
+
flow.continue_automatically = False
|
| 97 |
+
flow.paused = False
|
| 98 |
+
flow.stop.set()
|
| 99 |
+
return frame(flow, session_store(flow), full=True)
|
| 100 |
+
|
| 101 |
+
|
| 102 |
+
def pause_generation(flow):
|
| 103 |
+
flow.continue_automatically = False
|
| 104 |
+
flow.paused = True
|
| 105 |
+
flow.stop.set()
|
| 106 |
+
return ("Pausing after the current token. Use Step back / Step forward in the 3D view, then Resume generation.",
|
| 107 |
+
frame(flow, session_store(flow), full=True))
|
| 108 |
+
|
| 109 |
+
|
| 110 |
+
def control_handler(name):
|
| 111 |
+
def update(value, flow):
|
| 112 |
+
try:
|
| 113 |
+
flow.update_controls(**{name: value})
|
| 114 |
+
except (ValueError, TypeError) as error:
|
| 115 |
+
raise gr.Error(str(error)) from error
|
| 116 |
+
return update
|
| 117 |
+
|
| 118 |
+
|
| 119 |
+
def _run(flow, temperature, top_p, penalty, seed, count, watch, delay, memory=128,
|
| 120 |
+
auto_continue=True, attention=True, attention_layer=-1, attention_head=-1, fresh=False, english_bias=2, capture_representations=True):
|
| 121 |
+
if flow.reset_requested:
|
| 122 |
+
return
|
| 123 |
+
store = session_store(flow)
|
| 124 |
+
if store.model is None:
|
| 125 |
+
raise gr.Error("Load a model first.")
|
| 126 |
+
if fresh:
|
| 127 |
+
clear(flow)
|
| 128 |
+
if ZERO_GPU and flow.continue_automatically and not auto_continue:
|
| 129 |
+
count = getattr(flow, "pass_remaining", None) or count
|
| 130 |
+
flow.update_controls(temperature=temperature, top_p=top_p, penalty=penalty,
|
| 131 |
+
count=count, watch=watch, delay=delay, memory=memory,
|
| 132 |
+
auto_continue=auto_continue, attention=attention,
|
| 133 |
+
attention_layer=attention_layer, attention_head=attention_head, english_bias=english_bias,
|
| 134 |
+
capture_representations=capture_representations)
|
| 135 |
+
flow.continue_automatically = False
|
| 136 |
+
flow.stop.clear()
|
| 137 |
+
flow.paused = False
|
| 138 |
+
panel = EMPTY
|
| 139 |
+
started = time.monotonic()
|
| 140 |
+
before = len(flow.tokens)
|
| 141 |
+
last_text = store.tokenizer.decode(flow.tokens, skip_special_tokens=True,
|
| 142 |
+
clean_up_tokenization_spaces=False)
|
| 143 |
+
trimmed = False
|
| 144 |
+
flow.running = True
|
| 145 |
+
try:
|
| 146 |
+
yield last_text, panel, "Generating…", frame(flow, session_store(flow), full=True)
|
| 147 |
+
for step in generate(store.model, store.tokenizer, flow, store.key,
|
| 148 |
+
count, temperature, top_p, penalty, seed, context_limit=memory,
|
| 149 |
+
live_settings=flow.controls, attention_modules=store.attention_modules,
|
| 150 |
+
english_prior=store.english_prior):
|
| 151 |
+
last_text = step["text"]
|
| 152 |
+
trimmed = step["context_trimmed"]
|
| 153 |
+
controls = flow.controls()
|
| 154 |
+
watching = controls["watch"]
|
| 155 |
+
if watching:
|
| 156 |
+
panel = inspector(store.tokenizer, step, len(flow.tokens))
|
| 157 |
+
status = (f"{len(flow.tokens)} tokens · seed {flow.seed} · "
|
| 158 |
+
f"{(len(flow.tokens) - before) / max(.001, time.monotonic() - started):.1f} tokens/s"
|
| 159 |
+
f" · memory {step['context_limit']} tokens"
|
| 160 |
+
f" · temperature {step['temperature']:g} · top-p {step['top_p']:g}"
|
| 161 |
+
f" · repetition {step['penalty']:g}")
|
| 162 |
+
status += f" / English bias {step['english_bias']:g}"
|
| 163 |
+
if controls["auto_continue"]:
|
| 164 |
+
status += " · automatic continuation on"
|
| 165 |
+
if trimmed:
|
| 166 |
+
status += f" · Only the latest {step['context_limit']} tokens inform the next choice."
|
| 167 |
+
yield last_text, panel if watching else "", status, frame(flow, session_store(flow))
|
| 168 |
+
delay = flow.controls()["delay"]
|
| 169 |
+
if delay and flow.stop.wait(float(delay)):
|
| 170 |
+
break
|
| 171 |
+
if ZERO_GPU and (time.monotonic() - started >= 18 or len(flow.tokens) - before >= 256):
|
| 172 |
+
flow.pass_remaining = max(0, int(flow.controls()["count"]) - (len(flow.tokens) - before))
|
| 173 |
+
flow.continue_automatically = bool((flow.controls()["auto_continue"] or flow.pass_remaining) and not flow.stop.is_set() and not flow.ended and len(flow.tokens) < 16384)
|
| 174 |
+
break
|
| 175 |
+
if flow.representations is not None:
|
| 176 |
+
flow.representations.finalize()
|
| 177 |
+
flow.running = False
|
| 178 |
+
if ZERO_GPU:
|
| 179 |
+
import torch
|
| 180 |
+
print(f"GPU validation {flow.selected_repo}: {torch.cuda.get_device_name()} / peak allocated {torch.cuda.max_memory_allocated() / 1024**3:.2f} GiB", flush=True)
|
| 181 |
+
if flow.continue_automatically:
|
| 182 |
+
reason = "GPU session complete. Requesting the next GPU session automatically."
|
| 183 |
+
elif flow.ended:
|
| 184 |
+
reason = "The model emitted an end token. Start fresh to begin another stream."
|
| 185 |
+
elif len(flow.tokens) >= 16384:
|
| 186 |
+
reason = "Session limit of 16,384 tokens reached. Download your text and start fresh."
|
| 187 |
+
elif flow.paused:
|
| 188 |
+
reason = "Paused. Step back / Step forward inspect saved attention; Resume generation continues the same stream."
|
| 189 |
+
elif flow.stop.is_set():
|
| 190 |
+
reason = "Stopped. Continue preserves the text and random sequence."
|
| 191 |
+
else:
|
| 192 |
+
reason = "Pass complete. Continue to let it flow further."
|
| 193 |
+
if trimmed:
|
| 194 |
+
reason += " Earlier text remains visible but is outside the model’s context."
|
| 195 |
+
controls = flow.controls()
|
| 196 |
+
yield last_text, panel if controls["watch"] else "", f"{reason} · {len(flow.tokens)} tokens · seed {flow.seed} · requested memory {int(controls['memory'])} tokens", frame(flow, session_store(flow), full=True)
|
| 197 |
+
except Exception as error:
|
| 198 |
+
flow.running = False
|
| 199 |
+
# Preserve already-generated text and RNG state so a failed pass can be retried.
|
| 200 |
+
raise gr.Error(str(error)) from error
|
| 201 |
+
finally:
|
| 202 |
+
flow.running = False
|
| 203 |
+
|
| 204 |
+
|
| 205 |
+
@spaces.GPU(duration=30)
|
| 206 |
+
def run(flow, temperature, top_p, penalty, seed, count, watch, delay, memory=128,
|
| 207 |
+
auto_continue=True, attention=True, attention_layer=-1, attention_head=-1, english_bias=2, capture_representations=True, automatic=False):
|
| 208 |
+
if automatic and (flow.paused or flow.reset_requested or not flow.continue_automatically):
|
| 209 |
+
return
|
| 210 |
+
for update in _run(flow, temperature, top_p, penalty, seed, count, watch, delay,
|
| 211 |
+
memory, auto_continue, attention, attention_layer, attention_head, english_bias=english_bias, capture_representations=capture_representations):
|
| 212 |
+
yield (*update, flow)
|
| 213 |
+
|
| 214 |
+
@spaces.GPU(duration=30)
|
| 215 |
+
def begin(flow, temperature, top_p, penalty, seed, count, watch, delay, memory=128,
|
| 216 |
+
auto_continue=True, attention=True, attention_layer=-1, attention_head=-1, english_bias=2, capture_representations=True):
|
| 217 |
+
for update in _run(flow, temperature, top_p, penalty, seed, count, watch, delay,
|
| 218 |
+
memory, auto_continue, attention, attention_layer, attention_head, fresh=True, english_bias=english_bias, capture_representations=capture_representations):
|
| 219 |
+
yield (*update, flow)
|
| 220 |
+
|
| 221 |
+
|
| 222 |
+
def export(flow):
|
| 223 |
+
if not flow.tokens:
|
| 224 |
+
raise gr.Error("Generate some text first.")
|
| 225 |
+
import tempfile
|
| 226 |
+
directory = Path(tempfile.mkdtemp(prefix="let-it-flow-"))
|
| 227 |
+
output = directory / "let-it-flow.txt"
|
| 228 |
+
output.write_text(flow.text, encoding="utf-8")
|
| 229 |
+
return str(output)
|
| 230 |
+
|
| 231 |
+
|
| 232 |
+
def reset_view(flow):
|
| 233 |
+
return *clear(flow), frame(flow, session_store(flow))
|
| 234 |
+
|
| 235 |
+
|
| 236 |
+
def choose_model(flow):
|
| 237 |
+
flow.reset_requested = True
|
| 238 |
+
flow.continue_automatically = False
|
| 239 |
+
flow.paused = False
|
| 240 |
+
flow.stop.set()
|
| 241 |
+
return gr.update(visible=True), gr.update(visible=False)
|
| 242 |
+
|
| 243 |
+
|
| 244 |
+
def refresh_view(flow):
|
| 245 |
+
flow.running = False
|
| 246 |
+
return frame(flow, session_store(flow), full=True)
|
| 247 |
+
|
| 248 |
+
|
| 249 |
+
def build_app():
|
| 250 |
+
# Shared look (brand.css, from shared-ui/) first, then this app's layout.
|
| 251 |
+
css = "".join(Path(__file__).with_name(name).read_text(encoding="utf-8") for name in ("brand.css", "style.css"))
|
| 252 |
+
js = Path(__file__).with_name("token_space.js").read_text(encoding="utf-8")
|
| 253 |
+
with gr.Blocks(title="Automatic Token Generation", css=css, js=js, theme=brand_theme(),
|
| 254 |
+
delete_cache=(3600, 3600)) as demo:
|
| 255 |
+
flow = gr.State(Flow())
|
| 256 |
+
with gr.Column(elem_id="model-picker", elem_classes=["brand-start"]) as picker:
|
| 257 |
+
gr.HTML('<header class="brand-header"><div class="eyebrow">AN EXPERIMENT IN AUTOMATIC WRITING</div>'
|
| 258 |
+
'<h1 class="brand-title">Automatic Token Generation<span class="title-stop">.</span></h1>'
|
| 259 |
+
'<p class="brand-intro">Inspired by the Surrealists\u2019 practice of automatic writing, this experiment lets language unfold without a written prompt. '
|
| 260 |
+
'A language model uses recent tokens to predict what could come next, then selects the next token by sampling from those probabilities. '
|
| 261 |
+
'A 3D view tracks attention weights from a selected layer and maps tokens through their embeddings.</p>'
|
| 262 |
+
'<p class="brand-intro">The model has no unconscious mind to uncover. This demo offers a look under the hood of how large language models generate text '
|
| 263 |
+
'through learned patterns, attention, and probabilistic sampling within a limited context window.</p></header>',
|
| 264 |
+
padding=False)
|
| 265 |
+
if ZERO_GPU:
|
| 266 |
+
TopLevelLoginButton(elem_id="hf-login-picker")
|
| 267 |
+
gr.Markdown("Sign in to use your Hugging Face ZeroGPU quota. Sign-in opens in this tab and brings you back here.",
|
| 268 |
+
elem_classes=["signin-note"])
|
| 269 |
+
# Labels describe each preset; the values sent are canonical repository IDs.
|
| 270 |
+
repo = gr.Dropdown([(MODEL_LABELS[preset].replace(" / ", " · "), preset) for preset in PRESETS],
|
| 271 |
+
value=PRESETS[0], allow_custom_value=not ZERO_GPU, label="Model",
|
| 272 |
+
info=None if ZERO_GPU else "Or paste a public model repository ID or Hugging Face URL.")
|
| 273 |
+
load = gr.Button("Load model & enter space", variant="primary", elem_id="load-model",
|
| 274 |
+
elem_classes=["brand-primary"])
|
| 275 |
+
gr.Markdown(elem_classes=["brand-note"], value=(
|
| 276 |
+
"**What you will see:** tokens appear in a 3D space as the model writes, with the probabilities and "
|
| 277 |
+
"attention behind each choice. Small **base models** work best. Loading includes preparing a fixed "
|
| 278 |
+
"3D embedding projection. " +
|
| 279 |
+
("Models are preloaded in 16-bit precision (Gemma in BF16 to keep generation numerically stable), up to "
|
| 280 |
+
"8 GB; each visitor has a separate stream. Generation uses short GPU sessions; Pause releases the GPU."
|
| 281 |
+
if ZERO_GPU else
|
| 282 |
+
"Public safetensors models only; 2 GB download limit. One model is shared by visitors. Gemma 3 1B "
|
| 283 |
+
"downloads about 2 GB and is slower on CPU; Qwen3 0.6B downloads about 1.2–1.5 GB. GGUF files are not "
|
| 284 |
+
"supported by this backend. Without a written prompt, output can be prose, code, lists, or other "
|
| 285 |
+
"training-data patterns.")))
|
| 286 |
+
with gr.Column(visible=False, elem_id="flow-workspace") as workspace:
|
| 287 |
+
gr.HTML(SCENE, elem_id="space-scene")
|
| 288 |
+
with gr.Column(elem_id="text-overlay"):
|
| 289 |
+
model_badge = gr.HTML('', elem_id="model-name", elem_classes=["brand-caption"])
|
| 290 |
+
page = gr.Textbox(label="The stream", lines=5, max_lines=8,
|
| 291 |
+
placeholder="No written prompt. Just the next token.", show_label=False,
|
| 292 |
+
interactive=False, show_copy_button=True, elem_id="page")
|
| 293 |
+
# Round ↺ button, outside the dock: returns to the start page (model choice and sign-in).
|
| 294 |
+
reset_model = gr.Button("Change model / sign in", elem_id="reset-model", elem_classes=["return-home"],
|
| 295 |
+
size="sm", min_width=0)
|
| 296 |
+
with gr.Column(elem_id="control-dock", elem_classes=["brand-dock"]):
|
| 297 |
+
with gr.Row(elem_id="stream-buttons"):
|
| 298 |
+
gr.HTML('<button type="button" class="generation-toggle-button" data-generation-toggle>Start</button>',
|
| 299 |
+
elem_id="generation-toggle")
|
| 300 |
+
with gr.Accordion("Settings, model & attention", open=False, elem_id="settings-drawer"):
|
| 301 |
+
with gr.Row(elem_id="sampling-controls"):
|
| 302 |
+
temperature = gr.Slider(.05, 2, value=1.3, step=.05, label="Temperature")
|
| 303 |
+
top_p = gr.Slider(.05, 1, value=1, step=.01, label="Top-p")
|
| 304 |
+
penalty = gr.Slider(1, 2, value=1.1, step=.01, label="Repetition penalty")
|
| 305 |
+
memory = gr.Slider(16, 2048, value=128, step=1, label="Memory span (tokens)")
|
| 306 |
+
english_bias = gr.Slider(0, 4, value=2, step=.25, label="English bias",
|
| 307 |
+
info="Favour English without a prompt. 0 = off. Applies live; languages can still mix.")
|
| 308 |
+
with gr.Row():
|
| 309 |
+
attention = gr.Checkbox(label="Capture attention", value=True,
|
| 310 |
+
info="Record layer averages for the coloured overlay, plus the selected layer/head.")
|
| 311 |
+
attention_layer = gr.Number(value=-1, precision=0, label="Selected attention layer",
|
| 312 |
+
info="-1 = last layer; otherwise a zero-based index.")
|
| 313 |
+
attention_head = gr.Number(value=-1, precision=0, label="Selected attention head",
|
| 314 |
+
info="-1 = average heads; otherwise a zero-based index.")
|
| 315 |
+
capture_representations = gr.Checkbox(value=True, label="Capture layer representations",
|
| 316 |
+
info="Record up to 128 recent token trajectories. Pause, then choose Layer representations in View. Optional; disabling reduces overhead.")
|
| 317 |
+
auto_continue = gr.Checkbox(label="Automatically continue", value=True,
|
| 318 |
+
info="Flow until Pause, Stop, an end token, or 16,384 tokens.")
|
| 319 |
+
with gr.Row():
|
| 320 |
+
seed = gr.Number(value=None, precision=0, label="Random seed",
|
| 321 |
+
info="A fresh random seed is selected on every model load. Clear for a random seed on the next new stream.")
|
| 322 |
+
count = gr.Slider(1, 1024, value=256, step=1, label="Tokens per pass",
|
| 323 |
+
info="Used when automatic continuation is off.")
|
| 324 |
+
delay = gr.Slider(0, .5, value=0 if ZERO_GPU else .06, step=.02, label="Reading delay per token (seconds)")
|
| 325 |
+
with gr.Row():
|
| 326 |
+
new_stream = gr.Button("New stream", elem_id="generation-new")
|
| 327 |
+
halt = gr.Button("Stop", variant="stop")
|
| 328 |
+
reset = gr.Button("Clear stream")
|
| 329 |
+
status = gr.Textbox(label="Stream status", value="Press Start to let it flow.", interactive=False)
|
| 330 |
+
model_status = gr.Textbox(label="Loaded model", interactive=False)
|
| 331 |
+
watch = gr.Checkbox(label="Watch the next token", value=True)
|
| 332 |
+
panel = gr.HTML(EMPTY)
|
| 333 |
+
with gr.Row():
|
| 334 |
+
save = gr.Button("Prepare text download", size="sm")
|
| 335 |
+
download = gr.File(label="Text export", interactive=False)
|
| 336 |
+
gr.Markdown("Drag to orbit, Shift-drag to pan, scroll to zoom. Pause to step through the last 512 tokens. "
|
| 337 |
+
"Positions are projected input embeddings. Attention arrows show measured weights from the "
|
| 338 |
+
"selected layer/head while predicting the following token; they are not a complete explanation. "
|
| 339 |
+
"Sliders apply live. The top overlay retains the full generated text; scroll it to read earlier passages.")
|
| 340 |
+
transport = gr.HTML('', elem_id="space-transport", elem_classes=["space-transport"])
|
| 341 |
+
start = gr.Button("Start generation", elem_id="generation-run", elem_classes=["generation-proxy"])
|
| 342 |
+
automatic_start = gr.Button("Continue GPU session", elem_id="generation-auto", elem_classes=["generation-proxy"])
|
| 343 |
+
automatic_request = gr.State(True)
|
| 344 |
+
pause = gr.Button("Pause generation", elem_id="generation-pause", elem_classes=["generation-proxy"])
|
| 345 |
+
outputs = [page, panel, status, transport]
|
| 346 |
+
inputs = [flow, temperature, top_p, penalty, seed, count, watch, delay, memory, auto_continue,
|
| 347 |
+
attention, attention_layer, attention_head, english_bias, capture_representations]
|
| 348 |
+
common = dict(concurrency_id="model", concurrency_limit=1)
|
| 349 |
+
for component, name in [(temperature, "temperature"), (top_p, "top_p"),
|
| 350 |
+
(penalty, "penalty"), (memory, "memory"), (count, "count"),
|
| 351 |
+
(delay, "delay"), (watch, "watch"), (auto_continue, "auto_continue"),
|
| 352 |
+
(attention, "attention"), (attention_layer, "attention_layer"),
|
| 353 |
+
(attention_head, "attention_head"), (english_bias, "english_bias"),
|
| 354 |
+
(capture_representations, "capture_representations")]:
|
| 355 |
+
component.input(control_handler(name), [component, flow], [], queue=False,
|
| 356 |
+
trigger_mode="always_last", api_name=f"update_{name}", show_progress="hidden")
|
| 357 |
+
load.click(load_model, [repo, flow], [model_status, *outputs, seed, model_badge, picker, workspace], **common)
|
| 358 |
+
reset_model.click(choose_model, [flow], [picker, workspace], queue=False).then(
|
| 359 |
+
reset_view, [flow], outputs, api_name="reset_model_state", **common)
|
| 360 |
+
start.click(run, inputs, [*outputs, flow], api_name="run", **common).failure(
|
| 361 |
+
refresh_view, [flow], transport, queue=False)
|
| 362 |
+
automatic_start.click(run, [*inputs, automatic_request], [*outputs, flow], api_name=False, **common).failure(
|
| 363 |
+
refresh_view, [flow], transport, queue=False)
|
| 364 |
+
new_stream.click(begin, inputs, [*outputs, flow], api_name="begin", **common).failure(
|
| 365 |
+
refresh_view, [flow], transport, queue=False)
|
| 366 |
+
halt.click(stop, [flow], transport, queue=False)
|
| 367 |
+
pause.click(pause_generation, [flow], [status, transport], queue=False)
|
| 368 |
+
reset.click(reset_view, [flow], outputs, api_name="clear", **common)
|
| 369 |
+
save.click(export, [flow], download, **common)
|
| 370 |
+
return demo.queue(max_size=16, default_concurrency_limit=1)
|
| 371 |
+
|
| 372 |
+
|
| 373 |
+
if __name__ == "__main__":
|
| 374 |
+
import os
|
| 375 |
+
default_host = "0.0.0.0" if os.environ.get("SPACE_ID") else "127.0.0.1"
|
| 376 |
+
build_app().launch(server_name=os.environ.get("FLOW_HOST", default_host),
|
| 377 |
+
server_port=int(os.environ.get("PORT", "7860")), show_error=True)
|
brand.css
ADDED
|
@@ -0,0 +1,293 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
/* ==========================================================================
|
| 2 |
+
Shared look for the Hugging Face Spaces in this folder:
|
| 3 |
+
Automatic Drawing, Stream of Consciousness (Let It Flow), Token Visualiser.
|
| 4 |
+
|
| 5 |
+
Canonical copy: shared-ui/brand.css. Edit it there, then run
|
| 6 |
+
`python shared-ui/sync.py` to copy it into each project.
|
| 7 |
+
|
| 8 |
+
- Start page: follows the browser's light/dark setting.
|
| 9 |
+
- Workspace: a dark stage with a pale mint control panel, identical in
|
| 10 |
+
both modes.
|
| 11 |
+
========================================================================== */
|
| 12 |
+
|
| 13 |
+
:root {
|
| 14 |
+
/* Workspace: the same in light and dark browser modes. */
|
| 15 |
+
--brand-stage: #080f18;
|
| 16 |
+
--brand-stage-raised: #112530;
|
| 17 |
+
--brand-stage-line: #577f89;
|
| 18 |
+
--brand-stage-text: #eef3f5;
|
| 19 |
+
--brand-stage-caption: #c5e2dd;
|
| 20 |
+
--brand-amber: #f4bf67;
|
| 21 |
+
--brand-amber-hover: #e7aa45;
|
| 22 |
+
--brand-amber-deep: #b77a20;
|
| 23 |
+
--brand-on-amber: #17242b;
|
| 24 |
+
--brand-mint: #eaf2eff2;
|
| 25 |
+
--brand-mint-solid: #eaf2ef;
|
| 26 |
+
--brand-mint-surface: #f4f8f6;
|
| 27 |
+
--brand-mint-text: #203c3a;
|
| 28 |
+
--brand-mint-label: #29433f;
|
| 29 |
+
--brand-mint-subdued: #526b68;
|
| 30 |
+
--brand-mint-line: #b3c7bd;
|
| 31 |
+
--brand-mint-border: #6d9f9b66;
|
| 32 |
+
--brand-shadow: 0 12px 50px #0006;
|
| 33 |
+
--brand-radius-panel: 18px;
|
| 34 |
+
--brand-radius-control: 10px;
|
| 35 |
+
--brand-serif: Georgia, 'Times New Roman', serif;
|
| 36 |
+
--brand-sans: system-ui, -apple-system, 'Segoe UI', Roboto, sans-serif;
|
| 37 |
+
|
| 38 |
+
/* Start page, light browser mode. */
|
| 39 |
+
--brand-page: #f4f8f6;
|
| 40 |
+
--brand-surface: #ffffff;
|
| 41 |
+
--brand-heading: #17242b;
|
| 42 |
+
--brand-text: #203c3a;
|
| 43 |
+
--brand-subdued: #526b68;
|
| 44 |
+
--brand-eyebrow: #92601c;
|
| 45 |
+
--brand-link: #92601c;
|
| 46 |
+
--brand-line: #b3c7bd;
|
| 47 |
+
--brand-input: #ffffff;
|
| 48 |
+
--brand-input-hover: #f4f8f6;
|
| 49 |
+
--brand-focus: #b77a20;
|
| 50 |
+
}
|
| 51 |
+
|
| 52 |
+
/* Start page, dark browser mode. Gradio puts .dark on an ancestor of the app and
|
| 53 |
+
honours ?__theme=. Streamlit follows the system setting, hence the media query. */
|
| 54 |
+
.dark {
|
| 55 |
+
--brand-page: #080f18;
|
| 56 |
+
--brand-surface: #091622;
|
| 57 |
+
--brand-heading: #eef3f5;
|
| 58 |
+
--brand-text: #d5e3e6;
|
| 59 |
+
--brand-subdued: #a8bdc4;
|
| 60 |
+
--brand-eyebrow: #f4bf67;
|
| 61 |
+
--brand-link: #f4bf67;
|
| 62 |
+
--brand-line: #577f89;
|
| 63 |
+
--brand-input: #112530;
|
| 64 |
+
--brand-input-hover: #193442;
|
| 65 |
+
--brand-focus: #f4bf67;
|
| 66 |
+
}
|
| 67 |
+
@media (prefers-color-scheme: dark) {
|
| 68 |
+
.stApp {
|
| 69 |
+
--brand-page: #080f18;
|
| 70 |
+
--brand-surface: #091622;
|
| 71 |
+
--brand-heading: #eef3f5;
|
| 72 |
+
--brand-text: #d5e3e6;
|
| 73 |
+
--brand-subdued: #a8bdc4;
|
| 74 |
+
--brand-eyebrow: #f4bf67;
|
| 75 |
+
--brand-link: #f4bf67;
|
| 76 |
+
--brand-line: #577f89;
|
| 77 |
+
--brand-input: #112530;
|
| 78 |
+
--brand-input-hover: #193442;
|
| 79 |
+
--brand-focus: #f4bf67;
|
| 80 |
+
}
|
| 81 |
+
}
|
| 82 |
+
|
| 83 |
+
/* ---- Start page --------------------------------------------------------- */
|
| 84 |
+
/* Order: eyebrow, title, intro, sign-in + note, model, primary action, note. */
|
| 85 |
+
/* .st-key-start_page is Token Visualiser's Streamlit start-page container. */
|
| 86 |
+
.brand-start, .st-key-start_page {
|
| 87 |
+
box-sizing: border-box;
|
| 88 |
+
width: calc(100% - 24px) !important;
|
| 89 |
+
max-width: 680px !important;
|
| 90 |
+
margin: 7vh auto !important;
|
| 91 |
+
padding: 24px !important;
|
| 92 |
+
gap: 18px !important;
|
| 93 |
+
}
|
| 94 |
+
/* Gradio wraps fields in a bordered card; keep the start page flat (label above field),
|
| 95 |
+
as in Token Visualiser. */
|
| 96 |
+
.brand-start .form { border: 0 !important; background: transparent !important; box-shadow: none !important; }
|
| 97 |
+
.brand-start .form > .block {
|
| 98 |
+
padding: 0 !important;
|
| 99 |
+
border: 0 !important;
|
| 100 |
+
background: transparent !important;
|
| 101 |
+
box-shadow: none !important;
|
| 102 |
+
}
|
| 103 |
+
.brand-start .form > .block [data-testid="block-info"] {
|
| 104 |
+
padding-left: 0 !important;
|
| 105 |
+
padding-right: 0 !important;
|
| 106 |
+
font-weight: 600;
|
| 107 |
+
color: var(--brand-text) !important;
|
| 108 |
+
}
|
| 109 |
+
/* Gradio pads HTML blocks; align the title with the controls below it. */
|
| 110 |
+
.brand-start .html-container { padding-left: 0 !important; padding-right: 0 !important; }
|
| 111 |
+
.brand-header { padding: 12px 0 6px; }
|
| 112 |
+
.eyebrow {
|
| 113 |
+
font: 600 11px/1.5 var(--brand-sans);
|
| 114 |
+
letter-spacing: .18em;
|
| 115 |
+
text-transform: uppercase;
|
| 116 |
+
color: var(--brand-eyebrow) !important;
|
| 117 |
+
}
|
| 118 |
+
.brand-title {
|
| 119 |
+
margin: 14px 0 18px !important;
|
| 120 |
+
padding: 0 !important;
|
| 121 |
+
border: 0 !important;
|
| 122 |
+
font: 400 clamp(38px, 6vw, 62px)/1.06 var(--brand-serif) !important;
|
| 123 |
+
letter-spacing: -.04em !important;
|
| 124 |
+
color: var(--brand-heading) !important;
|
| 125 |
+
}
|
| 126 |
+
.title-stop { color: var(--brand-amber) !important; }
|
| 127 |
+
.brand-intro {
|
| 128 |
+
margin: 0 0 12px !important;
|
| 129 |
+
font: 16px/1.7 var(--brand-sans) !important;
|
| 130 |
+
color: var(--brand-text) !important;
|
| 131 |
+
}
|
| 132 |
+
.brand-note, .brand-note p, .brand-note li,
|
| 133 |
+
.signin-note, .signin-note p {
|
| 134 |
+
margin: 0;
|
| 135 |
+
font: 14px/1.6 var(--brand-sans) !important;
|
| 136 |
+
color: var(--brand-subdued) !important;
|
| 137 |
+
}
|
| 138 |
+
.brand-note strong, .signin-note strong { color: var(--brand-text) !important; }
|
| 139 |
+
.brand-note a, .signin-note a, .brand-header a { color: var(--brand-link) !important; }
|
| 140 |
+
/* .st-key-hf_load_preset is Token Visualiser's "Load model" button. */
|
| 141 |
+
.brand-primary, .st-key-hf_load_preset button {
|
| 142 |
+
min-height: 48px !important;
|
| 143 |
+
border: 0 !important;
|
| 144 |
+
border-radius: var(--brand-radius-control) !important;
|
| 145 |
+
background: var(--brand-amber) !important;
|
| 146 |
+
color: var(--brand-on-amber) !important;
|
| 147 |
+
font: 600 16px/1.4 var(--brand-sans) !important;
|
| 148 |
+
}
|
| 149 |
+
.brand-primary:hover, .st-key-hf_load_preset button:hover { background: var(--brand-amber-hover) !important; }
|
| 150 |
+
.brand-primary:focus-visible, .st-key-hf_load_preset button:focus-visible {
|
| 151 |
+
outline: 3px solid var(--brand-focus) !important;
|
| 152 |
+
outline-offset: 2px;
|
| 153 |
+
}
|
| 154 |
+
@media (max-width: 640px) {
|
| 155 |
+
.brand-start, .st-key-start_page { margin: 3vh auto !important; padding: 18px !important; }
|
| 156 |
+
}
|
| 157 |
+
|
| 158 |
+
/* ---- Workspace ---------------------------------------------------------- */
|
| 159 |
+
/* Floating mint panel. A light island: readable in both browser modes. */
|
| 160 |
+
.brand-dock {
|
| 161 |
+
box-sizing: border-box;
|
| 162 |
+
border: 1px solid var(--brand-mint-border) !important;
|
| 163 |
+
border-radius: var(--brand-radius-panel) !important;
|
| 164 |
+
background: var(--brand-mint) !important;
|
| 165 |
+
backdrop-filter: blur(18px);
|
| 166 |
+
box-shadow: var(--brand-shadow);
|
| 167 |
+
color: var(--brand-mint-text);
|
| 168 |
+
color-scheme: light;
|
| 169 |
+
/* Start-page tokens revert to their light values inside the panel. */
|
| 170 |
+
--brand-heading: #17242b;
|
| 171 |
+
--brand-text: #203c3a;
|
| 172 |
+
--brand-subdued: #526b68;
|
| 173 |
+
--brand-eyebrow: #92601c;
|
| 174 |
+
--brand-link: #92601c;
|
| 175 |
+
--brand-line: #b3c7bd;
|
| 176 |
+
--brand-input: #ffffff;
|
| 177 |
+
--brand-input-hover: #f4f8f6;
|
| 178 |
+
--brand-focus: #b77a20;
|
| 179 |
+
/* Gradio theme variables, so the panel ignores Gradio's dark mode. */
|
| 180 |
+
--body-text-color: #203c3a;
|
| 181 |
+
--body-text-color-subdued: #526b68;
|
| 182 |
+
--block-background-fill: #f4f8f6;
|
| 183 |
+
--background-fill-primary: #f4f8f6;
|
| 184 |
+
--background-fill-secondary: #e3ece7;
|
| 185 |
+
--block-label-background-fill: #f4f8f6;
|
| 186 |
+
--block-label-text-color: #29433f;
|
| 187 |
+
--block-title-text-color: #203c3a;
|
| 188 |
+
--block-title-background-fill: transparent;
|
| 189 |
+
--block-title-border-color: transparent;
|
| 190 |
+
--block-info-text-color: #526b68;
|
| 191 |
+
--block-border-color: #bdcdc5;
|
| 192 |
+
--border-color-primary: #b3c7bd;
|
| 193 |
+
--input-background-fill: #ffffff;
|
| 194 |
+
--input-background-fill-hover: #f4f8f6;
|
| 195 |
+
--input-background-fill-focus: #ffffff;
|
| 196 |
+
--input-border-color: #b3c7bd;
|
| 197 |
+
--input-text-color: #1c3536;
|
| 198 |
+
--input-placeholder-color: #526b68;
|
| 199 |
+
--accordion-text-color: #203c3a;
|
| 200 |
+
--checkbox-background-color: #ffffff;
|
| 201 |
+
--checkbox-border-color: #8aa49c;
|
| 202 |
+
--checkbox-label-background-fill: #f4f8f6;
|
| 203 |
+
--checkbox-label-text-color: #203c3a;
|
| 204 |
+
--button-secondary-background-fill: #f4f8f6;
|
| 205 |
+
--button-secondary-background-fill-hover: #dce9e1;
|
| 206 |
+
--button-secondary-text-color: #203c3a;
|
| 207 |
+
--button-secondary-text-color-hover: #17242b;
|
| 208 |
+
--button-secondary-border-color: #b3c7bd;
|
| 209 |
+
--link-text-color: #725020;
|
| 210 |
+
--table-even-background-fill: #ffffff;
|
| 211 |
+
--table-odd-background-fill: #f4f8f6;
|
| 212 |
+
}
|
| 213 |
+
.brand-dock .prose, .brand-dock .prose strong { color: var(--brand-mint-text) !important; }
|
| 214 |
+
.brand-dock label, .brand-dock .label-wrap, .brand-dock .label-wrap span {
|
| 215 |
+
color: var(--brand-mint-label) !important;
|
| 216 |
+
background: transparent !important;
|
| 217 |
+
}
|
| 218 |
+
.brand-dock input[type="number"], .brand-dock input[type="text"], .brand-dock textarea {
|
| 219 |
+
max-width: 100%;
|
| 220 |
+
color: #1c3536 !important;
|
| 221 |
+
-webkit-text-fill-color: #1c3536 !important;
|
| 222 |
+
background: #ffffff !important;
|
| 223 |
+
}
|
| 224 |
+
.brand-dock .block-info { color: var(--brand-mint-subdued) !important; }
|
| 225 |
+
.brand-dock button:focus-visible { outline: 3px solid var(--brand-amber-deep) !important; outline-offset: 2px; }
|
| 226 |
+
|
| 227 |
+
/* Model and status line at the top left of the stage. */
|
| 228 |
+
.brand-caption, .brand-caption .prose, .brand-caption p {
|
| 229 |
+
color: var(--brand-stage-caption) !important;
|
| 230 |
+
font: 13px/1.5 var(--brand-sans) !important;
|
| 231 |
+
}
|
| 232 |
+
.brand-caption strong { color: var(--brand-amber) !important; font-weight: 600; }
|
| 233 |
+
|
| 234 |
+
/* Round "change model" button, bottom right, outside the panel.
|
| 235 |
+
Its text stays as the accessible name; the ↺ glyph is drawn instead.
|
| 236 |
+
.st-key-clear_model is the Streamlit wrapper of Token Visualiser's button. */
|
| 237 |
+
.return-home, .st-key-clear_model button {
|
| 238 |
+
position: fixed !important;
|
| 239 |
+
right: max(16px, env(safe-area-inset-right));
|
| 240 |
+
bottom: max(16px, env(safe-area-inset-bottom));
|
| 241 |
+
z-index: 60;
|
| 242 |
+
display: flex !important;
|
| 243 |
+
align-items: center;
|
| 244 |
+
justify-content: center;
|
| 245 |
+
box-sizing: border-box;
|
| 246 |
+
width: 40px !important;
|
| 247 |
+
height: 40px !important;
|
| 248 |
+
min-width: 40px !important;
|
| 249 |
+
min-height: 40px !important;
|
| 250 |
+
padding: 0 !important;
|
| 251 |
+
border: 1px solid #86b6b366 !important;
|
| 252 |
+
border-radius: 50% !important;
|
| 253 |
+
background: #112530ed !important;
|
| 254 |
+
color: var(--brand-stage-caption) !important;
|
| 255 |
+
font-size: 0 !important;
|
| 256 |
+
box-shadow: 0 3px 16px #0004;
|
| 257 |
+
cursor: pointer;
|
| 258 |
+
}
|
| 259 |
+
.return-home::before, .st-key-clear_model button::before {
|
| 260 |
+
content: "\21ba";
|
| 261 |
+
font: 22px/1 var(--brand-sans);
|
| 262 |
+
color: var(--brand-stage-caption);
|
| 263 |
+
}
|
| 264 |
+
.return-home::after, .st-key-clear_model button::after {
|
| 265 |
+
content: var(--brand-return-label, "Change model");
|
| 266 |
+
position: absolute;
|
| 267 |
+
top: 50%;
|
| 268 |
+
right: 50px;
|
| 269 |
+
transform: translateY(-50%);
|
| 270 |
+
padding: 5px 9px;
|
| 271 |
+
border: 1px solid #78949d66;
|
| 272 |
+
border-radius: 7px;
|
| 273 |
+
background: #07121ff5;
|
| 274 |
+
color: #e2edf0;
|
| 275 |
+
font: 12px/1.4 var(--brand-sans);
|
| 276 |
+
white-space: nowrap;
|
| 277 |
+
opacity: 0;
|
| 278 |
+
pointer-events: none;
|
| 279 |
+
transition: opacity .15s;
|
| 280 |
+
}
|
| 281 |
+
.return-home:hover, .st-key-clear_model button:hover { background: #23434d !important; }
|
| 282 |
+
.return-home:hover::after, .return-home:focus-visible::after,
|
| 283 |
+
.st-key-clear_model button:hover::after, .st-key-clear_model button:focus-visible::after { opacity: 1; }
|
| 284 |
+
.return-home:focus-visible, .st-key-clear_model button:focus-visible {
|
| 285 |
+
outline: 2px solid var(--brand-amber) !important;
|
| 286 |
+
outline-offset: 3px;
|
| 287 |
+
}
|
| 288 |
+
@media (max-width: 640px) {
|
| 289 |
+
.return-home, .st-key-clear_model button { right: 12px; bottom: 12px; }
|
| 290 |
+
}
|
| 291 |
+
|
| 292 |
+
/* Gradio's "Use via API · Built with Gradio" footer. */
|
| 293 |
+
footer { display: none !important; }
|
brand_theme.py
ADDED
|
@@ -0,0 +1,61 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
"""Gradio theme shared by the Spaces in this folder.
|
| 2 |
+
|
| 3 |
+
Canonical copy: shared-ui/brand_theme.py. Edit it there, then run
|
| 4 |
+
`python shared-ui/sync.py` to copy it into each project.
|
| 5 |
+
|
| 6 |
+
The start page follows the browser's light/dark setting: plain keys hold the
|
| 7 |
+
light palette and `*_dark` keys the dark one. The workspace sets its own colours
|
| 8 |
+
(see brand.css), so it looks the same in both modes.
|
| 9 |
+
"""
|
| 10 |
+
import gradio as gr
|
| 11 |
+
|
| 12 |
+
LIGHT = {
|
| 13 |
+
"body_background_fill": "#f4f8f6", "body_text_color": "#203c3a",
|
| 14 |
+
"body_text_color_subdued": "#526b68", "background_fill_primary": "#f4f8f6",
|
| 15 |
+
"background_fill_secondary": "#eaf2ef", "block_background_fill": "#ffffff",
|
| 16 |
+
"block_border_color": "#cfdcd6", "block_label_background_fill": "#ffffff",
|
| 17 |
+
"block_label_text_color": "#29433f", "block_title_background_fill": "transparent",
|
| 18 |
+
"block_title_text_color": "#203c3a", "block_info_text_color": "#526b68",
|
| 19 |
+
"panel_background_fill": "#eaf2ef", "input_background_fill": "#ffffff",
|
| 20 |
+
"input_background_fill_hover": "#f4f8f6", "input_background_fill_focus": "#ffffff",
|
| 21 |
+
"input_border_color": "#b3c7bd", "input_placeholder_color": "#6b827e",
|
| 22 |
+
"accordion_text_color": "#203c3a", "border_color_primary": "#b3c7bd",
|
| 23 |
+
"button_secondary_background_fill": "#eaf2ef", "button_secondary_background_fill_hover": "#dce9e1",
|
| 24 |
+
"button_secondary_text_color": "#203c3a", "button_secondary_text_color_hover": "#17242b",
|
| 25 |
+
"link_text_color": "#92601c", "link_text_color_hover": "#b77a20",
|
| 26 |
+
}
|
| 27 |
+
DARK = {
|
| 28 |
+
"body_background_fill": "#080f18", "body_text_color": "#eef3f5",
|
| 29 |
+
"body_text_color_subdued": "#a8bdc4", "background_fill_primary": "#091622",
|
| 30 |
+
"background_fill_secondary": "#112530", "block_background_fill": "#091622",
|
| 31 |
+
"block_border_color": "#577f89", "block_label_background_fill": "#091622",
|
| 32 |
+
"block_label_text_color": "#eef3f5", "block_title_background_fill": "transparent",
|
| 33 |
+
"block_title_text_color": "#eef3f5", "block_info_text_color": "#a8bdc4",
|
| 34 |
+
"panel_background_fill": "#091622", "input_background_fill": "#112530",
|
| 35 |
+
"input_background_fill_hover": "#193442", "input_background_fill_focus": "#112530",
|
| 36 |
+
"input_border_color": "#577f89", "input_placeholder_color": "#a8bdc4",
|
| 37 |
+
"accordion_text_color": "#eef3f5", "border_color_primary": "#577f89",
|
| 38 |
+
"button_secondary_background_fill": "#193442", "button_secondary_background_fill_hover": "#577f89",
|
| 39 |
+
"button_secondary_text_color": "#eef3f5", "button_secondary_text_color_hover": "#ffffff",
|
| 40 |
+
"link_text_color": "#f4bf67", "link_text_color_hover": "#f8d49a",
|
| 41 |
+
}
|
| 42 |
+
# Same system font stack as brand.css (--brand-sans) and Token Visualiser's Streamlit theme.
|
| 43 |
+
FONT = ["system-ui", "-apple-system", "Segoe UI", "Roboto", "sans-serif"]
|
| 44 |
+
# Amber primary actions and plain bordered inputs (as in Token Visualiser) in both modes.
|
| 45 |
+
PRIMARY = {
|
| 46 |
+
"input_border_width": "1px", "input_shadow": "none",
|
| 47 |
+
"input_shadow_focus": "0 0 0 2px #f4bf6733", "input_border_color_focus": "#f4bf67",
|
| 48 |
+
"button_primary_background_fill": "#f4bf67", "button_primary_background_fill_hover": "#e7aa45",
|
| 49 |
+
"button_primary_text_color": "#17242b", "button_primary_text_color_hover": "#17242b",
|
| 50 |
+
"button_primary_border_color": "#f4bf67", "button_primary_border_color_hover": "#e7aa45",
|
| 51 |
+
}
|
| 52 |
+
|
| 53 |
+
|
| 54 |
+
# Settings Gradio applies to both modes at once (no *_dark variant).
|
| 55 |
+
BOTH_MODES = {"input_radius": "10px"}
|
| 56 |
+
|
| 57 |
+
|
| 58 |
+
def brand_theme():
|
| 59 |
+
values = {**LIGHT, **PRIMARY, **BOTH_MODES}
|
| 60 |
+
values.update({key + "_dark": value for key, value in {**DARK, **PRIMARY}.items()})
|
| 61 |
+
return gr.themes.Soft(primary_hue="amber", neutral_hue="stone", font=FONT).set(**values)
|
hf_login.py
CHANGED
|
@@ -1,37 +1,54 @@
|
|
| 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 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
"""Hugging Face sign-in shared by the Gradio Spaces in this folder.
|
| 2 |
+
|
| 3 |
+
Canonical copy: shared-ui/hf_login.py. Edit it there, then run
|
| 4 |
+
`python shared-ui/sync.py` to copy it into each project.
|
| 5 |
+
|
| 6 |
+
The button opens the OAuth route of the Space's canonical *.hf.space origin in
|
| 7 |
+
the same tab (target `_top`). The cookie-based round trip therefore happens
|
| 8 |
+
outside the huggingface.co iframe and then returns to the app. Gradio's own
|
| 9 |
+
OAuth state validation, callback, expiry checks and logout stay in use.
|
| 10 |
+
Only basic profile identity is requested.
|
| 11 |
+
"""
|
| 12 |
+
import json
|
| 13 |
+
import os
|
| 14 |
+
import re
|
| 15 |
+
|
| 16 |
+
import gradio as gr
|
| 17 |
+
|
| 18 |
+
HOST_PATTERN = re.compile(r"[a-z0-9][a-z0-9-]*\.hf\.space")
|
| 19 |
+
|
| 20 |
+
|
| 21 |
+
def canonical_space_origin():
|
| 22 |
+
"""The Space's canonical https origin, or None when not running on Spaces."""
|
| 23 |
+
host = os.environ.get("SPACE_HOST", "").split(",", 1)[0].strip().lower()
|
| 24 |
+
if not host:
|
| 25 |
+
return None
|
| 26 |
+
if not HOST_PATTERN.fullmatch(host):
|
| 27 |
+
raise ValueError("Expected the canonical hf.space hostname for OAuth.")
|
| 28 |
+
return "https://" + host
|
| 29 |
+
|
| 30 |
+
|
| 31 |
+
def login_redirect_js(default_value):
|
| 32 |
+
# Outside Spaces (local runs) the page's own origin is used, which reaches
|
| 33 |
+
# Gradio's local mocked sign-in.
|
| 34 |
+
return """(buttonValue) => {
|
| 35 |
+
const origin = ORIGIN || window.location.origin;
|
| 36 |
+
const route = buttonValue === DEFAULT ? '/login/huggingface' : '/logout';
|
| 37 |
+
const url = new URL(route, origin);
|
| 38 |
+
url.searchParams.set('_target_url', '/');
|
| 39 |
+
window.open(url.href, '_top');
|
| 40 |
+
}""".replace("ORIGIN", json.dumps(canonical_space_origin())).replace("DEFAULT", json.dumps(default_value))
|
| 41 |
+
|
| 42 |
+
|
| 43 |
+
class TopLevelLoginButton(gr.LoginButton):
|
| 44 |
+
"""Gradio's LoginButton, rendered as a normal button, signing in in the same tab."""
|
| 45 |
+
|
| 46 |
+
def get_block_name(self):
|
| 47 |
+
return "button"
|
| 48 |
+
|
| 49 |
+
def get_block_class(self):
|
| 50 |
+
return "button"
|
| 51 |
+
|
| 52 |
+
def activate(self):
|
| 53 |
+
self.click(fn=None, inputs=[self], outputs=None, js=login_redirect_js(self.value))
|
| 54 |
+
self.attach_load_event(self._check_login_status, None)
|
style.css
CHANGED
|
@@ -1,218 +1,203 @@
|
|
| 1 |
-
.gradio-container { max-width: 1600px !important; margin: auto; }
|
| 2 |
-
|
| 3 |
-
|
| 4 |
-
|
| 5 |
-
|
| 6 |
-
|
| 7 |
-
|
| 8 |
-
.
|
| 9 |
-
.
|
| 10 |
-
.
|
| 11 |
-
.candidate {
|
| 12 |
-
.
|
| 13 |
-
.
|
| 14 |
-
|
| 15 |
-
|
| 16 |
-
|
| 17 |
-
|
| 18 |
-
|
| 19 |
-
#
|
| 20 |
-
#
|
| 21 |
-
#
|
| 22 |
-
|
| 23 |
-
|
| 24 |
-
|
| 25 |
-
|
| 26 |
-
|
| 27 |
-
.space-
|
| 28 |
-
.space-
|
| 29 |
-
.space-bottom {
|
| 30 |
-
.space-
|
| 31 |
-
.space-
|
| 32 |
-
.space-
|
| 33 |
-
.space-
|
| 34 |
-
@media(max-width:640px)
|
| 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 |
-
.paused-token-reader
|
| 64 |
-
.token-
|
| 65 |
-
.paused-token-
|
| 66 |
-
.
|
| 67 |
-
|
| 68 |
-
|
| 69 |
-
.
|
| 70 |
-
.
|
| 71 |
-
|
| 72 |
-
.generation-
|
| 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 |
-
.attention-
|
| 123 |
-
.attention-
|
| 124 |
-
|
| 125 |
-
|
| 126 |
-
|
| 127 |
-
.layer-controls label
|
| 128 |
-
.layer-
|
| 129 |
-
.layer-
|
| 130 |
-
.layer-
|
| 131 |
-
.layer-
|
| 132 |
-
.layer-
|
| 133 |
-
.layer-
|
| 134 |
-
.layer-
|
| 135 |
-
.layer-
|
| 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 |
-
.connection-
|
| 171 |
-
|
| 172 |
-
.representation-
|
| 173 |
-
|
| 174 |
-
|
| 175 |
-
.representation-
|
| 176 |
-
.representation-
|
| 177 |
-
.representation-
|
| 178 |
-
.representation-
|
| 179 |
-
.representation-
|
| 180 |
-
.representation-actions
|
| 181 |
-
.representation-actions button
|
| 182 |
-
.representation-actions label {
|
| 183 |
-
.representation-
|
| 184 |
-
|
| 185 |
-
|
| 186 |
-
|
| 187 |
-
.
|
| 188 |
-
@media(
|
| 189 |
-
|
| 190 |
-
|
| 191 |
-
|
| 192 |
-
|
| 193 |
-
|
| 194 |
-
|
| 195 |
-
|
| 196 |
-
|
| 197 |
-
|
| 198 |
-
|
| 199 |
-
|
| 200 |
-
}
|
| 201 |
-
|
| 202 |
-
.dimension-
|
| 203 |
-
@media(
|
| 204 |
-
.dimension-axes-top { display:flex;align-items:center;justify-content:space-between;gap:8px; }
|
| 205 |
-
.dimension-axes-top label { display:flex;align-items:center;flex-wrap:wrap;gap:5px;font:600 12px/1.4 system-ui,sans-serif; }
|
| 206 |
-
.dimension-axes-top input[type="checkbox"] { appearance:none !important; -webkit-appearance:none !important; display:inline-block !important; position:relative; flex:0 0 22px; width:22px !important; height:22px !important; margin:0 5px 0 0 !important; padding:0 !important; border:2px solid #eef3f5 !important; border-radius:4px; background:#112530 !important; cursor:pointer; }
|
| 207 |
-
.dimension-axes-top input[type="checkbox"]:checked { border-color:#f4bf67 !important; background:#f4bf67 !important; }
|
| 208 |
-
.dimension-axes-top input[type="checkbox"]:checked::after { content:""; position:absolute; left:6px; top:2px; width:6px; height:11px; border:solid #091622; border-width:0 3px 3px 0; transform:rotate(45deg); }
|
| 209 |
-
.dimension-axes-top input[type="checkbox"]:focus-visible { outline:2px solid #f4bf67 !important; outline-offset:4px; }
|
| 210 |
-
.dimension-axes-top button { padding:3px 7px;border:1px solid #6b8796;border-radius:5px;background:#112530;color:#eef3f5 !important;font:12px/1.4 system-ui,sans-serif;cursor:pointer; }
|
| 211 |
-
.dimension-axes-options[hidden] { display:none !important; }
|
| 212 |
-
.dimension-axes-options { padding-top:10px; }
|
| 213 |
-
.dimension-axes-options label { display:flex;flex-direction:column;gap:6px;margin:9px 0;font:12px/1.5 system-ui,sans-serif; }
|
| 214 |
-
.dimension-axes-options select { padding:5px 8px;border:1px solid #6b8796;border-radius:6px;background:#112530; }
|
| 215 |
-
.dimension-axes-options p { font:12px/1.55 system-ui,sans-serif; margin:8px 0; }
|
| 216 |
-
.dimension-axes-controls label,.dimension-axes-controls span,.dimension-axes-controls p { color:#eef3f5 !important; }
|
| 217 |
-
.dimension-axis-status { color:#f4bf67 !important; }
|
| 218 |
-
@media(max-width:640px) { .dimension-axes-controls { right:12px; top:calc(20dvh + 100px); bottom:auto; width:calc(100vw - 24px); max-width:360px; max-height:22dvh; padding:12px 14px; } .dimension-axes-top label { font-size:11px; } .dimension-axes-top button { font-size:11px; } }
|
|
|
|
| 1 |
+
.gradio-container { max-width: 1600px !important; margin: auto; }
|
| 2 |
+
/* Start page, eyebrow, title, dock and round return button: see brand.css (shared-ui/). */
|
| 3 |
+
#page textarea { font: 18px/1.65 Georgia, 'Times New Roman', serif !important; padding: 14px 20px !important; }
|
| 4 |
+
.inspector { padding: 22px; border: 1px solid #82968b40; border-radius: 14px; min-height: 230px; }
|
| 5 |
+
.inspector h3 { font: 26px/1.2 Georgia, serif; margin: 12px 0; }
|
| 6 |
+
.inspector p, .inspector small { opacity: .75; line-height: 1.6; }
|
| 7 |
+
.candidate { padding: 8px 10px; margin: 6px 0; border-radius: 8px; }
|
| 8 |
+
.candidate.selected { background: #f4bf6726; outline: 1px solid #f4bf6780; }
|
| 9 |
+
.candidate-label { display: flex; justify-content: space-between; gap: 12px; font-size: 12px; }
|
| 10 |
+
.candidate-label code { white-space: pre-wrap; overflow-wrap: anywhere; }
|
| 11 |
+
.candidate small { font-size: 10px; }
|
| 12 |
+
.track { height: 5px; background: #82968b20; border-radius: 8px; margin: 7px 0 3px; overflow: hidden; }
|
| 13 |
+
.track div { height: 100%; background: #f4bf67; border-radius: 8px; }
|
| 14 |
+
|
| 15 |
+
#flow-workspace { gap:10px; }
|
| 16 |
+
#workspace-top textarea { font-size:11px; }
|
| 17 |
+
#sampling-controls { gap:8px; }
|
| 18 |
+
#space-scene { padding:0 !important; border:0 !important; }
|
| 19 |
+
#token-universe { position:relative; height:clamp(340px,55vh,800px); overflow:hidden; border-radius:16px; background:#080f18; color:#bdd8dd; }
|
| 20 |
+
#token-universe canvas { width:100%; height:100%; display:block; cursor:grab; touch-action:none; }
|
| 21 |
+
#token-universe canvas:active { cursor:grabbing; }
|
| 22 |
+
.space-top,.space-bottom { position:absolute; left:22px; right:22px; display:flex; justify-content:space-between; gap:16px; pointer-events:none; font:11px/1.5 system-ui,sans-serif; }
|
| 23 |
+
.space-top { top:18px; letter-spacing:.12em; }
|
| 24 |
+
.space-bottom { bottom:16px; opacity:.6; }
|
| 25 |
+
.space-brand { color:#f4bf67; }
|
| 26 |
+
.space-empty { position:absolute; inset:0; display:flex; flex-direction:column; align-items:center; justify-content:center; gap:14px; pointer-events:none; font:clamp(20px,3vw,34px)/1.4 Georgia,serif; color:#b9d0d4; }
|
| 27 |
+
.space-empty small { font:13px/1.5 system-ui,sans-serif; opacity:.65; }
|
| 28 |
+
.space-transport { display:none !important; }
|
| 29 |
+
@media(max-width:640px) { .space-bottom { font-size:9px;left:12px;right:12px; } .space-top { left:12px;right:12px;font-size:9px; } }
|
| 30 |
+
.space-tools { position:absolute; top:48px; left:22px; right:22px; display:flex; align-items:center; gap:14px; flex-wrap:wrap; font:12px/1.4 system-ui,sans-serif; }
|
| 31 |
+
.space-tools label { display:flex; align-items:center; gap:7px; color:#c2dadc; }
|
| 32 |
+
.space-tools select,.space-tools button { border:1px solid #577f89; border-radius:7px; padding:6px 8px; background:#112530; color:#d6e9e9; cursor:pointer; font:inherit; }
|
| 33 |
+
.space-detail { position:absolute; left:22px; bottom:44px; max-width:min(650px,85%); padding:8px 12px; border-radius:7px; background:#0a1726d9; color:#c4d8da; font:11px/1.5 system-ui,sans-serif; pointer-events:none; }
|
| 34 |
+
@media(max-width:640px){ .space-tools{top:43px;left:12px;right:12px;gap:7px;font-size:10px;} .space-detail{left:12px;bottom:55px;font-size:10px;} .space-bottom{flex-wrap:wrap;} }
|
| 35 |
+
/* Loaded experience: a viewport-sized canvas with text and controls above it. */
|
| 36 |
+
.gradio-container { max-width:none !important; min-height:100dvh !important; }
|
| 37 |
+
#flow-workspace { position:fixed !important; inset:0 !important; width:100vw !important; height:100dvh !important; margin:0 !important; padding:0 !important; gap:0 !important; overflow:hidden !important; background:#080f18; z-index:50; }
|
| 38 |
+
#space-scene { position:absolute !important; inset:0 !important; width:100% !important; height:100% !important; z-index:0; }
|
| 39 |
+
#token-universe { width:100%; height:100% !important; border-radius:0 !important; }
|
| 40 |
+
#page { position:absolute !important; top:max(18px,env(safe-area-inset-top)); left:clamp(16px,4vw,72px); right:clamp(16px,4vw,72px); width:auto !important; z-index:2; padding:0 !important; border:1px solid #b4dad52b !important; border-radius:16px !important; background:#091622 !important; backdrop-filter:blur(10px); box-shadow:0 10px 40px #0003; }
|
| 41 |
+
#page textarea { height:clamp(110px,22vh,240px) !important; min-height:110px !important; max-height:45vh !important; overflow-y:auto !important; resize:vertical !important; color:#e0eeeb !important; background:transparent !important; border:none !important; font:clamp(16px,1.5vw,21px)/1.7 Georgia,serif !important; padding:20px 24px !important; scrollbar-color:#668c8b #10232d; }
|
| 42 |
+
#page > div { background:transparent !important; }
|
| 43 |
+
#control-dock { position:absolute !important; bottom:max(16px,env(safe-area-inset-bottom)); left:50%; transform:translateX(-50%); width:min(940px,calc(100vw - 32px)) !important; max-height:65dvh; overflow-y:auto; z-index:4; padding:12px !important; gap:8px !important; }
|
| 44 |
+
#stream-buttons { gap:10px !important; flex-wrap:nowrap !important; }
|
| 45 |
+
#stream-buttons button { min-height:44px; min-width:0 !important; }
|
| 46 |
+
#settings-drawer { border:0 !important; background:transparent !important; }
|
| 47 |
+
#sampling-controls { flex-wrap:wrap; }
|
| 48 |
+
#sampling-controls > div { min-width:180px !important; }
|
| 49 |
+
.space-top { top:auto !important; bottom:8px; left:18px; right:18px; font-size:9px; opacity:.5; }
|
| 50 |
+
.space-tools { top:auto !important; bottom:150px; left:24px; right:24px; justify-content:center; gap:10px; z-index:1; }
|
| 51 |
+
.space-detail { bottom:203px; left:24px; max-width:min(720px,calc(100vw - 48px)); z-index:1; }
|
| 52 |
+
.space-bottom { display:none !important; }
|
| 53 |
+
@media(max-width:640px) { #page { left:12px;right:12px;top:12px; } #page textarea { height:20vh !important; font-size:16px !important; padding:12px 16px !important; } #control-dock { bottom:12px;width:calc(100vw - 24px) !important;padding:8px !important;max-height:60dvh; } .space-tools { bottom:145px;left:12px;right:12px;font-size:10px;gap:6px; } .space-detail { bottom:228px;left:12px;max-width:calc(100vw - 24px);font-size:10px; } }
|
| 54 |
+
#token-universe { position:fixed !important; inset:0 !important; width:100vw !important; height:100dvh !important; }
|
| 55 |
+
#stream-buttons { position:sticky; top:0; z-index:6; background:#eaf2eff2; }
|
| 56 |
+
#page[data-token-inspection="true"] textarea { display:none !important; }
|
| 57 |
+
.paused-token-reader { position:relative; height:clamp(110px,22vh,240px); max-height:45vh; overflow-y:auto; padding:14px 24px 20px; color:#e0eeeb; font:clamp(16px,1.5vw,21px)/1.7 Georgia,serif; scrollbar-color:#668c8b #10232d; }
|
| 58 |
+
.token-reader-hint { position:sticky; top:-14px; padding:6px 0 10px; background:#0c1c27f5; color:#f4bf67; font:11px/1.4 system-ui,sans-serif; letter-spacing:.04em; z-index:1; }
|
| 59 |
+
.paused-token-content { white-space:pre-wrap; overflow-wrap:anywhere; }
|
| 60 |
+
.paused-token-reader button.text-token { all:unset; display:inline; white-space:pre-wrap; font:inherit; color:inherit; cursor:pointer; border-radius:4px; }
|
| 61 |
+
.paused-token-reader button.text-token:hover { background:#ffffff20; box-shadow:0 0 0 1px #f4bf6766; }
|
| 62 |
+
.paused-token-reader button.text-token.is-selected { background:#f4bf67; color:#17242b; box-shadow:0 0 0 2px #f4bf6755; }
|
| 63 |
+
.paused-token-reader button.text-token:focus-visible { outline:2px solid #f4bf67; outline-offset:2px; }
|
| 64 |
+
.token-piece-choices { margin-top:8px; color:#b4cdd2; font:12px/1.7 ui-monospace,monospace; }
|
| 65 |
+
@media(max-width:640px){.paused-token-reader { height:20vh;padding:12px 16px;font-size:16px; }}
|
| 66 |
+
.generation-proxy { display:none !important; }
|
| 67 |
+
#generation-toggle { border:0 !important; padding:0 !important; background:transparent !important; flex:3 !important; min-width:0 !important; }
|
| 68 |
+
|
| 69 |
+
.generation-toggle-button { width:100%; min-height:44px; padding:10px 18px; border:0; border-radius:10px; background:#f4bf67; color:#17242b; font:600 16px/1.4 system-ui,sans-serif; cursor:pointer; box-shadow:0 2px 8px #173c381a; }
|
| 70 |
+
.generation-toggle-button:hover { background:#e7aa45; }
|
| 71 |
+
.generation-toggle-button:disabled { opacity:.65; cursor:wait; }
|
| 72 |
+
.generation-toggle-button:focus-visible { outline:3px solid #f4bf67; outline-offset:2px; }
|
| 73 |
+
|
| 74 |
+
/* Model caption and compact reset remain outside the expandable dock. */
|
| 75 |
+
#text-overlay { position:absolute !important; top:max(18px,env(safe-area-inset-top)); left:clamp(16px,4vw,72px); right:clamp(16px,4vw,72px); width:auto !important; gap:7px !important; z-index:2; }
|
| 76 |
+
#model-name { padding:0 24px !important; border:0 !important; min-height:18px !important; background:transparent !important; color:#c5e2dd; text-align:left; font:600 13px/1.5 system-ui,sans-serif; overflow-wrap:anywhere; }
|
| 77 |
+
#page { position:relative !important; top:auto !important; left:auto !important; right:auto !important; width:100% !important; }
|
| 78 |
+
#flow-workspace { --brand-return-label:"Change model / sign in"; }
|
| 79 |
+
#control-dock { width:min(940px,calc(100vw - 120px)) !important; }
|
| 80 |
+
@media(max-width:640px) { #text-overlay { top:12px;left:12px;right:12px;gap:5px !important; } #model-name { font-size:12px;padding:0 16px !important; } #control-dock { left:12px;transform:none;width:calc(100vw - 72px) !important; } }
|
| 81 |
+
|
| 82 |
+
/* Override theme colours on rendered HTML children and the textbox's form shell. */
|
| 83 |
+
#model-name, #model-name * { color:var(--brand-stage-caption) !important; opacity:1 !important; font:600 13px/1.5 var(--brand-sans) !important; }
|
| 84 |
+
#text-overlay { --body-text-color:#d9f6ef; --body-text-color-subdued:#a8c9c5; --block-background-fill:transparent; --input-background-fill:#091622; }
|
| 85 |
+
#text-overlay > .form { background:transparent !important; border:0 !important; border-radius:16px !important; box-shadow:none !important; overflow:hidden !important; }
|
| 86 |
+
#page { overflow:hidden !important; background:#091622 !important; background-image:none !important; box-shadow:none !important; }
|
| 87 |
+
#page > div, #page label, #page .input-container, #page .input-container:focus-within { background:transparent !important; background-image:none !important; border:0 !important; box-shadow:none !important; }
|
| 88 |
+
#page textarea { background:transparent !important; background-image:none !important; border-radius:0 !important; box-shadow:none !important; resize:none !important; }
|
| 89 |
+
|
| 90 |
+
/* Amber links the title punctuation, primary actions, focus and selections. */
|
| 91 |
+
.gradio-container { --primary-400:#f8d49a !important; --primary-500:#f4bf67 !important; --primary-600:#b77a20 !important; --color-accent:#f4bf67 !important; --color-accent-soft:#f4bf6726 !important; }
|
| 92 |
+
.space-tools button:hover,.space-tools select:focus-visible { border-color:#f4bf67; }
|
| 93 |
+
|
| 94 |
+
/* A readable attention inspector, with raw weights rather than renormalized bars. */
|
| 95 |
+
.space-detail { width:440px; max-width:calc(100vw - 48px); max-height:42dvh; overflow-y:auto; padding:18px 20px; border:1px solid #78949d45; border-radius:14px; background:#0a1726f5; color:#d5e3e6; font:14px/1.55 system-ui,sans-serif; pointer-events:auto; scrollbar-color:#687c88 #0a1726; }
|
| 96 |
+
.attention-title { margin:0 0 6px; color:#f4bf67 !important; font:600 18px/1.35 system-ui,sans-serif; overflow-wrap:anywhere; }
|
| 97 |
+
.attention-intro { margin:0 0 6px; color:#d5e3e6 !important; }
|
| 98 |
+
.attention-meta { margin:0 0 14px; color:#9fb5bd !important; font-size:12px; }
|
| 99 |
+
.attention-list { display:grid; gap:9px; }
|
| 100 |
+
.attention-item { display:grid; grid-template-columns:minmax(80px,1fr) minmax(65px,1.15fr) 48px; gap:12px; align-items:center; }
|
| 101 |
+
.attention-token { overflow:hidden; text-overflow:ellipsis; white-space:nowrap; color:#e0ebed !important; font:13px/1.5 ui-monospace,monospace; }
|
| 102 |
+
.attention-bar { height:7px; overflow:hidden; border-radius:4px; background:#ffffff15; }
|
| 103 |
+
.attention-bar-fill { display:block; height:100%; background:#f4bf67; border-radius:4px; }
|
| 104 |
+
.attention-percent { color:#f4bf67 !important; text-align:right; font-variant-numeric:tabular-nums; font-size:13px; }
|
| 105 |
+
.attention-coverage { margin:14px 0 0; color:#a8bdc4 !important; font-size:12px; }
|
| 106 |
+
.attention-help { margin-top:12px; border-top:1px solid #ffffff18; padding-top:10px; color:#b8cbd1 !important; font-size:12px; }
|
| 107 |
+
.attention-help summary { cursor:pointer; color:#f4bf67; }
|
| 108 |
+
.attention-help p { margin:9px 0 0; color:#b8cbd1 !important; }
|
| 109 |
+
@media(max-width:640px) { .space-detail { bottom:228px; width:calc(100vw - 24px); max-width:calc(100vw - 24px); max-height:30dvh; padding:14px; font-size:13px; box-sizing:border-box; } .attention-title { font-size:16px; } .attention-item { grid-template-columns:minmax(65px,1fr) minmax(50px,1fr) 43px; gap:8px; } }
|
| 110 |
+
|
| 111 |
+
.layer-controls { display:flex; flex-wrap:wrap; gap:10px; margin:12px 0; }
|
| 112 |
+
.layer-controls label { display:flex; flex-direction:column; gap:4px; color:#bacdd4; font:12px/1.4 system-ui,sans-serif; }
|
| 113 |
+
.layer-controls select { padding:6px 8px; border:1px solid #6b8796; border-radius:6px; background:#112530; color:#e0ebed; font:inherit; }
|
| 114 |
+
.layer-filter { flex:1 1 100%; }
|
| 115 |
+
.layer-filter input { width:100%; accent-color:#f4bf67; }
|
| 116 |
+
.layer-caption { margin:10px 0; color:#a8bdc4 !important; font:12px/1.5 system-ui,sans-serif; }
|
| 117 |
+
.layer-legend { display:flex; flex-wrap:wrap; gap:6px; margin-bottom:15px; }
|
| 118 |
+
.layer-chip,.layer-restore { padding:4px 8px; border:1px solid; border-radius:6px; background:#ffffff08; font:600 12px/1.5 system-ui,sans-serif; cursor:pointer; }
|
| 119 |
+
.layer-chip[aria-pressed="false"] { opacity:.35; text-decoration:line-through; }
|
| 120 |
+
.layer-chip:focus-visible,.layer-restore:focus-visible { outline:2px solid #f4bf67; outline-offset:2px; }
|
| 121 |
+
.layer-restore { border-color:#78949d; color:#d5e3e6; }
|
| 122 |
+
.attention-layer + .attention-layer { margin-top:16px; padding-top:12px; border-top:1px solid #ffffff18; }
|
| 123 |
+
.attention-layer > .attention-meta { border-left:3px solid; padding-left:8px; }
|
| 124 |
+
.space-edge-tooltip { position:fixed; z-index:9; max-width:260px; padding:8px 10px; border:1px solid #78949d66; border-radius:7px; background:#07121ff5; color:#e2edf0; font:12px/1.5 system-ui,sans-serif; pointer-events:none; }
|
| 125 |
+
.space-edge-tooltip[hidden] { display:none !important; }
|
| 126 |
+
|
| 127 |
+
.layer-controls label,.layer-controls label > span { color:#bacdd4 !important; }
|
| 128 |
+
.layer-settings > summary { cursor:pointer; color:#f4bf67 !important; font:600 12px/1.5 system-ui,sans-serif; margin:10px 0; }
|
| 129 |
+
.layer-caption-mobile { display:none; }
|
| 130 |
+
:is(.layer-controls,.representation-layer-label,.dimension-axes-options) input[type="range"] { appearance:none; height:20px; padding:0 !important; border:0 !important; background:transparent !important; box-shadow:none !important; }
|
| 131 |
+
:is(.layer-controls,.representation-layer-label,.dimension-axes-options) input[type="range"]::-webkit-slider-runnable-track { height:5px; border-radius:4px; background:#354654; }
|
| 132 |
+
:is(.layer-controls,.representation-layer-label,.dimension-axes-options) input[type="range"]::-webkit-slider-thumb { appearance:none; width:14px; height:14px; margin-top:-4.5px; border:0; border-radius:50%; background:#f4bf67; cursor:ew-resize; }
|
| 133 |
+
:is(.layer-controls,.representation-layer-label,.dimension-axes-options) input[type="range"]::-moz-range-track { height:5px; border-radius:4px; background:#354654; }
|
| 134 |
+
:is(.layer-controls,.representation-layer-label,.dimension-axes-options) input[type="range"]::-moz-range-thumb { width:14px; height:14px; border:0; border-radius:50%; background:#f4bf67; }
|
| 135 |
+
:is(.layer-controls,.representation-layer-label,.dimension-axes-options) input[type="range"]:focus-visible { outline:2px solid #f4bf67; outline-offset:3px; }
|
| 136 |
+
@media(max-width:640px) { .space-detail { max-height:max(160px,min(40dvh,calc(100dvh - 440px))); } .layer-caption-desktop { display:none; } .layer-caption-mobile { display:inline; } }
|
| 137 |
+
|
| 138 |
+
/* HTML theme rules set colours on child spans, so specify HUD text explicitly. */
|
| 139 |
+
.layer-caption,.layer-caption span { color:#a8bdc4 !important; }
|
| 140 |
+
.layer-restore { color:#d5e3e6 !important; }
|
| 141 |
+
.space-tools [data-space-step],.space-empty small { color:#b8cbd1 !important; }
|
| 142 |
+
.space-top .space-count { color:#8aa4ad !important; }
|
| 143 |
+
.space-top .space-brand { color:#f4bf67 !important; }
|
| 144 |
+
|
| 145 |
+
/* Keep native popup options and explanatory text readable on the dark canvas. */
|
| 146 |
+
#token-universe select,#token-universe select option { color:#f4f7f8 !important; background-color:#112530 !important; color-scheme:dark; opacity:1 !important; }
|
| 147 |
+
.space-tools label,.layer-controls label,.layer-controls label > span,.layer-caption,.layer-caption span,.attention-intro,.attention-meta,.attention-coverage,.attention-help p { color:#eef3f5 !important; }
|
| 148 |
+
.connection-explanation,.connection-note,.connection-selected,.connection-token { color:#eef3f5 !important; }
|
| 149 |
+
.connection-explanation { margin:8px 0 12px; font:14px/1.6 system-ui,sans-serif; }
|
| 150 |
+
.connection-note { margin:10px 0; font:13px/1.6 system-ui,sans-serif; }
|
| 151 |
+
.connection-selected { margin:16px 0 10px; font:600 13px/1.5 system-ui,sans-serif; overflow-wrap:anywhere; }
|
| 152 |
+
.connection-matches { display:grid; gap:9px; margin:12px 0; }
|
| 153 |
+
.connection-match { display:flex; justify-content:space-between; align-items:baseline; gap:12px; }
|
| 154 |
+
.connection-token { min-width:0; overflow-wrap:anywhere; font:13px/1.5 ui-monospace,monospace; }
|
| 155 |
+
.connection-score { color:#f4bf67 !important; flex-shrink:0; font:12px/1.5 ui-monospace,monospace; }
|
| 156 |
+
|
| 157 |
+
.representation-controls[hidden] { display:none !important; }
|
| 158 |
+
.representation-controls { border-bottom:1px solid #ffffff26; padding-bottom:15px; margin-bottom:15px; }
|
| 159 |
+
.representation-note,.representation-stage,.representation-layer-label,.representation-actions label { color:#eef3f5 !important; font:13px/1.55 system-ui,sans-serif; }
|
| 160 |
+
.representation-note { margin:8px 0 12px; }
|
| 161 |
+
.representation-layer-label { display:flex; flex-direction:column; gap:8px; }
|
| 162 |
+
.representation-layer-label input { width:100%; accent-color:#f4bf67; color-scheme:dark; }
|
| 163 |
+
.representation-stage { font-weight:600; color:#f4bf67 !important; margin:8px 0 12px; }
|
| 164 |
+
.representation-actions { display:flex; align-items:center; flex-wrap:wrap; gap:12px; }
|
| 165 |
+
.representation-actions button { border:1px solid #f4bf67; border-radius:7px; padding:6px 10px; background:#f4bf67; color:#17242b !important; font:600 13px/1.5 system-ui,sans-serif; cursor:pointer; }
|
| 166 |
+
.representation-actions button:disabled { opacity:.5; cursor:default; }
|
| 167 |
+
.representation-actions label { display:flex; align-items:center; gap:7px; }
|
| 168 |
+
.representation-actions input { accent-color:#f4bf67; }
|
| 169 |
+
|
| 170 |
+
.connection-detail { color:#eef3f5 !important; }
|
| 171 |
+
|
| 172 |
+
.representation-connection-details > summary { display:none; }
|
| 173 |
+
@media(max-width:640px) {
|
| 174 |
+
#token-universe[data-position-mode="representations"] .space-detail { max-height:210px; }
|
| 175 |
+
#token-universe[data-position-mode="representations"] .representation-controls { margin-bottom:8px;padding-bottom:8px; }
|
| 176 |
+
#token-universe[data-position-mode="representations"] .representation-controls > .attention-title { display:none; }
|
| 177 |
+
#token-universe[data-position-mode="representations"] .representation-note { font-size:11px;line-height:1.35;margin:0 0 6px;max-height:32px;overflow:auto; }
|
| 178 |
+
#token-universe[data-position-mode="representations"] .representation-layer-label { font-size:0;line-height:0;gap:0; }
|
| 179 |
+
#token-universe[data-position-mode="representations"] .representation-stage { font-size:12px;margin:4px 0 8px; }
|
| 180 |
+
#token-universe[data-position-mode="representations"] .representation-actions { gap:8px; }
|
| 181 |
+
#token-universe[data-position-mode="representations"] .representation-actions button { font-size:12px;padding:4px 8px; }
|
| 182 |
+
#token-universe[data-position-mode="representations"] .representation-actions label { font-size:11px; }
|
| 183 |
+
#token-universe[data-position-mode="representations"] .representation-controls .attention-help { margin-top:6px;padding-top:6px; }
|
| 184 |
+
#token-universe[data-position-mode="representations"] .representation-connection-details > summary { display:list-item;color:#f4bf67 !important;cursor:pointer;font:12px/1.5 system-ui,sans-serif;margin:6px 0; }
|
| 185 |
+
}
|
| 186 |
+
|
| 187 |
+
.dimension-axes-controls { position:absolute; right:24px; bottom:203px; z-index:1; width:360px; max-width:calc(50vw - 36px); max-height:42dvh; overflow-y:auto; box-sizing:border-box; padding:18px 20px; border:1px solid #78949d45; border-radius:14px; background:#0a1726f5; color:#eef3f5; scrollbar-color:#687c88 #0a1726; }
|
| 188 |
+
@media(min-width:641px) { .space-detail { box-sizing:border-box; max-width:calc(50vw - 36px); } }
|
| 189 |
+
.dimension-axes-top { display:flex;align-items:center;justify-content:space-between;gap:8px; }
|
| 190 |
+
.dimension-axes-top label { display:flex;align-items:center;flex-wrap:wrap;gap:5px;font:600 12px/1.4 system-ui,sans-serif; }
|
| 191 |
+
.dimension-axes-top input[type="checkbox"] { appearance:none !important; -webkit-appearance:none !important; display:inline-block !important; position:relative; flex:0 0 22px; width:22px !important; height:22px !important; margin:0 5px 0 0 !important; padding:0 !important; border:2px solid #eef3f5 !important; border-radius:4px; background:#112530 !important; cursor:pointer; }
|
| 192 |
+
.dimension-axes-top input[type="checkbox"]:checked { border-color:#f4bf67 !important; background:#f4bf67 !important; }
|
| 193 |
+
.dimension-axes-top input[type="checkbox"]:checked::after { content:""; position:absolute; left:6px; top:2px; width:6px; height:11px; border:solid #091622; border-width:0 3px 3px 0; transform:rotate(45deg); }
|
| 194 |
+
.dimension-axes-top input[type="checkbox"]:focus-visible { outline:2px solid #f4bf67 !important; outline-offset:4px; }
|
| 195 |
+
.dimension-axes-top button { padding:3px 7px;border:1px solid #6b8796;border-radius:5px;background:#112530;color:#eef3f5 !important;font:12px/1.4 system-ui,sans-serif;cursor:pointer; }
|
| 196 |
+
.dimension-axes-options[hidden] { display:none !important; }
|
| 197 |
+
.dimension-axes-options { padding-top:10px; }
|
| 198 |
+
.dimension-axes-options label { display:flex;flex-direction:column;gap:6px;margin:9px 0;font:12px/1.5 system-ui,sans-serif; }
|
| 199 |
+
.dimension-axes-options select { padding:5px 8px;border:1px solid #6b8796;border-radius:6px;background:#112530; }
|
| 200 |
+
.dimension-axes-options p { font:12px/1.55 system-ui,sans-serif; margin:8px 0; }
|
| 201 |
+
.dimension-axes-controls label,.dimension-axes-controls span,.dimension-axes-controls p { color:#eef3f5 !important; }
|
| 202 |
+
.dimension-axis-status { color:#f4bf67 !important; }
|
| 203 |
+
@media(max-width:640px) { .dimension-axes-controls { right:12px; top:calc(20dvh + 100px); bottom:auto; width:calc(100vw - 24px); max-width:360px; max-height:22dvh; padding:12px 14px; } .dimension-axes-top label { font-size:11px; } .dimension-axes-top button { font-size:11px; } }
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|