PeterPinetree commited on
Commit
c9b807e
·
verified ·
1 Parent(s): b373af6

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +38 -21
app.py CHANGED
@@ -293,36 +293,53 @@ class HoverList(anywidget.AnyWidget):
293
  clicked_id = t.Int(allow_none=True).tag(sync=True)
294
 
295
 
 
296
  @solara.component
297
  def PredictionsList():
298
- token_probs = token_probs_rx.value or []
299
- selected_token_id = selected_token_id_rx.value
 
 
 
 
 
 
 
 
300
 
301
- with solara.Column():
302
- for tid, prob in token_probs[:10]:
303
- row_label = f"{id_to_token.get(tid, tid)} ({prob:.2f})"
304
- is_selected = tid == selected_token_id
 
305
 
 
306
  with solara.Div(
307
- style={
308
- "background": "#333" if is_selected else "transparent",
309
- "padding": "2px",
310
- "borderRadius": "4px",
311
- },
312
- on_mouse_enter=lambda tid=tid: preview_token(tid),
313
- on_mouse_leave=lambda tid=tid: preview_token(None),
 
 
 
314
  ):
 
315
  solara.Button(
316
  row_label,
 
 
 
317
  on_click=lambda *args, tid=tid: append_token(tid),
318
- style={
319
- "justifyContent": "flex-start",
320
- "width": "100%",
321
- "textAlign": "left",
322
- "color": "#38bdf8" if is_selected else "white",
323
- },
324
- on_mouse_enter=lambda tid=tid: preview_token(tid),
325
- on_mouse_leave=lambda tid=tid: preview_token(None),
326
  )
327
 
328
  # ---------- Page ----------
 
293
  clicked_id = t.Int(allow_none=True).tag(sync=True)
294
 
295
 
296
+ # ---------- Predictions list ----------
297
  @solara.component
298
  def PredictionsList():
299
+ df = preds_rx.value # your DataFrame with columns: probs, id, tok
300
+ with solara.Column(gap="6px", style={"maxWidth": "720px"}):
301
+ solara.Markdown("### Prediction")
302
+ solara.Text(
303
+ " # probs token predicted next token",
304
+ style={
305
+ "color": "var(--muted)",
306
+ "fontFamily": 'ui-monospace, SFMono-Regular, Menlo, Monaco, Consolas, "Liberation Mono", "Courier New", monospace',
307
+ },
308
+ )
309
 
310
+ for i, row in df.iterrows():
311
+ tid = int(row["id"])
312
+ prob = row["probs"] # already formatted like "3.21%"
313
+ tok_disp = display_token_from_id(tid)
314
+ row_label = fmt_row(i, prob, tid, tok_disp)
315
 
316
+ # Wrapper DIV handles hover reliably
317
  with solara.Div(
318
+ classes=["rowbtn"], # styling on wrapper
319
+ style={"justifyContent": "flex-start", "width": "100%"},
320
+ attributes={"tabindex": "0", "role": "button"},
321
+ # --- HOVER = preview neighborhood ---
322
+ on_mouse_enter=lambda *args, tid=tid: preview_token(tid),
323
+ on_mouse_over=lambda *args, tid=tid: preview_token(tid),
324
+ on_mouse_move=lambda *args, tid=tid: preview_token(tid),
325
+ on_pointer_enter=lambda *args, tid=tid: preview_token(tid),
326
+ on_pointer_move=lambda *args, tid=tid: preview_token(tid),
327
+ on_focus=lambda *args, tid=tid: preview_token(tid), # keyboard
328
  ):
329
+ # Inner BUTTON handles click-to-append (and also binds hover for extra safety)
330
  solara.Button(
331
  row_label,
332
+ classes=[], # keep wrapper styled; button unstyled
333
+ style={"justifyContent": "flex-start", "width": "100%"},
334
+ # --- CLICK = append token to text ---
335
  on_click=lambda *args, tid=tid: append_token(tid),
336
+ # redundant hover hooks (helps on some builds)
337
+ on_mouse_enter=lambda *args, tid=tid: preview_token(tid),
338
+ on_mouse_over=lambda *args, tid=tid: preview_token(tid),
339
+ on_mouse_move=lambda *args, tid=tid: preview_token(tid),
340
+ on_pointer_enter=lambda *args, tid=tid: preview_token(tid),
341
+ on_pointer_move=lambda *args, tid=tid: preview_token(tid),
342
+ on_focus=lambda *args, tid=tid: preview_token(tid),
 
343
  )
344
 
345
  # ---------- Page ----------