jejunepixels commited on
Commit
b07a730
·
verified ·
1 Parent(s): a02fde5

Combine start and pause controls, reset to model picker, and add Qwen and Gemma presets

Browse files
Files changed (7) hide show
  1. README.md +23 -2
  2. app.py +33 -9
  3. engine.py +3 -0
  4. models.py +11 -1
  5. style.css +7 -0
  6. token_space.js +24 -1
  7. token_space.py +3 -1
README.md CHANGED
@@ -49,8 +49,8 @@ Extract the archive and upload its nine files to the root of your Gradio Space.
49
 
50
  The opening screen shows only model selection. Successful loading hides the picker
51
  and reveals a viewport-filling 3D token view. The full generated text is retained in a
52
- scrollable, resizable top overlay. Start / Resume and Pause generation sit in a
53
- bottom overlay dock. Expand Settings, model & attention for the remaining controls.
54
  The overlay fills the app viewport, including when embedded in the Space page. **Change model**
55
  returns to the picker and requests Stop if generation is running.
56
 
@@ -136,8 +136,29 @@ attention with different layer/head settings. Resume generation continues the sa
136
  text and RNG sequence and restores the prior viewer mode. Stop keeps its normal
137
  fading behavior. Pausing also works after a pass has completed.
138
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
139
  ## Controls
140
 
 
 
 
 
 
 
 
141
  Each successful model load draws a fresh 32-bit random seed and replaces any
142
  previous manual seed in the settings field. Start / Resume uses that seed for a
143
  new stream; resuming preserves the existing RNG state. You can still enter a seed
 
49
 
50
  The opening screen shows only model selection. Successful loading hides the picker
51
  and reveals a viewport-filling 3D token view. The full generated text is retained in a
52
+ scrollable, resizable top overlay. A combined Start / Pause / Resume button and Reset sit in a
53
+ bottom overlay dock. Reset stops the current stream and returns to model selection. Expand Settings, model & attention for the remaining controls.
54
  The overlay fills the app viewport, including when embedded in the Space page. **Change model**
55
  returns to the picker and requests Stop if generation is running.
56
 
 
136
  text and RNG sequence and restores the prior viewer mode. Stop keeps its normal
137
  fading behavior. Pausing also works after a pass has completed.
138
 
139
+ ## Model presets
140
+
141
+ Eight presets are available: SmolLM2 135M and 360M, GPT-2, Qwen3 0.6B Base,
142
+ Qwen3 0.6B instruction tuned, Qwen2.5 0.5B Base, and Gemma 3 1B in base and
143
+ instruction-tuned versions. These include the model families in Token Visualiser.
144
+ Gemma uses public safetensors repositories (`unsloth/gemma-3-1b-pt` and
145
+ `unsloth/gemma-3-1b-it`) instead of the Visualiser's GGUF file. Public repository
146
+ metadata, download sizes, tokenizers, and attention-compatible model architectures
147
+ were checked; full pretrained inference was smoke-tested with the default SmolLM2.
148
+ The added model architectures were checked using reduced test configurations.
149
+ Gemma downloads about 2 GB and is slower on CPU; the Qwen models download about
150
+ 1?1.5 GB. Base models are labelled separately from instruction-tuned models.
151
+ Custom public model repository IDs and main repository URLs remain supported.
152
+
153
  ## Controls
154
 
155
+ The main button starts as Start, changes to Pause during generation, and becomes
156
+ Resume after pausing. It waits for the current inference step before enabling
157
+ Resume. After a model end token, Start begins a new stream. Reset is always next
158
+ to the combined button and returns to the model picker immediately, stopping the
159
+ current generation before clearing the session. The selected model remains in the
160
+ shared process until another model is loaded; other visitors' sessions are not reset.
161
+
162
  Each successful model load draws a fresh 32-bit random seed and replaces any
163
  previous manual seed in the settings field. Start / Resume uses that seed for a
164
  new stream; resuming preserves the existing RNG state. You can still enter a seed
app.py CHANGED
@@ -7,7 +7,7 @@ import time
7
  import gradio as gr
8
 
9
  from engine import Flow, generate
10
- from models import ModelStore, PRESETS
11
  from token_space import SCENE, frame
12
 
13
  STORE = ModelStore()
@@ -45,6 +45,8 @@ def clear(flow):
45
  flow.attention_history.clear()
46
  flow.text_snapshot_cache = None
47
  flow.paused = False
 
 
48
  flow.text = ""
49
  flow.model_key = ""
50
  flow.seed = flow.rng_state = None
@@ -86,6 +88,8 @@ def control_handler(name):
86
 
87
  def run(flow, temperature, top_p, penalty, seed, count, watch, delay, memory=128,
88
  auto_continue=True, attention=True, attention_layer=-1, attention_head=-1, fresh=False):
 
 
89
  if STORE.model is None:
90
  raise gr.Error("Load a model first.")
91
  if fresh:
@@ -102,6 +106,7 @@ def run(flow, temperature, top_p, penalty, seed, count, watch, delay, memory=128
102
  last_text = STORE.tokenizer.decode(flow.tokens, skip_special_tokens=True,
103
  clean_up_tokenization_spaces=False)
104
  trimmed = False
 
105
  try:
106
  yield last_text, panel, "Generating…", frame(flow, STORE, full=True)
107
  for step in generate(STORE.model, STORE.tokenizer, flow, STORE.key,
@@ -126,6 +131,7 @@ def run(flow, temperature, top_p, penalty, seed, count, watch, delay, memory=128
126
  delay = flow.controls()["delay"]
127
  if delay and flow.stop.wait(float(delay)):
128
  break
 
129
  if flow.ended:
130
  reason = "The model emitted an end token. Start fresh to begin another stream."
131
  elif len(flow.tokens) >= 16384:
@@ -141,8 +147,11 @@ def run(flow, temperature, top_p, penalty, seed, count, watch, delay, memory=128
141
  controls = flow.controls()
142
  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, STORE, full=True)
143
  except Exception as error:
 
144
  # Preserve already-generated text and RNG state so a failed pass can be retried.
145
  raise gr.Error(str(error)) from error
 
 
146
 
147
 
148
  def begin(*args):
@@ -164,10 +173,17 @@ def reset_view(flow):
164
 
165
 
166
  def choose_model(flow):
 
 
167
  flow.stop.set()
168
  return gr.update(visible=True), gr.update(visible=False)
169
 
170
 
 
 
 
 
 
171
  def build_app():
172
  css = Path(__file__).with_name("style.css").read_text(encoding="utf-8")
173
  js = Path(__file__).with_name("token_space.js").read_text(encoding="utf-8")
@@ -177,12 +193,15 @@ def build_app():
177
  with gr.Column(elem_id="model-picker") as picker:
178
  gr.HTML('<header><div class="eyebrow">AN EXPERIMENT IN AUTOMATIC WRITING</div>'
179
  '<h1>Let it flow<span>.</span></h1><p>Choose a model. Enter its token space.</p></header>')
180
- repo = gr.Dropdown(PRESETS, value=PRESETS[0], allow_custom_value=True,
181
  label="Public model repository or Hugging Face URL")
182
  load = gr.Button("Load model & enter space", variant="primary")
183
  gr.Markdown("Small **base models** work best. Public safetensors models only; "
184
  "2 GB download limit. One model is shared by visitors. "
185
  "Loading includes preparing a fixed 3D embedding projection.")
 
 
 
186
  with gr.Column(visible=False, elem_id="flow-workspace") as workspace:
187
  gr.HTML(SCENE, elem_id="space-scene")
188
  page = gr.Textbox(label="The stream", lines=5, max_lines=8,
@@ -190,8 +209,9 @@ def build_app():
190
  interactive=False, show_copy_button=True, elem_id="page")
191
  with gr.Column(elem_id="control-dock"):
192
  with gr.Row(elem_id="stream-buttons"):
193
- start = gr.Button("Start / Resume", variant="primary")
194
- pause = gr.Button("Pause generation")
 
195
  with gr.Accordion("Settings, model & attention", open=False, elem_id="settings-drawer"):
196
  with gr.Row(elem_id="sampling-controls"):
197
  temperature = gr.Slider(.05, 2, value=1.3, step=.05, label="Temperature")
@@ -214,12 +234,11 @@ def build_app():
214
  info="Used when automatic continuation is off.")
215
  delay = gr.Slider(0, .5, value=.06, step=.02, label="Reading delay per token (seconds)")
216
  with gr.Row():
217
- new_stream = gr.Button("New stream")
218
  halt = gr.Button("Stop", variant="stop")
219
  reset = gr.Button("Clear stream")
220
  status = gr.Textbox(label="Stream status", value="Press Start to let it flow.", interactive=False)
221
  model_status = gr.Textbox(label="Loaded model", interactive=False)
222
- change_model = gr.Button("Change model", size="sm")
223
  watch = gr.Checkbox(label="Watch the next token", value=True)
224
  panel = gr.HTML(EMPTY)
225
  with gr.Row():
@@ -230,6 +249,8 @@ def build_app():
230
  "selected layer/head while predicting the following token; they are not a complete explanation. "
231
  "Sliders apply live. The top overlay retains the full generated text; scroll it to read earlier passages.")
232
  transport = gr.HTML('', elem_id="space-transport", elem_classes=["space-transport"])
 
 
233
  outputs = [page, panel, status, transport]
234
  inputs = [flow, temperature, top_p, penalty, seed, count, watch, delay, memory, auto_continue,
235
  attention, attention_layer, attention_head]
@@ -242,9 +263,12 @@ def build_app():
242
  component.input(control_handler(name), [component, flow], [], queue=False,
243
  trigger_mode="always_last", api_name=f"update_{name}", show_progress="hidden")
244
  load.click(load_model, [repo, flow], [model_status, *outputs, seed, picker, workspace], **common)
245
- change_model.click(choose_model, [flow], [picker, workspace], queue=False)
246
- start.click(run, inputs, outputs, api_name="run", **common)
247
- new_stream.click(begin, inputs, outputs, api_name="begin", **common)
 
 
 
248
  halt.click(stop, [flow], transport, queue=False)
249
  pause.click(pause_generation, [flow], [status, transport], queue=False)
250
  reset.click(reset_view, [flow], outputs, api_name="clear", **common)
 
7
  import gradio as gr
8
 
9
  from engine import Flow, generate
10
+ from models import ModelStore, PRESETS, MODEL_LABELS
11
  from token_space import SCENE, frame
12
 
13
  STORE = ModelStore()
 
45
  flow.attention_history.clear()
46
  flow.text_snapshot_cache = None
47
  flow.paused = False
48
+ flow.running = False
49
+ flow.reset_requested = False
50
  flow.text = ""
51
  flow.model_key = ""
52
  flow.seed = flow.rng_state = None
 
88
 
89
  def run(flow, temperature, top_p, penalty, seed, count, watch, delay, memory=128,
90
  auto_continue=True, attention=True, attention_layer=-1, attention_head=-1, fresh=False):
91
+ if flow.reset_requested:
92
+ return
93
  if STORE.model is None:
94
  raise gr.Error("Load a model first.")
95
  if fresh:
 
106
  last_text = STORE.tokenizer.decode(flow.tokens, skip_special_tokens=True,
107
  clean_up_tokenization_spaces=False)
108
  trimmed = False
109
+ flow.running = True
110
  try:
111
  yield last_text, panel, "Generating…", frame(flow, STORE, full=True)
112
  for step in generate(STORE.model, STORE.tokenizer, flow, STORE.key,
 
131
  delay = flow.controls()["delay"]
132
  if delay and flow.stop.wait(float(delay)):
133
  break
134
+ flow.running = False
135
  if flow.ended:
136
  reason = "The model emitted an end token. Start fresh to begin another stream."
137
  elif len(flow.tokens) >= 16384:
 
147
  controls = flow.controls()
148
  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, STORE, full=True)
149
  except Exception as error:
150
+ flow.running = False
151
  # Preserve already-generated text and RNG state so a failed pass can be retried.
152
  raise gr.Error(str(error)) from error
153
+ finally:
154
+ flow.running = False
155
 
156
 
157
  def begin(*args):
 
173
 
174
 
175
  def choose_model(flow):
176
+ flow.reset_requested = True
177
+ flow.paused = False
178
  flow.stop.set()
179
  return gr.update(visible=True), gr.update(visible=False)
180
 
181
 
182
+ def refresh_view(flow):
183
+ flow.running = False
184
+ return frame(flow, STORE, full=True)
185
+
186
+
187
  def build_app():
188
  css = Path(__file__).with_name("style.css").read_text(encoding="utf-8")
189
  js = Path(__file__).with_name("token_space.js").read_text(encoding="utf-8")
 
193
  with gr.Column(elem_id="model-picker") as picker:
194
  gr.HTML('<header><div class="eyebrow">AN EXPERIMENT IN AUTOMATIC WRITING</div>'
195
  '<h1>Let it flow<span>.</span></h1><p>Choose a model. Enter its token space.</p></header>')
196
+ repo = gr.Dropdown([(MODEL_LABELS[r], r) for r in PRESETS], value=PRESETS[0], allow_custom_value=True,
197
  label="Public model repository or Hugging Face URL")
198
  load = gr.Button("Load model & enter space", variant="primary")
199
  gr.Markdown("Small **base models** work best. Public safetensors models only; "
200
  "2 GB download limit. One model is shared by visitors. "
201
  "Loading includes preparing a fixed 3D embedding projection.")
202
+ gr.Markdown("Gemma 3 1B downloads about 2 GB and is slower on CPU. Qwen3 0.6B downloads "
203
+ "about 1.2–1.5 GB. Base models are the closest fit for prompt-free continuation. "
204
+ "Gemma presets use safetensors versions; GGUF files are not supported by this backend.")
205
  with gr.Column(visible=False, elem_id="flow-workspace") as workspace:
206
  gr.HTML(SCENE, elem_id="space-scene")
207
  page = gr.Textbox(label="The stream", lines=5, max_lines=8,
 
209
  interactive=False, show_copy_button=True, elem_id="page")
210
  with gr.Column(elem_id="control-dock"):
211
  with gr.Row(elem_id="stream-buttons"):
212
+ gr.HTML('<button type="button" class="generation-toggle-button" data-generation-toggle>Start</button>',
213
+ elem_id="generation-toggle")
214
+ reset_model = gr.Button("Reset", elem_id="reset-model")
215
  with gr.Accordion("Settings, model & attention", open=False, elem_id="settings-drawer"):
216
  with gr.Row(elem_id="sampling-controls"):
217
  temperature = gr.Slider(.05, 2, value=1.3, step=.05, label="Temperature")
 
234
  info="Used when automatic continuation is off.")
235
  delay = gr.Slider(0, .5, value=.06, step=.02, label="Reading delay per token (seconds)")
236
  with gr.Row():
237
+ new_stream = gr.Button("New stream", elem_id="generation-new")
238
  halt = gr.Button("Stop", variant="stop")
239
  reset = gr.Button("Clear stream")
240
  status = gr.Textbox(label="Stream status", value="Press Start to let it flow.", interactive=False)
241
  model_status = gr.Textbox(label="Loaded model", interactive=False)
 
242
  watch = gr.Checkbox(label="Watch the next token", value=True)
243
  panel = gr.HTML(EMPTY)
244
  with gr.Row():
 
249
  "selected layer/head while predicting the following token; they are not a complete explanation. "
250
  "Sliders apply live. The top overlay retains the full generated text; scroll it to read earlier passages.")
251
  transport = gr.HTML('', elem_id="space-transport", elem_classes=["space-transport"])
252
+ start = gr.Button("Start generation", elem_id="generation-run", elem_classes=["generation-proxy"])
253
+ pause = gr.Button("Pause generation", elem_id="generation-pause", elem_classes=["generation-proxy"])
254
  outputs = [page, panel, status, transport]
255
  inputs = [flow, temperature, top_p, penalty, seed, count, watch, delay, memory, auto_continue,
256
  attention, attention_layer, attention_head]
 
263
  component.input(control_handler(name), [component, flow], [], queue=False,
264
  trigger_mode="always_last", api_name=f"update_{name}", show_progress="hidden")
265
  load.click(load_model, [repo, flow], [model_status, *outputs, seed, picker, workspace], **common)
266
+ reset_model.click(choose_model, [flow], [picker, workspace], queue=False).then(
267
+ reset_view, [flow], outputs, api_name="reset_model_state", **common)
268
+ start.click(run, inputs, outputs, api_name="run", **common).failure(
269
+ refresh_view, [flow], transport, queue=False)
270
+ new_stream.click(begin, inputs, outputs, api_name="begin", **common).failure(
271
+ refresh_view, [flow], transport, queue=False)
272
  halt.click(stop, [flow], transport, queue=False)
273
  pause.click(pause_generation, [flow], [status, transport], queue=False)
274
  reset.click(reset_view, [flow], outputs, api_name="clear", **common)
engine.py CHANGED
@@ -14,6 +14,9 @@ class Flow:
14
  self.space_history = []
15
  self.attention_history = {}
16
  self.paused = False
 
 
 
17
  self.view_lock = threading.RLock()
18
  self.text_snapshot_cache = None
19
  self.text = text
 
14
  self.space_history = []
15
  self.attention_history = {}
16
  self.paused = False
17
+ self.running = False
18
+ self.reset_requested = False
19
+ self.view_revision = 0
20
  self.view_lock = threading.RLock()
21
  self.text_snapshot_cache = None
22
  self.text = text
models.py CHANGED
@@ -11,7 +11,17 @@ import torch
11
  from transformers import AutoConfig, AutoModelForCausalLM, AutoTokenizer
12
 
13
  CACHE = Path(__file__).parent / ".model-cache"
14
- PRESETS = ["HuggingFaceTB/SmolLM2-135M", "HuggingFaceTB/SmolLM2-360M", "openai-community/gpt2"]
 
 
 
 
 
 
 
 
 
 
15
 
16
 
17
  def repository(value):
 
11
  from transformers import AutoConfig, AutoModelForCausalLM, AutoTokenizer
12
 
13
  CACHE = Path(__file__).parent / ".model-cache"
14
+ MODEL_LABELS = {
15
+ "HuggingFaceTB/SmolLM2-135M": "SmolLM2 135M / base / quick CPU start",
16
+ "HuggingFaceTB/SmolLM2-360M": "SmolLM2 360M / base",
17
+ "openai-community/gpt2": "GPT-2 / classic base model",
18
+ "Qwen/Qwen3-0.6B-Base": "Qwen3 0.6B / base / multilingual",
19
+ "Qwen/Qwen3-0.6B": "Qwen3 0.6B / instruction tuned / Token Visualiser option",
20
+ "Qwen/Qwen2.5-0.5B": "Qwen2.5 0.5B / base / multilingual",
21
+ "unsloth/gemma-3-1b-pt": "Gemma 3 1B / base / larger CPU model",
22
+ "unsloth/gemma-3-1b-it": "Gemma 3 1B / instruction tuned / safetensors",
23
+ }
24
+ PRESETS = list(MODEL_LABELS)
25
 
26
 
27
  def repository(value):
style.css CHANGED
@@ -69,3 +69,10 @@ header p { font: 18px/1.6 Georgia, serif; color: #777; }
69
  .paused-token-reader button.text-token:focus-visible { outline:2px solid #9ce4d2; outline-offset:2px; }
70
  .token-piece-choices { margin-top:8px; color:#b4cdd2; font:12px/1.7 ui-monospace,monospace; }
71
  @media(max-width:640px){.paused-token-reader { height:20vh;padding:12px 16px;font-size:16px; }}
 
 
 
 
 
 
 
 
69
  .paused-token-reader button.text-token:focus-visible { outline:2px solid #9ce4d2; outline-offset:2px; }
70
  .token-piece-choices { margin-top:8px; color:#b4cdd2; font:12px/1.7 ui-monospace,monospace; }
71
  @media(max-width:640px){.paused-token-reader { height:20vh;padding:12px 16px;font-size:16px; }}
72
+ .generation-proxy { display:none !important; }
73
+ #generation-toggle { border:0 !important; padding:0 !important; background:transparent !important; flex:3 !important; min-width:0 !important; }
74
+ #reset-model { flex:1 !important; min-width:80px !important; }
75
+ .generation-toggle-button { width:100%; min-height:44px; padding:10px 18px; border:0; border-radius:10px; background:#20c7b6; color:#fff; font:600 16px/1.4 system-ui,sans-serif; cursor:pointer; box-shadow:0 2px 8px #173c381a; }
76
+ .generation-toggle-button:hover { background:#16b5a5; }
77
+ .generation-toggle-button:disabled { opacity:.65; cursor:wait; }
78
+ .generation-toggle-button:focus-visible { outline:3px solid #547bba; outline-offset:2px; }
token_space.js CHANGED
@@ -8,6 +8,27 @@
8
  let lastText='';
9
  let paused=false, previousMode='live';
10
  let textView=null,externalSelected=null,reader=null,readerSignature='',lastHighlighted=null;
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
11
  function sourcePoint(){
12
  const pinned=history.find(p=>p.n===selected)||externalSelected;
13
  if(paused)return pinned;
@@ -149,6 +170,7 @@
149
  mount();const node=document.querySelector('[data-flow-frame]');if(!node)return;
150
  const raw=node.getAttribute('data-flow-frame');if(raw===payload)return;
151
  payload=raw;let data;try{data=JSON.parse(raw);}catch{return;}
 
152
  if(data.stream!==stream){stream=data.stream;seen=-1;history=[];selected=null;paused=false;textView=null;externalSelected=null;details();}
153
  const now=Date.now(),existing=new Set(history.map(p=>p.n));
154
  for(const p of data.points||[]){
@@ -177,6 +199,7 @@
177
  }
178
  function tick(){
179
  if(disposed)return;
 
180
  // Remount if Gradio replaced the canvas. Aging uses wall time, never server steps.
181
  mount();const now=Date.now(),dt=Math.min(now-lastTime,100);lastTime=now;
182
  if(!ctx||!width||!height)return;
@@ -260,5 +283,5 @@
260
  observer=new MutationObserver(receive);
261
  observer.observe(document.body,{subtree:true,childList:true,attributes:true,attributeFilter:['data-flow-frame']});
262
  receive();tick();timer=setInterval(tick,33);
263
- window.__letItFlowSpace=()=>{disposed=true;observer.disconnect();if(resize)resize.disconnect();clearInterval(timer);};
264
  }
 
8
  let lastText='';
9
  let paused=false, previousMode='live';
10
  let textView=null,externalSelected=null,reader=null,readerSignature='',lastHighlighted=null;
11
+ let running=false,ended=false,togglePending=false,toggleButton=null;
12
+ function generationClick(){
13
+ if(togglePending||(running&&paused))return;
14
+ const pausing=running&&!paused;
15
+ const host=document.querySelector(pausing?'#generation-pause':ended?'#generation-new':'#generation-run');
16
+ const proxy=host?.querySelector?.('button')||host;
17
+ if(typeof proxy?.click!=='function')return;
18
+ togglePending=true;toggleButton.textContent=pausing?'Pausing...':'Starting...';toggleButton.disabled=true;
19
+ proxy.click();
20
+ }
21
+ function mountGenerationControl(){
22
+ const button=document.querySelector('[data-generation-toggle]');
23
+ if(!button||typeof button.addEventListener!=='function')return;
24
+ if(button!==toggleButton){
25
+ toggleButton?.removeEventListener?.('click',generationClick);toggleButton=button;
26
+ toggleButton.addEventListener('click',generationClick);
27
+ }
28
+ const label=togglePending?toggleButton.textContent:running?(paused?'Pausing...':'Pause'):paused?'Resume':seen>=0&&!ended?'Resume':'Start';
29
+ if(toggleButton.textContent!==label)toggleButton.textContent=label;
30
+ toggleButton.disabled=togglePending||(running&&paused);
31
+ }
32
  function sourcePoint(){
33
  const pinned=history.find(p=>p.n===selected)||externalSelected;
34
  if(paused)return pinned;
 
170
  mount();const node=document.querySelector('[data-flow-frame]');if(!node)return;
171
  const raw=node.getAttribute('data-flow-frame');if(raw===payload)return;
172
  payload=raw;let data;try{data=JSON.parse(raw);}catch{return;}
173
+ running=Boolean(data.running);ended=Boolean(data.ended);togglePending=false;
174
  if(data.stream!==stream){stream=data.stream;seen=-1;history=[];selected=null;paused=false;textView=null;externalSelected=null;details();}
175
  const now=Date.now(),existing=new Set(history.map(p=>p.n));
176
  for(const p of data.points||[]){
 
199
  }
200
  function tick(){
201
  if(disposed)return;
202
+ mountGenerationControl();
203
  // Remount if Gradio replaced the canvas. Aging uses wall time, never server steps.
204
  mount();const now=Date.now(),dt=Math.min(now-lastTime,100);lastTime=now;
205
  if(!ctx||!width||!height)return;
 
283
  observer=new MutationObserver(receive);
284
  observer.observe(document.body,{subtree:true,childList:true,attributes:true,attributeFilter:['data-flow-frame']});
285
  receive();tick();timer=setInterval(tick,33);
286
+ window.__letItFlowSpace=()=>{disposed=true;observer.disconnect();if(resize)resize.disconnect();clearInterval(timer);toggleButton?.removeEventListener?.('click',generationClick);};
287
  }
token_space.py CHANGED
@@ -76,6 +76,7 @@ def frame(flow, store, full=False):
76
 
77
 
78
  def _frame(flow, store, full=False):
 
79
  tokens = flow.tokens.copy()
80
  points = []
81
  if store.projection is not None and flow.model_key == store.key:
@@ -100,7 +101,8 @@ def _frame(flow, store, full=False):
100
  store.tokenizer.decode([link["id"]], skip_special_tokens=False,
101
  clean_up_tokenization_spaces=False))
102
  points = flow.space_history[-512 if full else -48:]
103
- data = {"stream": flow.stream_id, "paused": flow.paused, "points": points}
 
104
  if flow.paused and store.projection is not None and flow.model_key == store.key:
105
  if flow.text_snapshot_cache is None or flow.text_snapshot_cache[0] != len(tokens):
106
  flow.text_snapshot_cache = (len(tokens), text_snapshot(tokens, store.tokenizer, store.projection))
 
76
 
77
 
78
  def _frame(flow, store, full=False):
79
+ flow.view_revision += 1
80
  tokens = flow.tokens.copy()
81
  points = []
82
  if store.projection is not None and flow.model_key == store.key:
 
101
  store.tokenizer.decode([link["id"]], skip_special_tokens=False,
102
  clean_up_tokenization_spaces=False))
103
  points = flow.space_history[-512 if full else -48:]
104
+ data = {"stream": flow.stream_id, "revision": flow.view_revision, "paused": flow.paused, "running": flow.running,
105
+ "ended": flow.ended, "points": points}
106
  if flow.paused and store.projection is not None and flow.model_key == store.key:
107
  if flow.text_snapshot_cache is None or flow.text_snapshot_cache[0] != len(tokens):
108
  flow.text_snapshot_cache = (len(tokens), text_snapshot(tokens, store.tokenizer, store.projection))