Spaces:
Sleeping
Sleeping
Lamp Socrates
commited on
Commit
•
c89a5c0
1
Parent(s):
9aa35b5
latest
Browse files
app.py
CHANGED
@@ -1,5 +1,4 @@
|
|
1 |
import streamlit as st
|
2 |
-
import wandb
|
3 |
from transformers import pipeline
|
4 |
from transformers import AutoTokenizer, AutoModelForTokenClassification
|
5 |
import pandas as pd
|
@@ -33,12 +32,16 @@ def load_random_examples(dataset_name, num_examples=5):
|
|
33 |
dataset = load_dataset("surrey-nlp/PLOD-CW")
|
34 |
|
35 |
# Convert the dataset to a pandas DataFrame
|
36 |
-
df = pd.DataFrame(dataset['
|
37 |
|
38 |
# Select random examples
|
39 |
-
random_examples = df.sample(n=
|
40 |
-
|
41 |
-
|
|
|
|
|
|
|
|
|
42 |
|
43 |
def render_entities(tokens, entities):
|
44 |
"""
|
@@ -65,15 +68,19 @@ def render_entities(tokens, entities):
|
|
65 |
th {
|
66 |
background-color: #4CAF50;
|
67 |
color: white;
|
|
|
68 |
}
|
69 |
tr:hover {
|
70 |
background-color: #f5f5f5;
|
71 |
}
|
|
|
|
|
|
|
72 |
</style>
|
73 |
""", unsafe_allow_html=True)
|
74 |
|
75 |
# Title and description
|
76 |
-
st.title("Token Entities Table")
|
77 |
st.write("This table shows the entity corresponding to each token in a cool and chilled theme.")
|
78 |
|
79 |
# Create the table
|
@@ -85,8 +92,6 @@ def render_random_examples():
|
|
85 |
Render random examples from the PLOD-CW dataset in a Streamlit table.
|
86 |
"""
|
87 |
# Load random examples
|
88 |
-
random_examples = load_random_examples("surrey-nlp/PLOD-CW")
|
89 |
-
|
90 |
|
91 |
# Custom CSS for chilled and cool theme
|
92 |
st.markdown("""
|
@@ -108,16 +113,20 @@ def render_random_examples():
|
|
108 |
th {
|
109 |
background-color: #4CAF50;
|
110 |
color: white;
|
|
|
111 |
}
|
112 |
tr:hover {
|
113 |
background-color: #f5f5f5;
|
114 |
}
|
|
|
|
|
|
|
115 |
</style>
|
116 |
""", unsafe_allow_html=True)
|
117 |
|
118 |
# Title and description
|
119 |
st.title("Random Examples from PLOD-CW")
|
120 |
-
st.write("This table shows
|
121 |
|
122 |
# Add a button to select a different set of random samples
|
123 |
if st.button('Show another set of random examples'):
|
@@ -130,13 +139,12 @@ def render_random_examples():
|
|
130 |
# Display the table
|
131 |
st.table(st.session_state['random_examples'])
|
132 |
|
133 |
-
|
134 |
def prep_page():
|
135 |
model = load_trained_model()
|
136 |
|
137 |
# Streamlit app
|
138 |
# Page configuration
|
139 |
-
st.set_page_config(page_title="NER Token Entities", layout="centered")
|
140 |
|
141 |
st.title("Named Entity Recognition with BERT on PLOD-CW")
|
142 |
st.write("Enter a sentence to see the named entities recognized by the model.")
|
@@ -185,7 +193,7 @@ def prep_page():
|
|
185 |
|
186 |
render_entities(text, entities)
|
187 |
|
188 |
-
|
189 |
|
190 |
|
191 |
|
|
|
1 |
import streamlit as st
|
|
|
2 |
from transformers import pipeline
|
3 |
from transformers import AutoTokenizer, AutoModelForTokenClassification
|
4 |
import pandas as pd
|
|
|
32 |
dataset = load_dataset("surrey-nlp/PLOD-CW")
|
33 |
|
34 |
# Convert the dataset to a pandas DataFrame
|
35 |
+
df = pd.DataFrame(dataset['test'])
|
36 |
|
37 |
# Select random examples
|
38 |
+
random_examples = df.sample(n=1)
|
39 |
+
|
40 |
+
tokens = random_examples.tokens
|
41 |
+
ner_tags = random_examples.ner_tags
|
42 |
+
|
43 |
+
return pd.DataFrame((tokens, ner_tags))
|
44 |
+
|
45 |
|
46 |
def render_entities(tokens, entities):
|
47 |
"""
|
|
|
68 |
th {
|
69 |
background-color: #4CAF50;
|
70 |
color: white;
|
71 |
+
width: 16.66%;
|
72 |
}
|
73 |
tr:hover {
|
74 |
background-color: #f5f5f5;
|
75 |
}
|
76 |
+
td {
|
77 |
+
width: 16.66%;
|
78 |
+
}
|
79 |
</style>
|
80 |
""", unsafe_allow_html=True)
|
81 |
|
82 |
# Title and description
|
83 |
+
st.title("Model predicted Token vs Entities Table")
|
84 |
st.write("This table shows the entity corresponding to each token in a cool and chilled theme.")
|
85 |
|
86 |
# Create the table
|
|
|
92 |
Render random examples from the PLOD-CW dataset in a Streamlit table.
|
93 |
"""
|
94 |
# Load random examples
|
|
|
|
|
95 |
|
96 |
# Custom CSS for chilled and cool theme
|
97 |
st.markdown("""
|
|
|
113 |
th {
|
114 |
background-color: #4CAF50;
|
115 |
color: white;
|
116 |
+
width: 16.66%;
|
117 |
}
|
118 |
tr:hover {
|
119 |
background-color: #f5f5f5;
|
120 |
}
|
121 |
+
td {
|
122 |
+
width: 16.66%;
|
123 |
+
}
|
124 |
</style>
|
125 |
""", unsafe_allow_html=True)
|
126 |
|
127 |
# Title and description
|
128 |
st.title("Random Examples from PLOD-CW")
|
129 |
+
st.write("This table shows 1 random examples from the PLOD-CW dataset in a cool and chilled theme.")
|
130 |
|
131 |
# Add a button to select a different set of random samples
|
132 |
if st.button('Show another set of random examples'):
|
|
|
139 |
# Display the table
|
140 |
st.table(st.session_state['random_examples'])
|
141 |
|
|
|
142 |
def prep_page():
|
143 |
model = load_trained_model()
|
144 |
|
145 |
# Streamlit app
|
146 |
# Page configuration
|
147 |
+
#st.set_page_config(page_title="NER Token Entities", layout="centered")
|
148 |
|
149 |
st.title("Named Entity Recognition with BERT on PLOD-CW")
|
150 |
st.write("Enter a sentence to see the named entities recognized by the model.")
|
|
|
193 |
|
194 |
render_entities(text, entities)
|
195 |
|
196 |
+
render_random_examples()
|
197 |
|
198 |
|
199 |
|