Spaces:
Runtime error
Runtime error
Commit
·
32fbbc2
1
Parent(s):
b83ecd0
Add total count to output
Browse files- tapas_visualizer.py +13 -7
tapas_visualizer.py
CHANGED
@@ -126,10 +126,10 @@ class TapasVisualizer:
|
|
126 |
cnt_html = (
|
127 |
f'<td style="border: none;" align="right">'
|
128 |
f'{self.style_span(str(cumulative_cnt), ["non-token", "count"])}'
|
129 |
-
|
130 |
f'<td style="border: none;" align="right">'
|
131 |
f'{self.style_span(f"<+{row_token_cnt}", ["non-token", "count"])}'
|
132 |
-
|
133 |
)
|
134 |
row_html = cnt_html + row_html
|
135 |
table_html += f"<tr>{row_html}</tr>"
|
@@ -150,17 +150,13 @@ class TapasVisualizer:
|
|
150 |
if int(segment_id) == 1:
|
151 |
cell_tokens[(row_id, col_id)].append(token_text)
|
152 |
|
153 |
-
table_html = (
|
154 |
-
'<tr><td style="border: none;" colspan="2" align="left">#Tokens</td></tr>'
|
155 |
-
)
|
156 |
-
|
157 |
table_html, cumulative_cnt = self.cells_to_html(
|
158 |
cell_vals=[table.columns],
|
159 |
cell_tokens=cell_tokens,
|
160 |
row_id_start=0,
|
161 |
cell_element="th",
|
162 |
cumulative_cnt=0,
|
163 |
-
table_html=
|
164 |
)
|
165 |
|
166 |
table_html, cumulative_cnt = self.cells_to_html(
|
@@ -171,6 +167,16 @@ class TapasVisualizer:
|
|
171 |
cumulative_cnt=cumulative_cnt,
|
172 |
table_html=table_html,
|
173 |
)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
174 |
|
175 |
table_html = f"<table>{table_html}</table>"
|
176 |
return HTMLBody(table_html)
|
|
|
126 |
cnt_html = (
|
127 |
f'<td style="border: none;" align="right">'
|
128 |
f'{self.style_span(str(cumulative_cnt), ["non-token", "count"])}'
|
129 |
+
"</td>"
|
130 |
f'<td style="border: none;" align="right">'
|
131 |
f'{self.style_span(f"<+{row_token_cnt}", ["non-token", "count"])}'
|
132 |
+
"</td>"
|
133 |
)
|
134 |
row_html = cnt_html + row_html
|
135 |
table_html += f"<tr>{row_html}</tr>"
|
|
|
150 |
if int(segment_id) == 1:
|
151 |
cell_tokens[(row_id, col_id)].append(token_text)
|
152 |
|
|
|
|
|
|
|
|
|
153 |
table_html, cumulative_cnt = self.cells_to_html(
|
154 |
cell_vals=[table.columns],
|
155 |
cell_tokens=cell_tokens,
|
156 |
row_id_start=0,
|
157 |
cell_element="th",
|
158 |
cumulative_cnt=0,
|
159 |
+
table_html="",
|
160 |
)
|
161 |
|
162 |
table_html, cumulative_cnt = self.cells_to_html(
|
|
|
167 |
cumulative_cnt=cumulative_cnt,
|
168 |
table_html=table_html,
|
169 |
)
|
170 |
+
top_label = self.style_span("#Tokens", ["count"])
|
171 |
+
top_label_cnt = self.style_span(f"(Total: {cumulative_cnt})", ["count"])
|
172 |
+
|
173 |
+
table_html = (
|
174 |
+
'<tr style="line-height: 2rem">'
|
175 |
+
f'<td style="border: none;" colspan="2" align="left">{top_label}</td>'
|
176 |
+
f'<td style="border: none;" colspan="1" align="left">{top_label_cnt}</td>'
|
177 |
+
"</tr>"
|
178 |
+
f"{table_html}"
|
179 |
+
)
|
180 |
|
181 |
table_html = f"<table>{table_html}</table>"
|
182 |
return HTMLBody(table_html)
|