kcarnold commited on
Commit
a2477f5
·
1 Parent(s): 212669f

display tweaks: only show on hover

Browse files
Files changed (1) hide show
  1. app.py +12 -8
app.py CHANGED
@@ -148,8 +148,8 @@ def highlights_component(spans, show_alternatives, min_loss):
148
  show = span['token'] != span['most_likely_token'] and span['loss_ratio'] >= min_loss
149
  show_alternative = show and show_alternatives
150
  hover = f'<span class="alternative">{span["most_likely_token"]}</span>'
151
- html_out += '<span style="position: relative; color: {color}" title="{title}">{hover}{orig_token}</span>'.format(
152
- color="green" if show else "black",
153
  title=html.escape(span["most_likely_token"]).replace('\n', ' ') if show_alternative else '',
154
  orig_token=html.escape(span["token"]).replace('\n', '<br>'),
155
  hover=hover if show_alternative else ''
@@ -160,16 +160,20 @@ def highlights_component(spans, show_alternatives, min_loss):
160
  background: white;
161
  line-height: 2.5;
162
  }}
 
 
 
163
  p.highlights-container .alternative {{
 
 
 
 
164
  position: absolute;
165
- top: -10px;
166
  left: 5px;
167
- font-size: 10px;
168
- min-width:6em;
169
  line-height: 1;
170
- color: grey;
171
- transform-origin:
172
- left; transform: rotate(-15deg);
173
  }}
174
  </style>
175
  <p class="highlights-container">{html_out}</p>
 
148
  show = span['token'] != span['most_likely_token'] and span['loss_ratio'] >= min_loss
149
  show_alternative = show and show_alternatives
150
  hover = f'<span class="alternative">{span["most_likely_token"]}</span>'
151
+ html_out += '<span style="color: {color}" title="{title}">{hover}{orig_token}</span>'.format(
152
+ color="grey" if show else "black",
153
  title=html.escape(span["most_likely_token"]).replace('\n', ' ') if show_alternative else '',
154
  orig_token=html.escape(span["token"]).replace('\n', '<br>'),
155
  hover=hover if show_alternative else ''
 
160
  background: white;
161
  line-height: 2.5;
162
  }}
163
+ p.highlights-container > span {{
164
+ position: relative;
165
+ }}
166
  p.highlights-container .alternative {{
167
+ display: none;
168
+ }}
169
+ p.highlights-container > span:hover .alternative {{
170
+ display: inline;
171
  position: absolute;
172
+ top: -12px;
173
  left: 5px;
174
+ min-width: 6em;
 
175
  line-height: 1;
176
+ color: green;
 
 
177
  }}
178
  </style>
179
  <p class="highlights-container">{html_out}</p>