PeterPinetree commited on
Commit
7dc7f88
·
verified ·
1 Parent(s): 08c4a63

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +14 -18
app.py CHANGED
@@ -192,7 +192,7 @@ def append_token(token_id: int):
192
  text_rx.set(text_rx.value + decoded)
193
  # lock highlight to the clicked token and keep it after re-predict
194
  preview_token(int(token_id))
195
- on_predict() # refresh next tokens but do NOT override highlight anymore
196
 
197
  # ------------------ Auto-predict on typing (debounced) ------------------
198
  @solara.component
@@ -221,7 +221,7 @@ def AutoPredictWatcher():
221
  solara.use_effect(effect, [text, auto])
222
  return solara.Text("", style={"display": "none"})
223
 
224
- # ------------------ UI: clickable + hoverable list ------------------
225
  @solara.component
226
  def PredictionsList():
227
  df = preds_rx.value
@@ -240,21 +240,17 @@ def PredictionsList():
240
  tok_disp = display_token_from_id(tid)
241
  label = fmt_row(i, prob, tid, tok_disp)
242
 
243
- # Wrap a Button (click) inside a Div (hover). Div events pass (event, ...),
244
- # Button click is reliable across Solara versions.
245
- with solara.Div(
246
- attributes={"tabindex": "0", "role": "button"},
247
- on_mouse_enter=lambda e=None, tid=tid: preview_token(tid),
248
- on_mouse_over=lambda e=None, tid=tid: preview_token(tid),
249
- on_mouse_move=lambda e=None, tid=tid: preview_token(tid),
250
- on_focus=lambda e=None, tid=tid: preview_token(tid),
251
- ):
252
- solara.Button(
253
- label,
254
- on_click=lambda tid=tid: append_token(tid),
255
- classes=["rowbtn"],
256
- style={"justifyContent": "flex-start", "width": "100%"},
257
- )
258
 
259
  # ------------------ Page ------------------
260
  @solara.component
@@ -298,4 +294,4 @@ def Page():
298
 
299
  # Seed initial predictions and mount
300
  on_predict()
301
- Page()
 
192
  text_rx.set(text_rx.value + decoded)
193
  # lock highlight to the clicked token and keep it after re-predict
194
  preview_token(int(token_id))
195
+ on_predict() # refresh next tokens but preserve highlight
196
 
197
  # ------------------ Auto-predict on typing (debounced) ------------------
198
  @solara.component
 
221
  solara.use_effect(effect, [text, auto])
222
  return solara.Text("", style={"display": "none"})
223
 
224
+ # ------------------ UI: clickable + HOVERABLE rows ------------------
225
  @solara.component
226
  def PredictionsList():
227
  df = preds_rx.value
 
240
  tok_disp = display_token_from_id(tid)
241
  label = fmt_row(i, prob, tid, tok_disp)
242
 
243
+ # Put ALL hover handlers directly on the Button.
244
+ solara.Button(
245
+ label,
246
+ on_click=lambda tid=tid: append_token(tid), # click to append
247
+ on_mouse_enter=lambda e=None, tid=tid: preview_token(tid), # hover preview
248
+ on_mouse_over=lambda e=None, tid=tid: preview_token(tid), # extra safety
249
+ on_mouse_move=lambda e=None, tid=tid: preview_token(tid), # tracks movement
250
+ on_focus=lambda e=None, tid=tid: preview_token(tid), # keyboard focus
251
+ classes=["rowbtn"],
252
+ style={"justifyContent": "flex-start", "width": "100%"},
253
+ )
 
 
 
 
254
 
255
  # ------------------ Page ------------------
256
  @solara.component
 
294
 
295
  # Seed initial predictions and mount
296
  on_predict()
297
+ Page()