Spaces:
Running
Running
Refactor highlights display into a separate component
Browse files
app.py
CHANGED
@@ -96,7 +96,6 @@ def get_highlights(prompt, doc, updated_doc):
|
|
96 |
|
97 |
|
98 |
def highlight_edits():
|
99 |
-
import html
|
100 |
cols = st.columns([1, 4], vertical_alignment="center")
|
101 |
with cols[0]:
|
102 |
prompt = get_prompt(include_generation_options=False)
|
@@ -132,6 +131,18 @@ def highlight_edits():
|
|
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
|
@@ -144,14 +155,8 @@ def highlight_edits():
|
|
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 |
-
|
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']])
|
154 |
-
st.write("Token loss is the difference between the original token and the most likely token. The loss ratio is the token loss divided by the highest token loss in the document.")
|
155 |
|
156 |
def get_revised_docs(prompt, doc, n):
|
157 |
response = requests.get("https://tools.kenarnold.org/api/gen_revisions", params=dict(prompt=prompt, doc=doc, n=n))
|
|
|
96 |
|
97 |
|
98 |
def highlight_edits():
|
|
|
99 |
cols = st.columns([1, 4], vertical_alignment="center")
|
100 |
with cols[0]:
|
101 |
prompt = get_prompt(include_generation_options=False)
|
|
|
131 |
show_alternatives = st.checkbox("Show alternatives", value=True)
|
132 |
min_loss = loss_ratios_for_different[num_to_show - 1]
|
133 |
|
134 |
+
with output_container:
|
135 |
+
highlights_component(spans, show_alternatives, min_loss)
|
136 |
+
|
137 |
+
if st.checkbox("Show details"):
|
138 |
+
import pandas as pd
|
139 |
+
st.write(pd.DataFrame(spans)[['token', 'token_loss', 'most_likely_token', 'loss_ratio']])
|
140 |
+
st.write("Token loss is the difference between the original token and the most likely token. The loss ratio is the token loss divided by the highest token loss in the document.")
|
141 |
+
|
142 |
+
def highlights_component(spans, show_alternatives, min_loss):
|
143 |
+
import streamlit.components.v1 as components
|
144 |
+
import html
|
145 |
+
|
146 |
html_out = ''
|
147 |
for span in spans:
|
148 |
show = span['token'] != span['most_likely_token'] and span['loss_ratio'] >= min_loss
|
|
|
155 |
hover=hover if show_alternative else ''
|
156 |
)
|
157 |
html_out = f"<p style=\"background: white; line-height: 2.5;\">{html_out}</p>"
|
158 |
+
return st.html(html_out)
|
159 |
+
|
|
|
|
|
|
|
|
|
|
|
|
|
160 |
|
161 |
def get_revised_docs(prompt, doc, n):
|
162 |
response = requests.get("https://tools.kenarnold.org/api/gen_revisions", params=dict(prompt=prompt, doc=doc, n=n))
|