Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
@@ -79,22 +79,31 @@ for lang in langs:
|
|
79 |
st.markdown(f"<b>PE</b>: {'<bdi>' if lang == 'ara' else ''}{dic['tgt_text']}{'</bdi>' if lang == 'ara' else ''}", unsafe_allow_html=True)
|
80 |
st.markdown(f"<b>Aligned edits</b>:", unsafe_allow_html=True)
|
81 |
if dic["aligned_edit"] is not None:
|
82 |
-
|
|
|
|
|
|
|
|
|
83 |
else:
|
84 |
st.text("MT : N/A\nPE : N/A\nEVAL: N/A\n")
|
85 |
st.markdown(f"<b>Metadata</b>:", unsafe_allow_html=True)
|
86 |
st.json({k:v for k,v in dic.items() if k not in ["src_text", "mt_text", "tgt_text", "aligned_edit"]}, expanded=False)
|
87 |
-
if
|
88 |
setting = "pe1" if task_name == "Google PE (PE1)" else "pe2"
|
89 |
st.markdown(f"<b>Attributions</b>:", unsafe_allow_html=True)
|
90 |
st.text("Click on checkboxes to show/hide the respective attributions computed with mBART 1-to-50.")
|
91 |
for sentence_type in ["mt", "pe", "diff"]:
|
92 |
url = attribution_path.format(idx=item_id, setting=setting, sentence_type=sentence_type)
|
93 |
-
|
94 |
-
|
95 |
-
|
96 |
-
|
97 |
-
|
98 |
-
|
99 |
-
st.
|
|
|
|
|
|
|
|
|
|
|
100 |
|
|
|
79 |
st.markdown(f"<b>PE</b>: {'<bdi>' if lang == 'ara' else ''}{dic['tgt_text']}{'</bdi>' if lang == 'ara' else ''}", unsafe_allow_html=True)
|
80 |
st.markdown(f"<b>Aligned edits</b>:", unsafe_allow_html=True)
|
81 |
if dic["aligned_edit"] is not None:
|
82 |
+
aligned_edit = dic["aligned_edit"].replace("\\n", "\n").replace("REF:", "MT :").replace("HYP:", "PE :")
|
83 |
+
if lang == 'ara':
|
84 |
+
edits_reverse = aligned_edit.split("EVAL:")[1][::-1]
|
85 |
+
aligned_edit = aligned_edit.split("EVAL:")[0] + edits_reverse
|
86 |
+
st.text()
|
87 |
else:
|
88 |
st.text("MT : N/A\nPE : N/A\nEVAL: N/A\n")
|
89 |
st.markdown(f"<b>Metadata</b>:", unsafe_allow_html=True)
|
90 |
st.json({k:v for k,v in dic.items() if k not in ["src_text", "mt_text", "tgt_text", "aligned_edit"]}, expanded=False)
|
91 |
+
if task_name != "From Scratch (HT)":
|
92 |
setting = "pe1" if task_name == "Google PE (PE1)" else "pe2"
|
93 |
st.markdown(f"<b>Attributions</b>:", unsafe_allow_html=True)
|
94 |
st.text("Click on checkboxes to show/hide the respective attributions computed with mBART 1-to-50.")
|
95 |
for sentence_type in ["mt", "pe", "diff"]:
|
96 |
url = attribution_path.format(idx=item_id, setting=setting, sentence_type=sentence_type)
|
97 |
+
try:
|
98 |
+
g = urllib.request.urlopen(url)
|
99 |
+
fpath = f"attr_{sentence_type}.json.gz"
|
100 |
+
with open(fpath, 'b+w') as f:
|
101 |
+
f.write(g.read())
|
102 |
+
attr = FeatureAttributionOutput.load(fpath, decompress=True)
|
103 |
+
if st.checkbox(sentence_type.upper(), key=f"{lang}_{task_name}_{sentence_type}"):
|
104 |
+
st.markdown(f"{attr.show(return_html=True, display=False, do_aggregation=False)}", unsafe_allow_html=True)
|
105 |
+
except (urllib.HTTPError, urllib.URLError) as e:
|
106 |
+
st.checkbox(sentence_type.upper() + " (NOT AVAILABLE)", key=f"{lang}_{task_name}_{sentence_type}", disabled=True)
|
107 |
+
|
108 |
+
|
109 |
|