Spaces:
Runtime error
Runtime error
Update app.py
Browse files
app.py
CHANGED
@@ -96,8 +96,16 @@ if Run_Button == True:
|
|
96 |
else:
|
97 |
spacy_display["ents"].append({"start": entity["start"], "end": entity["end"], "label": entity["entity"]})
|
98 |
|
99 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
100 |
# colors = {'PER': '#85DCDF', 'LOC': '#DF85DC', 'ORG': '#DCDF85', 'MISC': '#85ABDF',}
|
101 |
-
html = spacy.displacy.render(spacy_display, style="ent", minify=True, manual=True, options={"ents":
|
102 |
style = "<style>mark.entity { display: inline-block }</style>"
|
103 |
st.write(f"{style}{get_html(html)}", unsafe_allow_html=True)
|
|
|
96 |
else:
|
97 |
spacy_display["ents"].append({"start": entity["start"], "end": entity["end"], "label": entity["entity"]})
|
98 |
|
99 |
+
tner_entity_list = ["person", "group", "facility", "organization", "geopolitical area", "location", "product", "event", "work of art", "law", "language", "date", "time", "percent", "money", "quantity", "ordinal number", "cardinal number"]
|
100 |
+
spacy_entity_list = ["PERSON", "NORP", "FAC", "ORG", "GPE", "LOC", "PRODUCT", "EVENT", "WORK_OF_ART", "LAW", "LANGUAGE", "DATE", "TIME", "PERCENT", "MONEY", "QUANTITY", "ORDINAL", "CARDINAL", "MISC"]
|
101 |
+
|
102 |
+
for ent in spacy_display["ents"]:
|
103 |
+
if model_checkpoint == "tner/tner-xlm-roberta-base-ontonotes5":
|
104 |
+
ent["label"] = spacy_entity_list[tner_entity_list.index(ent["label"])]
|
105 |
+
else:
|
106 |
+
if ent["label"] == "PER": ent["label"] = "PERSON"
|
107 |
+
|
108 |
# colors = {'PER': '#85DCDF', 'LOC': '#DF85DC', 'ORG': '#DCDF85', 'MISC': '#85ABDF',}
|
109 |
+
html = spacy.displacy.render(spacy_display, style="ent", minify=True, manual=True, options={"ents": spacy_entity_list}) # , "colors": colors})
|
110 |
style = "<style>mark.entity { display: inline-block }</style>"
|
111 |
st.write(f"{style}{get_html(html)}", unsafe_allow_html=True)
|