Skip to content

Commit a33fae2

Browse files
committed
Fix treescope html saving
1 parent 9de007e commit a33fae2

File tree

2 files changed

+9
-7
lines changed

2 files changed

+9
-7
lines changed

inseq/commands/attribute_context/attribute_context_viz_helpers.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -326,6 +326,7 @@ def visualize_attribute_context_treescope(
326326
rounding=10,
327327
colormap=cmap_cci,
328328
strip_chars=replace_chars,
329+
show_empty_tokens=False,
329330
)
330331
)
331332
cci_parts.append(rp.text("\n\n"))
@@ -341,6 +342,7 @@ def visualize_attribute_context_treescope(
341342
rounding=10,
342343
colormap=cmap_cci,
343344
strip_chars=replace_chars,
345+
show_empty_tokens=False,
344346
)
345347
)
346348
cci_parts.append(rp.text("\n\n"))

inseq/data/viz.py

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -234,7 +234,7 @@ def show_granular_attributions(
234234
if display:
235235
ts.show(fig)
236236
if return_html:
237-
return ts.render_to_html(fig)
237+
return ts.lowering.render_to_html_as_root(fg.treescope_part_from_display_object(fig))
238238

239239

240240
def show_token_attributions(
@@ -372,7 +372,7 @@ def show_token_attributions(
372372
if display:
373373
ts.show(fig)
374374
if return_html:
375-
return ts.render_to_html(fig)
375+
return ts.lowering.render_to_html_as_root(fg.treescope_part_from_display_object(fig))
376376

377377

378378
def get_attribution_colors(
@@ -621,12 +621,12 @@ def get_single_token_heatmap_treescope(
621621
parts.append(rp.text(repl))
622622
if (show_empty_tokens and token != "") or curr_tok != "":
623623
show_token = token if show_empty_tokens and curr_tok == "" else curr_tok
624-
highlighted_text = fg.treescope_part_from_display_object(
625-
fg.text_on_color(show_token, value=round(score, rounding), vmin=min_val, vmax=max_val, colormap=colormap)
626-
)
627-
parts[idx_highlight] = highlighted_text
628624
else:
629-
parts.pop(idx_highlight)
625+
show_token = " "
626+
highlighted_text = fg.treescope_part_from_display_object(
627+
fg.text_on_color(show_token, value=round(score, rounding), vmin=min_val, vmax=max_val, colormap=colormap)
628+
)
629+
parts[idx_highlight] = highlighted_text
630630
if return_highlighted_idx:
631631
return parts, idx_highlight, show_token
632632
return parts

0 commit comments

Comments
 (0)