Spaces:
Runtime error
Runtime error
Interface Update
Browse files
app.py
CHANGED
@@ -3,6 +3,7 @@
|
|
3 |
from transformers import pipeline, AutoModelForTokenClassification, AutoTokenizer
|
4 |
import streamlit as st
|
5 |
import pandas as pd
|
|
|
6 |
|
7 |
example_list = [
|
8 |
"Mustafa Kemal Atatürk 1919 yılında Samsun'a çıktı.",
|
@@ -63,6 +64,8 @@ if Run_Button == True:
|
|
63 |
ner_pipeline = setModel(model_checkpoint, aggregation)
|
64 |
output = ner_pipeline(input_text)
|
65 |
|
|
|
|
|
66 |
df = pd.DataFrame.from_dict(output)
|
67 |
if aggregation != "none":
|
68 |
cols_to_keep = ['word','entity_group','score','start','end']
|
@@ -70,5 +73,29 @@ if Run_Button == True:
|
|
70 |
cols_to_keep = ['word','entity','score','start','end']
|
71 |
df_final = df[cols_to_keep]
|
72 |
|
73 |
-
st.
|
74 |
st.dataframe(df_final)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
3 |
from transformers import pipeline, AutoModelForTokenClassification, AutoTokenizer
|
4 |
import streamlit as st
|
5 |
import pandas as pd
|
6 |
+
import spacy
|
7 |
|
8 |
example_list = [
|
9 |
"Mustafa Kemal Atatürk 1919 yılında Samsun'a çıktı.",
|
|
|
64 |
ner_pipeline = setModel(model_checkpoint, aggregation)
|
65 |
output = ner_pipeline(input_text)
|
66 |
|
67 |
+
print(output)
|
68 |
+
|
69 |
df = pd.DataFrame.from_dict(output)
|
70 |
if aggregation != "none":
|
71 |
cols_to_keep = ['word','entity_group','score','start','end']
|
|
|
73 |
cols_to_keep = ['word','entity','score','start','end']
|
74 |
df_final = df[cols_to_keep]
|
75 |
|
76 |
+
st.subheader("Recognized Entities")
|
77 |
st.dataframe(df_final)
|
78 |
+
|
79 |
+
def get_html(html: str):
|
80 |
+
WRAPPER = """<div style="overflow-x: auto; border: 1px solid #e6e9ef; border-radius: 0.25rem; padding: 1rem; margin-bottom: 2.5rem">{}</div>"""
|
81 |
+
html = html.replace("\n", " ")
|
82 |
+
return WRAPPER.format(html)
|
83 |
+
|
84 |
+
st.subheader("Spacy Style Display")
|
85 |
+
|
86 |
+
spacy_display = {}
|
87 |
+
spacy_display["ents"] = []
|
88 |
+
spacy_display["text"] = input_text
|
89 |
+
spacy_display["title"] = None
|
90 |
+
|
91 |
+
for entity in output:
|
92 |
+
if aggregation != "none":
|
93 |
+
spacy_display["ents"].append({"start": entity["start"], "end": entity["end"], "label": entity["entity_group"]})
|
94 |
+
else:
|
95 |
+
spacy_display["ents"].append({"start": entity["start"], "end": entity["end"], "label": entity["entity"]})
|
96 |
+
|
97 |
+
entity_list = ["PER", "LOC", "ORG", "MISC"]
|
98 |
+
colors = {'PER': '#85DCDF', 'LOC': '#DF85DC', 'ORG': '#DCDF85', 'MISC': '#85ABDF',}
|
99 |
+
html = spacy.displacy.render(spacy_display, style="ent", minify=True, manual=True, options={"ents": entity_list, "colors": colors})
|
100 |
+
style = "<style>mark.entity { display: inline-block }</style>"
|
101 |
+
st.write(f"{style}{get_html(html)}", unsafe_allow_html=True)
|