PeterPinetree commited on
Commit
65a9c4c
·
verified ·
1 Parent(s): 9a4a2b9

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +16 -6
app.py CHANGED
@@ -29,6 +29,13 @@ h1,h2,h3{ color:var(--text); }
29
  hr{ border-color:var(--border); }
30
  .badge{ display:inline-block; padding:2px 8px; border:1px solid var(--border); border-radius:999px; margin:2px; }
31
 
 
 
 
 
 
 
 
32
  .rowbtn{
33
  width:100%; padding:10px 12px; border-radius:12px;
34
  border:1px solid var(--border); background:#fff; color:var(--text);
@@ -177,6 +184,7 @@ def highlight(token_id: int):
177
  return fig
178
 
179
  def preview_token(token_id: int):
 
180
  token_id = int(token_id)
181
  # TEMP DEBUG: verify hover fires in Space logs
182
  print("preview ->", token_id)
@@ -188,6 +196,7 @@ def preview_token(token_id: int):
188
 
189
  def append_token(token_id: int):
190
  # keep decode() here so spacing stays correct in the prompt
 
191
  decoded = tokenizer.decode([int(token_id)])
192
  text_rx.set(text_rx.value + decoded)
193
  preview_token(int(token_id)) # keep highlight on clicked token
@@ -244,15 +253,16 @@ def PredictionsList():
244
  classes=["rowbtn"],
245
  style={"justifyContent": "flex-start", "width": "100%"},
246
  attributes={"tabindex": "0", "role": "button"},
247
- on_click=lambda e=None, tid=tid: append_token(tid), # click to append
248
- on_mouse_enter=lambda e=None, tid=tid: preview_token(tid), # hover preview
249
  on_mouse_over=lambda e=None, tid=tid: preview_token(tid),
250
  on_mouse_move=lambda e=None, tid=tid: preview_token(tid),
251
- on_pointer_enter=lambda e=None, tid=tid: preview_token(tid), # pointer events (more reliable)
252
- on_focus=lambda e=None, tid=tid: preview_token(tid), # keyboard
253
  ):
254
  solara.Text(label)
255
 
 
256
  # ------------------ Page ------------------
257
  @solara.component
258
  def Page():
@@ -272,10 +282,10 @@ def Page():
272
 
273
  # Two columns
274
  with solara.Row(gap="24px", style={"align-items": "flex-start"}):
275
- with solara.Column():
276
  PredictionsList()
277
 
278
- with solara.Column():
279
  solara.Markdown("### Semantic Neighborhood")
280
  if not coords:
281
  solara.Markdown("> Embedding map unavailable – add `assets/embeddings/*.json`.")
 
29
  hr{ border-color:var(--border); }
30
  .badge{ display:inline-block; padding:2px 8px; border:1px solid var(--border); border-radius:999px; margin:2px; }
31
 
32
+ /* Keep the predictions list above the plot so it can receive pointer events */
33
+ .predictions-panel { position: relative; z-index: 5; }
34
+ .plot-panel { position: relative; z-index: 1; }
35
+
36
+ /* Safety: prevent any wide Plotly overlay from swallowing events on the left */
37
+ .plot-panel .js-plotly-plot { position: relative; z-index: 1; }
38
+
39
  .rowbtn{
40
  width:100%; padding:10px 12px; border-radius:12px;
41
  border:1px solid var(--border); background:#fff; color:var(--text);
 
184
  return fig
185
 
186
  def preview_token(token_id: int):
187
+ print("preview ->", token_id) # TEMP: check Logs
188
  token_id = int(token_id)
189
  # TEMP DEBUG: verify hover fires in Space logs
190
  print("preview ->", token_id)
 
196
 
197
  def append_token(token_id: int):
198
  # keep decode() here so spacing stays correct in the prompt
199
+ print("append ->", token_id) # TEMP: check Logs
200
  decoded = tokenizer.decode([int(token_id)])
201
  text_rx.set(text_rx.value + decoded)
202
  preview_token(int(token_id)) # keep highlight on clicked token
 
253
  classes=["rowbtn"],
254
  style={"justifyContent": "flex-start", "width": "100%"},
255
  attributes={"tabindex": "0", "role": "button"},
256
+ on_click=lambda e=None, tid=tid: append_token(tid), # click to append
257
+ on_mouse_enter=lambda e=None, tid=tid: preview_token(tid), # hover preview
258
  on_mouse_over=lambda e=None, tid=tid: preview_token(tid),
259
  on_mouse_move=lambda e=None, tid=tid: preview_token(tid),
260
+ on_pointer_enter=lambda e=None, tid=tid: preview_token(tid),
261
+ on_focus=lambda e=None, tid=tid: preview_token(tid),
262
  ):
263
  solara.Text(label)
264
 
265
+
266
  # ------------------ Page ------------------
267
  @solara.component
268
  def Page():
 
282
 
283
  # Two columns
284
  with solara.Row(gap="24px", style={"align-items": "flex-start"}):
285
+ with solara.Column(classes=["predictions-panel"]):
286
  PredictionsList()
287
 
288
+ with solara.Column(classes=["plot-panel"]):
289
  solara.Markdown("### Semantic Neighborhood")
290
  if not coords:
291
  solara.Markdown("> Embedding map unavailable – add `assets/embeddings/*.json`.")