m-ric HF staff commited on
Commit
dccdd11
β€’
1 Parent(s): 179959e

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +16 -8
app.py CHANGED
@@ -150,13 +150,16 @@ STYLE = """
150
  }
151
  /*Hover-Section*/
152
  .tree li a:hover, .tree li a:hover+ul li a {
153
- background: var(--primary-600);
154
  }
155
  .tree li a:hover+ul li::after, .tree li a:hover+ul li::before, .tree li a:hover+ul::before, .tree li a:hover+ul ul::before, .tree li a:hover+ul a::before {
156
- border-color: var(--primary-400);
157
  }
158
- .end-of-text, .chosen-token {
159
- background-color: var(--primary-500);
 
 
 
160
  }
161
  .end-of-text {
162
  width:auto!important;
@@ -168,6 +171,9 @@ STYLE = """
168
  .selected-sequence {
169
  background-color: var(--secondary-500)!important;
170
  }
 
 
 
171
  """
172
 
173
 
@@ -205,12 +211,14 @@ def generate_nodes(node, step):
205
  """Recursively generate HTML for the tree nodes."""
206
  token = tokenizer.decode([node.current_token_ix])
207
 
208
- selected_class = "selected-sequence" if node.is_selected_sequence else ""
209
-
210
  if node.is_final:
 
 
 
 
211
  return f"<li> <a href='#' class='end-of-text child {selected_class}'> <span> <b>{clean(token)}</b> <br>Total score: {node.total_score:.2f}</span> </a> </li>"
212
 
213
- html_content = f"<li> <a href='#' class='nonfinal child {selected_class}'> <span> <b>{clean(token)}</b> </span>"
214
  if node.table is not None:
215
  html_content += node.table
216
  html_content += "</a>"
@@ -401,7 +409,7 @@ def get_beam_search_html(input_text, number_steps, number_beams, length_penalty)
401
  markdown += "\n\nThey are ranked by their scores, as given by the formula `score = cumulative_score / (output_length ** length_penalty)`.\n\n"
402
  markdown += "Only the top `num_beams` scoring sequences are returned: in the tree they are highlighted in **<span style='color:var(--secondary-500)!important'>blue</span>**."
403
  markdown += " The non-selected sequences are also shown in the tree, highlighted in **<span style='color:var(--primary-500)!important'>yellow</span>**."
404
- markdown += "\n#### <span style='color:var(--secondary-600)!important'>Output sequences:</span>"
405
  # Sequences are padded anyway so you can batch decode them
406
  decoded_sequences = tokenizer.batch_decode(outputs.sequences)
407
  for i, sequence in enumerate(decoded_sequences):
 
150
  }
151
  /*Hover-Section*/
152
  .tree li a:hover, .tree li a:hover+ul li a {
153
+ background: var(--primary-500);
154
  }
155
  .tree li a:hover+ul li::after, .tree li a:hover+ul li::before, .tree li a:hover+ul::before, .tree li a:hover+ul ul::before, .tree li a:hover+ul a::before {
156
+ border-color: var(--primary-300);
157
  }
158
+ .chosen-token {
159
+ background-color: var(--primary-400);
160
+ }
161
+ .chosen-token td, .chosen-token tr {
162
+ color: black!important;
163
  }
164
  .end-of-text {
165
  width:auto!important;
 
171
  .selected-sequence {
172
  background-color: var(--secondary-500)!important;
173
  }
174
+ .nonselected-sequence {
175
+ background-color: var(--primary-500)!important;
176
+ }
177
  """
178
 
179
 
 
211
  """Recursively generate HTML for the tree nodes."""
212
  token = tokenizer.decode([node.current_token_ix])
213
 
 
 
214
  if node.is_final:
215
+ if node.is_selected_sequence:
216
+ selected_class = "selected-sequence"
217
+ else:
218
+ selected_class = "nonselected-sequence"
219
  return f"<li> <a href='#' class='end-of-text child {selected_class}'> <span> <b>{clean(token)}</b> <br>Total score: {node.total_score:.2f}</span> </a> </li>"
220
 
221
+ html_content = f"<li> <a href='#' class='nonfinal child'> <span> <b>{clean(token)}</b> </span>"
222
  if node.table is not None:
223
  html_content += node.table
224
  html_content += "</a>"
 
409
  markdown += "\n\nThey are ranked by their scores, as given by the formula `score = cumulative_score / (output_length ** length_penalty)`.\n\n"
410
  markdown += "Only the top `num_beams` scoring sequences are returned: in the tree they are highlighted in **<span style='color:var(--secondary-500)!important'>blue</span>**."
411
  markdown += " The non-selected sequences are also shown in the tree, highlighted in **<span style='color:var(--primary-500)!important'>yellow</span>**."
412
+ markdown += "\n#### <span style='color:var(--secondary-500)!important'>Output sequences:</span>"
413
  # Sequences are padded anyway so you can batch decode them
414
  decoded_sequences = tokenizer.batch_decode(outputs.sequences)
415
  for i, sequence in enumerate(decoded_sequences):