PeterPinetree commited on
Commit
0e43a26
·
verified ·
1 Parent(s): d79b10f

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +11 -11
app.py CHANGED
@@ -1,5 +1,4 @@
1
  # app.py
2
- # app.py
3
  import json
4
  from pathlib import Path
5
  import threading, time
@@ -34,11 +33,11 @@ hr{ border-color:var(--border); }
34
  width:100%; padding:10px 12px; border-radius:12px;
35
  border:1px solid var(--border); background:#fff; color:var(--text);
36
  display:flex; justify-content:flex-start; align-items:center;
37
- text-align:left;
38
  font-family: ui-monospace, SFMono-Regular, Menlo, Monaco, Consolas, "Liberation Mono", "Courier New", monospace;
39
  letter-spacing:.2px;
40
  }
41
- .rowbtn:hover{ background:#f7fbff; border-color:#c3e8fb; cursor:pointer; }
42
  """
43
 
44
  # ------------------ App state ------------------
@@ -71,7 +70,7 @@ def display_token_from_id(tid: int) -> str:
71
  """Readable label for a single token id (no leading tokenizer markers)."""
72
  toks = tokenizer.convert_ids_to_tokens([int(tid)], skip_special_tokens=True)
73
  t = toks[0] if toks else ""
74
- for lead in ("▁", "Ġ"): # common leading markers
75
  if t.startswith(lead):
76
  t = t[len(lead):]
77
  t = t.replace("\n", "↵")
@@ -214,7 +213,7 @@ def AutoPredictWatcher():
214
  solara.use_effect(effect, [text, auto])
215
  return solara.Text("", style={"display": "none"})
216
 
217
- # ------------------ UI: custom clickable/hoverable list ------------------
218
  @solara.component
219
  def PredictionsList():
220
  df = preds_rx.value
@@ -233,15 +232,16 @@ def PredictionsList():
233
  tok_disp = display_token_from_id(tid)
234
  label = fmt_row(i, prob, tid, tok_disp)
235
 
236
- # Use Div instead of Button so hover works everywhere
237
  with solara.Div(
238
  classes=["rowbtn"],
239
  style={"justifyContent": "flex-start"},
240
- on_click=lambda tid=tid: append_token(tid),
241
- on_mouse_enter=lambda tid=tid: preview_token(tid),
242
- on_mouse_over=lambda tid=tid: preview_token(tid),
243
- on_focus=lambda tid=tid: preview_token(tid),
244
- attributes={"tabindex": "0"}, # keyboard focusable
 
245
  ):
246
  solara.Text(label)
247
 
 
1
  # app.py
 
2
  import json
3
  from pathlib import Path
4
  import threading, time
 
33
  width:100%; padding:10px 12px; border-radius:12px;
34
  border:1px solid var(--border); background:#fff; color:var(--text);
35
  display:flex; justify-content:flex-start; align-items:center;
36
+ text-align:left; cursor:pointer;
37
  font-family: ui-monospace, SFMono-Regular, Menlo, Monaco, Consolas, "Liberation Mono", "Courier New", monospace;
38
  letter-spacing:.2px;
39
  }
40
+ .rowbtn:hover{ background:#f7fbff; border-color:#c3e8fb; }
41
  """
42
 
43
  # ------------------ App state ------------------
 
70
  """Readable label for a single token id (no leading tokenizer markers)."""
71
  toks = tokenizer.convert_ids_to_tokens([int(tid)], skip_special_tokens=True)
72
  t = toks[0] if toks else ""
73
+ for lead in ("▁", "Ġ"):
74
  if t.startswith(lead):
75
  t = t[len(lead):]
76
  t = t.replace("\n", "↵")
 
213
  solara.use_effect(effect, [text, auto])
214
  return solara.Text("", style={"display": "none"})
215
 
216
+ # ------------------ UI: clickable + hoverable list ------------------
217
  @solara.component
218
  def PredictionsList():
219
  df = preds_rx.value
 
232
  tok_disp = display_token_from_id(tid)
233
  label = fmt_row(i, prob, tid, tok_disp)
234
 
235
+ # Use Div so hover works across Solara versions; note (event, ...) signatures
236
  with solara.Div(
237
  classes=["rowbtn"],
238
  style={"justifyContent": "flex-start"},
239
+ attributes={"tabindex": "0", "role": "button"},
240
+ on_click=lambda e=None, tid=tid: append_token(tid),
241
+ on_mouse_enter=lambda e=None, tid=tid: preview_token(tid),
242
+ on_mouse_over=lambda e=None, tid=tid: preview_token(tid),
243
+ on_mouse_move=lambda e=None, tid=tid: preview_token(tid),
244
+ on_focus=lambda e=None, tid=tid: preview_token(tid),
245
  ):
246
  solara.Text(label)
247