WhiteAngels
commited on
Commit
•
9ab5aa1
1
Parent(s):
f052c5d
Update app.py
Browse files
app.py
CHANGED
@@ -1,7 +1,8 @@
|
|
1 |
import streamlit as st
|
2 |
-
from transformers import pipeline,
|
3 |
import pandas as pd
|
4 |
import spacy
|
|
|
5 |
|
6 |
st.set_page_config(layout="wide")
|
7 |
|
@@ -106,17 +107,12 @@ if Run_Button and input_text != "":
|
|
106 |
spacy_display["title"] = None
|
107 |
|
108 |
for entity in output_comb:
|
109 |
-
|
110 |
-
|
111 |
-
|
112 |
-
|
113 |
-
|
114 |
-
|
115 |
-
|
116 |
-
ent["label"] = spacy_entity_list[tner_entity_list.index(ent["label"])]
|
117 |
-
else:
|
118 |
-
if ent["label"] == "PER": ent["label"] = "PERSON"
|
119 |
-
|
120 |
-
html = spacy.displacy.render(spacy_display, style="ent", minify=True, manual=True, options={"ents": spacy_entity_list})
|
121 |
style = "<style>mark.entity { display: inline-block }</style>"
|
122 |
st.write(f"{style}{get_html(html)}", unsafe_allow_html=True)
|
|
|
1 |
import streamlit as st
|
2 |
+
from transformers import pipeline, AutoModelForTokenClassification, AutoTokenizer
|
3 |
import pandas as pd
|
4 |
import spacy
|
5 |
+
from spacy import displacy
|
6 |
|
7 |
st.set_page_config(layout="wide")
|
8 |
|
|
|
107 |
spacy_display["title"] = None
|
108 |
|
109 |
for entity in output_comb:
|
110 |
+
label = entity["entity_group"]
|
111 |
+
# Make sure the label is not empty
|
112 |
+
if label not in ["PERSON", "NORP", "FAC", "ORG", "GPE", "LOC", "PRODUCT", "EVENT", "WORK_OF_ART", "LAW", "LANGUAGE", "DATE", "TIME", "PERCENT", "MONEY", "QUANTITY", "ORDINAL", "CARDINAL", "MISC"]:
|
113 |
+
label = "UNKNOWN"
|
114 |
+
spacy_display["ents"].append({"start": entity["start"], "end": entity["end"], "label": label})
|
115 |
+
|
116 |
+
html = displacy.render(spacy_display, style="ent", minify=True, manual=True, options={"ents": ["PERSON", "NORP", "FAC", "ORG", "GPE", "LOC", "PRODUCT", "EVENT", "WORK_OF_ART", "LAW", "LANGUAGE", "DATE", "TIME", "PERCENT", "MONEY", "QUANTITY", "ORDINAL", "CARDINAL", "MISC"]})
|
|
|
|
|
|
|
|
|
|
|
117 |
style = "<style>mark.entity { display: inline-block }</style>"
|
118 |
st.write(f"{style}{get_html(html)}", unsafe_allow_html=True)
|