kcarnold commited on
Commit
01c0ffa
1 Parent(s): fdf3450

Allow disabling the alternative suggestions.

Browse files
Files changed (1) hide show
  1. app.py +11 -4
app.py CHANGED
@@ -125,22 +125,29 @@ def highlight_edits():
125
  st.write("No possible edits found.")
126
  st.stop()
127
 
128
- num_to_show = st.slider("Number of edits to show", 1, num_different, value=num_different // 2)
 
 
 
 
129
  min_loss = loss_ratios_for_different[num_to_show - 1]
130
 
131
  html_out = ''
132
  for span in spans:
133
  show = span['token'] != span['most_likely_token'] and span['loss_ratio'] >= min_loss
 
134
  hover = f'<span style="position: absolute; top: -10px; left: 5px; font-size: 10px; min-width:6em; line-height: 1; color: grey; transform-origin: left; transform: rotate(-15deg)">{span["most_likely_token"]}</span>'
135
  html_out += '<span style="position: relative; color: {color}" title="{title}">{hover}{orig_token}</span>'.format(
136
  color="green" if show else "black",
137
- title=html.escape(span["most_likely_token"]).replace('\n', ' ') if show else '',
138
  orig_token=html.escape(span["token"]).replace('\n', '<br>'),
139
- hover=hover if show else ''
140
  )
141
  html_out = f"<p style=\"background: white; line-height: 2.5;\">{html_out}</p>"
142
 
143
- st.write(html_out, unsafe_allow_html=True)
 
 
144
  if st.checkbox("Show details"):
145
  import pandas as pd
146
  st.write(pd.DataFrame(spans)[['token', 'token_loss', 'most_likely_token', 'loss_ratio']])
 
125
  st.write("No possible edits found.")
126
  st.stop()
127
 
128
+ output_container = st.container(border=True)
129
+
130
+ with st.expander("Controls"):
131
+ num_to_show = st.slider("Number of edits to show", 1, num_different, value=num_different // 2)
132
+ show_alternatives = st.checkbox("Show alternatives", value=True)
133
  min_loss = loss_ratios_for_different[num_to_show - 1]
134
 
135
  html_out = ''
136
  for span in spans:
137
  show = span['token'] != span['most_likely_token'] and span['loss_ratio'] >= min_loss
138
+ show_alternative = show and show_alternatives
139
  hover = f'<span style="position: absolute; top: -10px; left: 5px; font-size: 10px; min-width:6em; line-height: 1; color: grey; transform-origin: left; transform: rotate(-15deg)">{span["most_likely_token"]}</span>'
140
  html_out += '<span style="position: relative; color: {color}" title="{title}">{hover}{orig_token}</span>'.format(
141
  color="green" if show else "black",
142
+ title=html.escape(span["most_likely_token"]).replace('\n', ' ') if show_alternative else '',
143
  orig_token=html.escape(span["token"]).replace('\n', '<br>'),
144
+ hover=hover if show_alternative else ''
145
  )
146
  html_out = f"<p style=\"background: white; line-height: 2.5;\">{html_out}</p>"
147
 
148
+ with output_container:
149
+ st.write(html_out, unsafe_allow_html=True)
150
+
151
  if st.checkbox("Show details"):
152
  import pandas as pd
153
  st.write(pd.DataFrame(spans)[['token', 'token_loss', 'most_likely_token', 'loss_ratio']])