Spaces:
Sleeping
Sleeping
Update app.py
Browse files
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 |
-
|
| 299 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 300 |
|
| 301 |
-
|
| 302 |
-
|
| 303 |
-
|
| 304 |
-
|
|
|
|
| 305 |
|
|
|
|
| 306 |
with solara.Div(
|
| 307 |
-
|
| 308 |
-
|
| 309 |
-
|
| 310 |
-
|
| 311 |
-
|
| 312 |
-
|
| 313 |
-
|
|
|
|
|
|
|
|
|
|
| 314 |
):
|
|
|
|
| 315 |
solara.Button(
|
| 316 |
row_label,
|
|
|
|
|
|
|
|
|
|
| 317 |
on_click=lambda *args, tid=tid: append_token(tid),
|
| 318 |
-
|
| 319 |
-
|
| 320 |
-
|
| 321 |
-
|
| 322 |
-
|
| 323 |
-
|
| 324 |
-
|
| 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 ----------
|